Skip to content

Commit

Permalink
Merge pull request #6912 from plotly/fix-tickson-boundaries-ticksarray
Browse files Browse the repository at this point in the history
Add x boundaries for ticksarray
  • Loading branch information
Farkites authored Mar 1, 2024
2 parents 55b5338 + 2c08009 commit 1087f73
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
1 change: 1 addition & 0 deletions draftlogs/6912_fix.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1087f73

Please sign in to comment.