Skip to content

Commit 1087f73

Browse files
authored
Merge pull request #6912 from plotly/fix-tickson-boundaries-ticksarray
Add x boundaries for ticksarray
2 parents 55b5338 + 2c08009 commit 1087f73

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

draftlogs/6912_fix.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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!

src/plots/cartesian/axes.js

+12-11
Original file line numberDiff line numberDiff line change
@@ -1293,10 +1293,7 @@ function arrayTicks(ax, majorOnly) {
12931293
for(var i = 0; i < vals.length; i++) {
12941294
var vali = tickVal2l(vals[i]);
12951295
if(vali > tickMin && vali < tickMax) {
1296-
var obj = text[i] === undefined ?
1297-
axes.tickText(ax, vali) :
1298-
tickTextObj(ax, vali, String(text[i]));
1299-
1296+
var obj = axes.tickText(ax, vali, false, String(text[i]));
13001297
if(isMinor) {
13011298
obj.minor = true;
13021299
obj.text = '';
@@ -1624,6 +1621,10 @@ axes.tickText = function(ax, x, hover, noSuffixPrefix) {
16241621
var tickVal2l = axType === 'category' ? ax.d2l_noadd : ax.d2l;
16251622
var i;
16261623

1624+
var inbounds = function(v) {
1625+
var p = ax.l2p(v);
1626+
return p >= 0 && p <= ax._length ? v : null;
1627+
};
16271628
if(arrayMode && Lib.isArrayOrTypedArray(ax.ticktext)) {
16281629
var rng = Lib.simpleMap(ax.range, ax.r2l);
16291630
var minDiff = (Math.abs(rng[1] - rng[0]) - (ax._lBreaks || 0)) / 10000;
@@ -1633,6 +1634,11 @@ axes.tickText = function(ax, x, hover, noSuffixPrefix) {
16331634
}
16341635
if(i < ax.ticktext.length) {
16351636
out.text = String(ax.ticktext[i]);
1637+
1638+
out.xbnd = [
1639+
inbounds(out.x - 0.5),
1640+
inbounds(out.x + ax.dtick - 0.5)
1641+
];
16361642
return out;
16371643
}
16381644
}
@@ -1674,11 +1680,6 @@ axes.tickText = function(ax, x, hover, noSuffixPrefix) {
16741680
// Setup ticks and grid lines boundaries
16751681
// at 1/2 a 'category' to the left/bottom
16761682
if(ax.tickson === 'boundaries' || ax.showdividers) {
1677-
var inbounds = function(v) {
1678-
var p = ax.l2p(v);
1679-
return p >= 0 && p <= ax._length ? v : null;
1680-
};
1681-
16821683
out.xbnd = [
16831684
inbounds(out.x - 0.5),
16841685
inbounds(out.x + ax.dtick - 0.5)
@@ -2807,7 +2808,7 @@ function getBoundaryVals(ax, vals) {
28072808
// boundaryVals are never used for labels;
28082809
// no need to worry about the other tickTextObj keys
28092810
var _push = function(d, bndIndex) {
2810-
var xb = d.xbnd ? d.xbnd[bndIndex] : d.x;
2811+
var xb = d.xbnd[bndIndex];
28112812
if(xb !== null) {
28122813
out.push(Lib.extendFlat({}, d, {x: xb}));
28132814
}
@@ -3755,7 +3756,7 @@ axes.drawLabels = function(gd, ax, opts) {
37553756
// TODO should secondary labels also fall into this fix-overlap regime?
37563757

37573758
for(i = 0; i < lbbArray.length; i++) {
3758-
var xbnd = (vals && vals[i].xbnd) ? vals[i].xbnd : [null, null];
3759+
var xbnd = vals[i].xbnd;
37593760
var lbb = lbbArray[i];
37603761
if(
37613762
(xbnd[0] !== null && (lbb.left - ax.l2p(xbnd[0])) < gap) ||
Loading

0 commit comments

Comments
 (0)