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
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/plots/cartesian/autorange.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.

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.

B = padInsideLabelsOnThisAxis(ax, max);
}
}
}

var zero = Math.max(A, B);
Expand Down
Binary file added test/image/baselines/ticklabelposition-5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
186 changes: 186 additions & 0 deletions test/image/mocks/ticklabelposition-5.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
{
"data": [{
"xaxis": "x",
"yaxis": "y",
"type": "bar",
"orientation": "h",
"x": [
67.5,
23.3,
5.2,
1.8,
0.8,
0.7,
0.23,
0.1,
0.1
],
"y": [
"Hydro",
"Solid biomass",
"Wind",
"Ethanol",
"Renewable municipal waste",
"Solar thermal",
"Biodiesel",
"Solar photovoltaic",
"Tidal"
]
}, {
"xaxis": "x2",
"yaxis": "y2",
"type": "bar",
"orientation": "h",
"x": [
67.5,
23.3,
5.2,
1.8,
0.8,
0.7,
0.23,
0.1,
0.1
],
"y": [
"Hydro",
"Solid biomass",
"Wind",
"Ethanol",
"Renewable municipal waste",
"Solar thermal",
"Biodiesel",
"Solar photovoltaic",
"Tidal"
]
}, {
"xaxis": "x3",
"yaxis": "y3",
"type": "bar",
"orientation": "v",
"y": [
67.5,
23.3,
5.2,
1.8,
0.8,
0.7,
0.23,
0.1,
0.1
],
"x": [
"Hydro",
"Solid biomass",
"Wind",
"Ethanol",
"Renewable municipal waste",
"Solar thermal",
"Biodiesel",
"Solar photovoltaic",
"Tidal"
]
}, {
"xaxis": "x4",
"yaxis": "y4",
"type": "bar",
"orientation": "v",
"y": [
67.5,
23.3,
5.2,
1.8,
0.8,
0.7,
0.23,
0.1,
0.1
],
"x": [
"Hydro",
"Solid biomass",
"Wind",
"Ethanol",
"Renewable municipal waste",
"Solar thermal",
"Biodiesel",
"Solar photovoltaic",
"Tidal"
]
}],
"layout": {
"xaxis": {
"rangemode": "nonnegative",
"anchor": "y",
"domain": [0, 0.475],
"side": "bottom",
"ticklabelposition": "outside",
"gridcolor": "white"
},
"yaxis": {
"anchor": "x",
"domain": [0, 0.475],
"side": "left",
"ticklabelposition": "inside",
"gridcolor": "white"
},
"xaxis2": {
"rangemode": "nonnegative",
"anchor": "y2",
"domain": [0.525, 1],
"side": "bottom",
"ticklabelposition": "inside",
"gridcolor": "white"
},
"yaxis2": {
"anchor": "x2",
"domain": [0, 0.475],
"side": "right",
"ticklabelposition": "inside",
"gridcolor": "white"
},
"xaxis3": {
"anchor": "y3",
"domain": [0.525, 1],
"side": "top",
"ticklabelposition": "inside",
"gridcolor": "white"
},
"yaxis3": {
"rangemode": "nonnegative",
"anchor": "x3",
"domain": [0.525, 1],
"side": "right",
"ticklabelposition": "inside",
"gridcolor": "white"
},
"xaxis4": {
"anchor": "y4",
"domain": [0, 0.475],
"side": "top",
"ticklabelposition": "inside",
"gridcolor": "white"
},
"yaxis4": {
"rangemode": "nonnegative",
"anchor": "x4",
"domain": [0.525, 1],
"side": "left",
"ticklabelposition": "outside",
"gridcolor": "white"
},
"font": {
"size": 24
},
"plot_bgcolor": "lightblue",
"showlegend": false,
"width": 1000,
"height": 1000,
"margin": {
"t": 40,
"b": 40,
"l": 40,
"r": 40
}
}
}