-
-
Notifications
You must be signed in to change notification settings - Fork 229
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
✨ (grapher) improve line legend algorithm #3647
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. Join @sophiamersmann and the rest of your teammates on |
Quick links (staging server):
Login:
SVG tester:Number of differences (default views): 5 (9f2da8) ❌ Edited: 2024-06-11 09:33:45 UTC |
995454e
to
76e94f0
Compare
c1dee4e
to
2879b3b
Compare
2879b3b
to
fe62b29
Compare
fe62b29
to
2373e42
Compare
81f49db
to
ea4136e
Compare
ea4136e
to
603a8be
Compare
603a8be
to
bbc4718
Compare
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.
Great idea!
I had a performance comment, and also found a case where this errors, but otherwise this is great, and certainly a nice improvement 🙌🏻
bbc4718
to
cd18d66
Compare
f00ce57
to
6e97a20
Compare
Co-authored-by: Marcel Gerber <mgerber59@gmail.com> 🤖 style: prettify code
6e97a20
to
6bc7239
Compare
Merge activity
|
Resolves #3351
Current implementation
The current implementation uses two different placing algorithms:
Updated implementation
I got rid of the second placing algorithm. Instead, if not all labels fit into the available space, then we drop as many labels as necessary, and then the first placing algorithm is used to compute the positions of the remaining labels.
How labels are dropped
The default strategy, used by line charts, tries to pick labels in a balanced way so that they're roughly at equidistance from each other. Stacked area charts overwrite this behaviour and drop labels based on the area size.
The default strategy works like this: Given a set of placed labels and a set of candidates, for each candidate, we find the two closest already placed labels, one to each side, and calculate a score based on the available space between the two placed labels (the bigger, the better) and the candidate's distance to the midpoint (the smaller, the better). We then pick the candidate with the best score that fits into the available space.
Future Work
Lines/Areas that don't get labelled should show a label on demand (previously, you could hover over the grayed-out background labels). Stacked area charts highlight the currently hovered area in the tooltip – we could do something similar for line charts. To be worked on...