Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InheritanceDiagram: cleanup code; avoid iframe hack; use single parameter #5056

Merged
merged 4 commits into from
Jan 13, 2022

Conversation

Elchi3
Copy link
Member

@Elchi3 Elchi3 commented Dec 10, 2021

The inheritanceDiagram macro was written for the MDN Wiki and therefore includes a variety of hacks that are no longer needed.

It amazingly (ab)used the "live sample" system to render SVGs because in the wiki you couldn't write SVGs directly. This means it generated svg code in a pre element which was then picked up for rendering by the live sample system and showed up on MDN in an iframe. We should avoid this hack now that we're out of the wiki. This PR renders the SVG directly and so iframes on roughly 250 MDN pages can be avoided(!).

The iframe hack also made it difficult to properly size the SVG viewbox. Without the iframe, the macro call parameters to define the width, height and offset are no longer needed. I'm opening an mdn/content PR to remove macro calls that contain these parameters. We can then cleanly call this macro without a parameter or with a parameter that defines a different interfaces (as needed on the new event pages).

I've also removed the logic for RTL locales given MDN has retired these locales.

This PR also cleans up the code to use more modern JS. It could probably be enhanced further, but this is a big step forward.

A follow-up to this PR should be to get inheritance data from the webref package. This would avoid that we have to maintain our own file: https://github.com/mdn/content/blob/main/files/jsondata/InterfaceData.json

@meyerweb
Copy link

AWESOME! This is great, Florian. Loving it.

@Elchi3
Copy link
Member Author

Elchi3 commented Dec 10, 2021

Should be merged together with mdn/content#11117, so marking as draft to avoid uncoordinated merges. Code is ready to review, though.

@Elchi3 Elchi3 marked this pull request as draft December 10, 2021 17:50
@schalkneethling
Copy link

Should be merged together with mdn/content#11117, so marking as draft to avoid uncoordinated merges. Code is ready to review, though.

Let me know when this is ready to be merged. Thanks, @Elchi3

@Elchi3
Copy link
Member Author

Elchi3 commented Dec 21, 2021

Thanks @schalkneethling! Basically if we are fine with this change on the yari side, then we just need someone to merge both PRs at the same time.

@wbamberg wbamberg self-requested a review December 22, 2021 23:36
Copy link
Collaborator

@wbamberg wbamberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is obviously much much better than what we had! I've tried it out alongside mdn/content#11117 and looks great in all cases I could see.

I did have a few suggestions which you might want to consider but they're not blockers.

I'm also going to take a look at mdn/content#11117 - I guess you'll want to wait for that so you can merge both at the same time?

@Elchi3
Copy link
Member Author

Elchi3 commented Dec 23, 2021

Thanks for the review, Will! I pushed an update that removes more weirdnesses that you nicely spotted!

I'm also going to take a look at mdn/content#11117 - I guess you'll want to wait for that so you can merge both at the same time?

Yes, I think merging at the same time would be great.

Copy link
Collaborator

@wbamberg wbamberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me.

Approving but not merging so we can sync with mdn/content#11117.

Also, do you think we might want to display nothing if there is no parent interface? Pages like https://developer.mozilla.org/en-US/docs/Web/API/EventTarget look strange.

@Elchi3
Copy link
Member Author

Elchi3 commented Jan 11, 2022

Thanks Will!

Also, do you think we might want to display nothing if there is no parent interface? Pages like https://developer.mozilla.org/en-US/docs/Web/API/EventTarget look strange.

I think this could be a great follow-up. I think usually page authors refrain from using the macro when there is no inheritance but we could probably force this by not displaying anything.

@Elchi3 Elchi3 marked this pull request as ready for review January 11, 2022 15:32
@wbamberg
Copy link
Collaborator

wbamberg commented Jan 11, 2022

This sometimes slices off the start of the last box when there are two rows of boxes, like:

Screen Shot 2022-01-11 at 10 57 41 AM

...this isn't really a regression as it already did that:

Screen Shot 2022-01-11 at 10 59 05 AM

...but I wonder if it's easy to fix this now it isn't in an iframe?

Apart from that this looks fine.

@Elchi3
Copy link
Member Author

Elchi3 commented Jan 12, 2022

Thanks Will!

I'm now tweaking the offset properly to react on negative x positions in the second row. (line 108 decreases this and at some point it is of course negative). The offset now takes this into account and shifts it back into the viewport.

Also, I now also added a commit to not display anything if there is no inheritance.

@wbamberg
Copy link
Collaborator

Thanks for the updates Florian! This looks and AFAICT works great.

@wbamberg wbamberg merged commit 96fce93 into mdn:main Jan 13, 2022
@Elchi3 Elchi3 deleted the inheritance-diagram-v2 branch January 13, 2022 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants