Skip to content

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

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

Merged
merged 6 commits into from
Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
31 changes: 22 additions & 9 deletions src/plots/cartesian/autorange.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ function getAutoRange(gd, ax) {
} else if(dv / axLen > mbest) {
// in case of padding longer than the axis
// at least include the unpadded data values.
minbest = {val: minpt.val, pad: 0};
maxbest = {val: maxpt.val, pad: 0};
minbest = {val: minpt.val, nopad: 1};
maxbest = {val: maxpt.val, nopad: 1};
mbest = dv / axLen;
}
}
Expand Down Expand Up @@ -158,17 +158,17 @@ function getAutoRange(gd, ax) {
} else {
if(toZero) {
if(minbest.val >= 0) {
minbest = {val: 0, pad: 0};
minbest = {val: 0, nopad: 1};
}
if(maxbest.val <= 0) {
maxbest = {val: 0, pad: 0};
maxbest = {val: 0, nopad: 1};
}
} else if(nonNegative) {
if(minbest.val - mbest * getPadMin(minbest) < 0) {
minbest = {val: 0, pad: 0};
minbest = {val: 0, nopad: 1};
}
if(maxbest.val <= 0) {
maxbest = {val: 1, pad: 0};
maxbest = {val: 1, nopad: 1};
}
}

Expand Down Expand Up @@ -226,8 +226,18 @@ 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 !== 'tozero' &&
ax.rangemode !== 'nonnegative'
) {
A = padInsideLabelsOnAnchorAxis(ax, max);
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.

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

var zero = Math.max(A, B);
Expand All @@ -240,7 +250,10 @@ function makePadFn(fullLayout, ax, max) {
(ax.domain[1] - ax.domain[0]);
}

return function getPad(pt) { return pt.pad + (pt.extrapad ? extrappad : zero); };
return function getPad(pt) {
if(pt.nopad) return 0;
return pt.pad + (pt.extrapad ? extrappad : zero);
};
}

var TEXTPAD = 3;
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
}
}
}