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

✨ (grapher) allow line breaks after hyphens / TAS-524 #3689

Merged
merged 1 commit into from
Jun 10, 2024

Conversation

sophiamersmann
Copy link
Member

@sophiamersmann sophiamersmann commented Jun 5, 2024

Summary

Adds the ability to break after hyphens (-) to TextWrap. This is then used for slope labels to reduce the space we need for the labels on both sides.

I considered making this the default but decided against it because many labels looked worse / less balanced with additional line breaks after hyphens.

SVG tester

Some charts come back with a difference, but they're visually the same. The new code trims whitespace from each side:

Svg was different for 2649. The difference starts at character 15152.
Reference: 5" y="465.895">home) </tspan></text></g>
Current  : 5" y="465.895">home)</tspan></text></g><
Svg was different for 3552. The difference starts at character 11307.
Reference: "4.995000000000001"> Lower respiratory i
Current  : "4.995000000000001">Lower respiratory in
Svg was different for 5215. The difference starts at character 8953.
Reference: urement policies and </tspan><tspan x="1
Current  : urement policies and</tspan><tspan x="16

Screenshots

Before After
Screenshot 2024-06-05 at 16 46 18 Screenshot 2024-06-05 at 16 46 12

Example chart: https://ourworldindata.org/grapher/maternal-mortality-slope-chart?country=High-income+countries~Lower-middle-income+countries

Copy link
Member Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @sophiamersmann and the rest of your teammates on Graphite Graphite

@sophiamersmann sophiamersmann changed the title ✨ (grapher) allow line breaks after hyphens ✨ (grapher) allow line breaks after hyphens / TAS-524 Jun 5, 2024
@sophiamersmann sophiamersmann marked this pull request as ready for review June 5, 2024 14:42
Copy link

@sophiamersmann sophiamersmann marked this pull request as draft June 5, 2024 14:42
@owidbot
Copy link
Contributor

owidbot commented Jun 5, 2024

Quick links (staging server):

Site Admin Wizard

Login: ssh owid@staging-site-grapher-hyphen-breaks

SVG tester:

Number of differences (default views): 11 (7b136e) ❌
Number of differences (all views): 0 ✅

Edited: 2024-06-10 11:38:13 UTC
Execution time: 1.17 seconds

@sophiamersmann sophiamersmann force-pushed the grapher-hyphen-breaks branch 3 times, most recently from 7a17f27 to e6b574d Compare June 6, 2024 12:30
@sophiamersmann sophiamersmann marked this pull request as ready for review June 6, 2024 12:31
@sophiamersmann sophiamersmann requested a review from danyx23 June 6, 2024 12:32
Copy link
Contributor

@danyx23 danyx23 left a comment

Choose a reason for hiding this comment

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

Looks good! I'd change the tests a bit though. I think it would be good to add two simple unit tests that just demonstrate what splitIntoFragments does with just a space and with space and hyphen.

I think it would also be more interesting to change the existing property style test to include the hyphen, rather than just default to space (but I really like that you added this kind of test :) )

@sophiamersmann sophiamersmann force-pushed the grapher-hyphen-breaks branch from e6b574d to 3d931e7 Compare June 10, 2024 10:54
@sophiamersmann
Copy link
Member Author

Thanks for the review! I updated the tests :)

@sophiamersmann sophiamersmann merged commit 0ba25b7 into master Jun 10, 2024
20 of 22 checks passed
@sophiamersmann sophiamersmann deleted the grapher-hyphen-breaks branch June 10, 2024 11:47
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.

3 participants