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

Handle case of nonnegative or tozero rangemodes for inside ticklabels #5331

Merged
merged 6 commits into from Dec 9, 2020

Conversation

archmoj
Copy link
Contributor

@archmoj archmoj commented Dec 9, 2020

@plotly/plotly_js

if(ax.rangemode !== 'nonnegative') {
A = padInsideLabelsOnAnchorAxis(ax, max);

if(anchorAxis.rangemode !== 'nonnegative') {
Copy link
Collaborator

Choose a reason for hiding this comment

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

why would rangemode of anchorAxis be relevant?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question. Fixed in f31d97c.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wait. I had to revert the commit.

@@ -226,8 +226,13 @@ function makePadFn(fullLayout, ax, max) {
var A = 0;
var B = 0;
if(!isLinked(fullLayout, ax._id)) {
A = padInsideLabelsOnAnchorAxis(ax, max);
B = padInsideLabelsOnThisAxis(ax, max);
if(ax.rangemode !== 'nonnegative') {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this is really the condition we want - we're not trying to completely prevent extra padding for labels when rangemode is 'nonnegative', we just want to prevent the range from going past zero. ie we never want this to prevent the high end of the range from expanding to make room for the labels, nor do we want to prevent the low end from expanding unless it's going to go past zero - so for example if you have for example scatter points from 1 to 10 and there are inside labels on the low end, so that without labels the range would be something like [0.4, 10.6], the labels should expand the range down to zero but not beyond.

if(
anchorAxis.rangemode !== 'tozero' &&
anchorAxis.rangemode !== 'nonnegative'
) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we want any of these rangemode conditions, now that you have nopad in the fallback conditions above. Basically in your new ticklabelposition-5 mock, only the blue one should have labels overlapping bars. Maybe you want to flip either the red or green labels to the bottom, in which case those would overlap the bars too, but otherwise just the blue should hit this condition.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed one of the checks in 0b254e7 but kept the other one.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The test images look good now, but I don't understand what the remaining check is doing - can you explain?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I drop the second check as you suggested.
After further investigation, it looks now that we could possibly drop padInsideLabelsOnThisAxis function which used to tweaks the range for giving the start/end labels more chance to appear on the graph. But I'd rather trying that in a separate PR.

@archmoj archmoj changed the title Handle case of nonnegative rangemode for inside ticklabels Handle case of nonnegative or tozero rangemodes for inside ticklabels Dec 9, 2020
Copy link
Collaborator

@alexcjohnson alexcjohnson left a comment

Choose a reason for hiding this comment

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

Fantastic. Very nice test images! 💃

@archmoj archmoj merged commit 9291457 into master Dec 9, 2020
@archmoj archmoj deleted the nonnegative-inside-ticklabels branch December 9, 2020 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants