-
Notifications
You must be signed in to change notification settings - Fork 279
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
feat: cropping picks smaller viewbox in gallery and editor
#1518
Conversation
± Registry diff
📊 PerformanceKeyNote that each bar component rounds up to the nearest 100ms, so each full bar is an overestimate by up to 400ms.
If a row has only one bar instead of four, that means it's not a trio and the bar just shows the total time spent for that example, again rounded up to the nearest 100ms. Data
|
Deploying with Cloudflare Pages
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! BTW I'm removing some redundant calls to cropSVG
in #1515 soon.
Description
This PR resolves the problem of diagram previews being cropped to the tightest bounding box even when the intended view box is zoomed in on a portion of the total shapes, which makes some previews look wholly unlike the actual diagrams in the gallery and the editor.
We introduce a check to compare the areas of (1) the existing view box and (2) the tightest bounding box of all shapes, and set the SVG
viewBox
to the smaller of the two.Implementation strategy and design decisions
Since this is done after the SVGs have been produced, we parse the widths and heights of the
viewBox
andcroppedViewBox
strings from these SVGs to calculate the area. We only set theviewBox
to the values incroppedViewBox
if the area of the latter is smaller than the former.Examples with steps to reproduce them
Here is a screenshot of the previously badly cropped diagram in the gallery (Brownian Motion Absorbed at Boundary), which is now fixed:
And here it is in the editor:
Checklist