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

Add x boundaries for ticksarray #6912

Merged
merged 4 commits into from Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions draftlogs/6912_fix.md
@@ -0,0 +1 @@
- Fix undesired behaviour introduced in [#6885](https://github.com/plotly/plotly.js/pull/6885) where `tickson: 'boundaries'` were ignored when used with `ticksmode: 'array'` and `showgrid: true`. This feature was anonymously sponsored: thank you to our sponsor!
23 changes: 12 additions & 11 deletions src/plots/cartesian/axes.js
Expand Up @@ -1293,10 +1293,7 @@ function arrayTicks(ax, majorOnly) {
for(var i = 0; i < vals.length; i++) {
var vali = tickVal2l(vals[i]);
if(vali > tickMin && vali < tickMax) {
var obj = text[i] === undefined ?
axes.tickText(ax, vali) :
tickTextObj(ax, vali, String(text[i]));

var obj = axes.tickText(ax, vali, false, String(text[i]));
if(isMinor) {
obj.minor = true;
obj.text = '';
Expand Down Expand Up @@ -1624,6 +1621,10 @@ axes.tickText = function(ax, x, hover, noSuffixPrefix) {
var tickVal2l = axType === 'category' ? ax.d2l_noadd : ax.d2l;
var i;

var inbounds = function(v) {
var p = ax.l2p(v);
return p >= 0 && p <= ax._length ? v : null;
};
if(arrayMode && Lib.isArrayOrTypedArray(ax.ticktext)) {
var rng = Lib.simpleMap(ax.range, ax.r2l);
var minDiff = (Math.abs(rng[1] - rng[0]) - (ax._lBreaks || 0)) / 10000;
Expand All @@ -1633,6 +1634,11 @@ axes.tickText = function(ax, x, hover, noSuffixPrefix) {
}
if(i < ax.ticktext.length) {
out.text = String(ax.ticktext[i]);

out.xbnd = [
inbounds(out.x - 0.5),
inbounds(out.x + ax.dtick - 0.5)
];
return out;
}
}
Expand Down Expand Up @@ -1674,11 +1680,6 @@ axes.tickText = function(ax, x, hover, noSuffixPrefix) {
// Setup ticks and grid lines boundaries
// at 1/2 a 'category' to the left/bottom
if(ax.tickson === 'boundaries' || ax.showdividers) {
var inbounds = function(v) {
var p = ax.l2p(v);
return p >= 0 && p <= ax._length ? v : null;
};

out.xbnd = [
inbounds(out.x - 0.5),
inbounds(out.x + ax.dtick - 0.5)
Expand Down Expand Up @@ -2807,7 +2808,7 @@ function getBoundaryVals(ax, vals) {
// boundaryVals are never used for labels;
// no need to worry about the other tickTextObj keys
var _push = function(d, bndIndex) {
var xb = d.xbnd ? d.xbnd[bndIndex] : d.x;
var xb = d.xbnd[bndIndex];
if(xb !== null) {
out.push(Lib.extendFlat({}, d, {x: xb}));
}
Expand Down Expand Up @@ -3755,7 +3756,7 @@ axes.drawLabels = function(gd, ax, opts) {
// TODO should secondary labels also fall into this fix-overlap regime?

for(i = 0; i < lbbArray.length; i++) {
var xbnd = (vals && vals[i].xbnd) ? vals[i].xbnd : [null, null];
var xbnd = vals[i].xbnd;
var lbb = lbbArray[i];
if(
(xbnd[0] !== null && (lbb.left - ax.l2p(xbnd[0])) < gap) ||
Expand Down
Binary file modified test/image/baselines/zz-tickson_boundaries_showgrid_categorical.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.