-
-
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
bb90e1d
Add test illustrating #1137.
darabos b682fe3
Vertically center multi-line labels on Y axis.
darabos 8f8876c
Fix multi-line alignment in different angles and sides.
darabos e96f7e1
More complete bar_multiline_labels test with the change disabled.
darabos 3adcdc9
Correct alignment on all sides and angles, reliable line count.
darabos b7a67ce
Fix eslint mistakes.
darabos 4431506
Update affected prior baselines.
darabos 261cb9d
Merge branch 'master' of https://github.com/plotly/plotly.js into dar…
darabos f4b2a85
Regenerate gl2d_date_axes.png after merge to resolve conflict.
darabos f9e1a57
Large anchor positioning cutoff for X. Use 30/60 degrees. Fix label i…
darabos 99292ee
Update baseline.
darabos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
{ | ||
"data":[ | ||
{ | ||
"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 commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Oops, fixed. |
||
}, | ||
{ | ||
"type": "bar", | ||
"x":["x 2","multiple<br>lines","one<br>two<br>three"], | ||
"y":["y 2","multiple<br>lines","one<br>two<br>three"], | ||
"xaxis": "x2", | ||
"yaxis": "y2" | ||
}, | ||
{ | ||
"type": "bar", | ||
"x":["x 3","multiple<br>lines","one<br>two<br>three"], | ||
"y":["y 3","multiple<br>lines","one<br>two<br>three"], | ||
"xaxis": "x3", | ||
"yaxis": "y3" | ||
}, | ||
{ | ||
"type": "bar", | ||
"x":["x 4","multiple<br>lines","one<br>two<br>three"], | ||
"y":["y 4","multiple<br>lines","one<br>two<br>three"], | ||
"xaxis": "x4", | ||
"yaxis": "y4" | ||
}, | ||
{ | ||
"type": "bar", | ||
"orientation": "h", | ||
"x":["x 5","multiple<br>lines","one<br>two<br>three"], | ||
"y":["y 5","multiple<br>lines","one<br>two<br>three"], | ||
"xaxis": "x5", | ||
"yaxis": "y5" | ||
}, | ||
{ | ||
"type": "bar", | ||
"orientation": "h", | ||
"x":["x 6","multiple<br>lines","one<br>two<br>three"], | ||
"y":["y 6","multiple<br>lines","one<br>two<br>three"], | ||
"xaxis": "x6", | ||
"yaxis": "y6" | ||
}, | ||
{ | ||
"type": "scatter", | ||
"x":["x 7","multiple<br>lines","one<br>two<br>three"], | ||
"y":["y 7","multiple<br>lines","one<br>two<br>three"], | ||
"xaxis": "x7", | ||
"yaxis": "y7" | ||
}, | ||
{ | ||
"type": "scatter", | ||
"x":["x 8","multiple<br>lines","one<br>two<br>three"], | ||
"y":["y 8","multiple<br>lines","one<br>two<br>three"], | ||
"xaxis": "x8", | ||
"yaxis": "y8" | ||
} | ||
], | ||
"layout":{ | ||
"showlegend": false, | ||
"xaxis": { | ||
"ticks": "outside", | ||
"domain": [0, 0.4] | ||
}, | ||
"yaxis": { | ||
"ticks": "outside", | ||
"domain": [0, 0.4] | ||
}, | ||
"xaxis2": { | ||
"ticks": "outside", | ||
"domain": [0, 0.4], | ||
"side": "top", | ||
"anchor": "y2", | ||
"tickangle": 90 | ||
}, | ||
"yaxis2": { | ||
"ticks": "outside", | ||
"domain": [0, 0.4], | ||
"side": "right", | ||
"tickangle": 90 | ||
}, | ||
"xaxis3": { | ||
"ticks": "outside", | ||
"domain": [0.6, 1], | ||
"tickangle": 90 | ||
}, | ||
"yaxis3": { | ||
"ticks": "outside", | ||
"domain": [0, 0.4], | ||
"anchor": "x3", | ||
"tickangle": 90 | ||
}, | ||
"xaxis4": { | ||
"ticks": "outside", | ||
"domain": [0.6, 1], | ||
"side": "top" | ||
}, | ||
"yaxis4": { | ||
"ticks": "outside", | ||
"domain": [0, 0.4], | ||
"side": "right", | ||
"anchor": "x4" | ||
}, | ||
"xaxis5": { | ||
"ticks": "outside", | ||
"domain": [0, 0.4], | ||
"anchor": "y5", | ||
"tickangle": 45 | ||
}, | ||
"yaxis5": { | ||
"ticks": "outside", | ||
"domain": [0.6, 1], | ||
"anchor": "x5", | ||
"tickangle": 45 | ||
}, | ||
"xaxis6": { | ||
"ticks": "outside", | ||
"domain": [0, 0.4], | ||
"side": "top", | ||
"anchor": "y6", | ||
"tickangle": -90 | ||
}, | ||
"yaxis6": { | ||
"ticks": "outside", | ||
"domain": [0.6, 1], | ||
"anchor": "x6", | ||
"side": "right", | ||
"tickangle": -90 | ||
}, | ||
"xaxis7": { | ||
"ticks": "outside", | ||
"domain": [0.6, 1], | ||
"anchor": "y7", | ||
"tickangle": -90 | ||
}, | ||
"yaxis7": { | ||
"ticks": "outside", | ||
"domain": [0.6, 1], | ||
"anchor": "x7", | ||
"tickangle": -90 | ||
}, | ||
"xaxis8": { | ||
"ticks": "outside", | ||
"domain": [0.6, 1], | ||
"side": "top", | ||
"anchor": "y8", | ||
"tickangle": -45 | ||
}, | ||
"yaxis8": { | ||
"ticks": "outside", | ||
"domain": [0.6, 1], | ||
"side": "right", | ||
"anchor": "x8", | ||
"tickangle": 45 | ||
}, | ||
"legend": "none", | ||
"height":800, | ||
"width":800 | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 angle90 - 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 fory 1
.I suppose this is unrelated to this pull request though, and does not really bother my eye.