diff --git a/draftlogs/6912_fix.md b/draftlogs/6912_fix.md new file mode 100644 index 00000000000..a7a779ad3f7 --- /dev/null +++ b/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! \ No newline at end of file diff --git a/src/plots/cartesian/axes.js b/src/plots/cartesian/axes.js index 2d86405eb12..30ed7b8f518 100644 --- a/src/plots/cartesian/axes.js +++ b/src/plots/cartesian/axes.js @@ -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 = ''; @@ -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; @@ -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; } } @@ -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) @@ -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})); } @@ -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) || diff --git a/test/image/baselines/zz-tickson_boundaries_showgrid_categorical.png b/test/image/baselines/zz-tickson_boundaries_showgrid_categorical.png index 8d4fb1d90df..6f32be16bf8 100644 Binary files a/test/image/baselines/zz-tickson_boundaries_showgrid_categorical.png and b/test/image/baselines/zz-tickson_boundaries_showgrid_categorical.png differ