-
-
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
LineChart/StackedArea: Improve labelling when space is tight #3351
Labels
Comments
Discussed this in issue triage - because this now comes up more in thumbnails and mobile chart exports we think it's important to fix this. To fix it, we should probably drop entities from the list of labelled entities if there is insufficient space until there is enough space. It's a bit unclear if we should drop entities by lowest value in the last year first or by area in the visible chart space. |
24 tasks
sophiamersmann
added a commit
that referenced
this issue
Jun 11, 2024
Resolves #3351 ### Current implementation The current implementation uses two different placing algorithms: 1. If all labels fit into the space, then labels are placed in a non-overlapping way using connector lines 2. If the labels don't fit into the available space, then labels are simply placed at their y-value and overlapping labels are greyed out and rendered into the background ### 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... | Before | After | | ------- | ------ | | ![total-population-living-in-extreme-poverty-by-world-region-mobile (1)](https://github.com/owid/owid-grapher/assets/12461810/71f8a036-784d-4ae1-a146-096bdc47f9d4) | ![total-population-living-in-extreme-poverty-by-world-region-mobile](https://github.com/owid/owid-grapher/assets/12461810/0c7c76c5-5869-4871-a7de-87024ed96e48) | | <img width="317" alt="Screenshot 2024-05-28 at 16 15 48" src="https://github.com/owid/owid-grapher/assets/12461810/325ab991-4cc3-4b41-a9c9-c94c69126765"> |<img width="317" alt="Screenshot 2024-05-28 at 16 36 15" src="https://github.com/owid/owid-grapher/assets/12461810/5f2cf38c-1419-47af-a4b8-085e39c718e6">|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
Expected behaviour
Steps to reproduce
Screenshots
When space is tight:
If there is more space (here achieved by removing text elements):
The text was updated successfully, but these errors were encountered: