-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
[WIP] Vertically center multi-line labels on Y axis #2424
Conversation
Oops, sorry. I was trying to follow the contribution guidelines and send this PR against my fork, but I messed up. Well anyway, as long as I'm here already, let me know what you think. I guess splitting on |
@darabos thanks for the PR and no problem, we can discuss it here. The new mock and baseline are great, thanks! The test failures come because we haven't always made sure that But three problems I see make me think we need a different solution: Second, I don't think splitting on Third, we need to consider how this interacts with I think the solution is going to need to be in |
Thanks for the careful advice! I'll switch to But what a terrible bloated code I ended up with! Sorry. I'll try to phrase it more compactly or move it to a separate function if I cannot. |
I've switched to I have expanded the test and you can see a before-after for the baseline image in 3adcdc9. Thanks! |
@darabos I haven't looked at the code yet, but from the tests that failed I like it already - four of our test images have multiline y axis labels that changed for the better, so we need to update the baseline images. If you look in the artifacts tab https://circleci.com/gh/plotly/plotly.js/7559#artifacts/containers/0 you can see which ones failed. If you've got our image tester set up you can run (side note: |
{ | ||
"type": "bar", | ||
"x":["x 1","multiple<br>lines","one<br >two<BR>three"], | ||
"y":["x 2","multiple<br>lines","one<br >two<BR>three"] |
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.
"y 1"
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.
"y 1"
Oops, fixed.
src/plots/cartesian/axes.js
Outdated
return -0.5 * h; | ||
} | ||
} | ||
return 0; |
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.
Very nice, I don't think this is overly long at all, it has pretty much exactly the complexity required.
The new mock is fantastic, clearly covers all the cases we care about. The only question in my mind is the cutoff angle - why did you choose 20 degrees? It looks a little funny to me in the 45-degree cases where the x and y axis labels are essentially symmetric (look at x5/y5, and rotate the image 90 degrees CCW), but the x axis labels are vertically centered while the y axis labels are aligned to the first line. Symmetry would say the logic for an x axis at angle angle
should match the logic for a y axis at angle 90 - angle
.
Thinking also about cases where this could cause problems: the main issue I see is if you have a hard edge on the plot (either axis.showline
or something like bars or a heatmap flush with the edge) particularly when you're not showing ticks. In order for multiline labels to not overlap the plot in that case, we need to make sure the angle between the vertical text and the axis is fairly small before we vertically center the text. So that would argue for a fairly small cutoff in the y case (could be 20 as you have it, or maybe 30?) and a correspondingly large cutoff in the x case (70 or 60).
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.
I had no particular reason for 20 degrees. I think I ended up with the asymmetric setup because it counteracts an existing asymmetry a bit. But that's not a good reason. 🙂 I've switched to your recommendation. (30° cutoff for y, 60° cutoff for x.)
You can see the asymmetry I mean if you look in the top right on the current baseline. Both place the anchor at the start of the third line, but the gap between the tick and the text is greater on the top than on the right. Also the gap for x 2
is greater than for y 1
.
I suppose this is unrelated to this pull request though, and does not really bother my eye.
💃 Great work @darabos - thanks! |
@darabos Incredible first PR. Thanks very much 🥇 |
Fixes #1137. The second commit shows the before and after images from the test.