-
Notifications
You must be signed in to change notification settings - Fork 97
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
Text in matplotlib svg #1097
Text in matplotlib svg #1097
Conversation
ec8681d
to
7420aa2
Compare
Ok this one is ready for review. @jovan-stojanovic could you check that it fixes #1095 for you? |
Thanks @jeromedockes, works perfectly well (verified on more than 4 million tweets)! Merging when the conflicts are solved |
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!
On small comment: can you add a comment on the fact that there is direction-changing character which could be picked up as a security risk.
thanks @GaelVaroquaux in the tests I replaced the literal bidirectional characters by unicode escape sequences so that the issue doesn't come up, with a comment explaining why this causes the display to look messed up in the source code I also added an example in the script that generates example reports for testing that we can visually check |
thanks a lot for checking @jovan-stojanovic ! |
Great! Merged! |
Fixes #1095
previously in the matplotlib plots, we used the default behavior for text which is that matplotlib itself renders the text (the matplotlib output svg contains svg paths rather than text)
this is simple because then matplotlib knows the size taken by the text and can set the correct viewbox so we don't need any processing of the svg afterwards.
but the drawbacks are that:
the alternative, chosen in this PR, is to ask matplotlib to put the labels as text in the svg, in which case the application which displays it (in our case a web browser) is responsible for rendering it. the main drawback is that matplotlib does not know how much space the text will take, so we need to adjust the plot's viewbox and width and height with javascript after the page loads.
not directly related, but this pr also improves a bit how the text is truncated for right-to-left scripts, so that the ellipsis ("...") is displayed on the correct side of the text (in more cases). and it also normalizes whitespace so that we don't have line breaks in matplotlib labels
main
this PR
wider screenshots
main
this pr