Skip to content
This repository was archived by the owner on Apr 21, 2023. It is now read-only.

Commit 1fc0223

Browse files
etpinardpetii
authored andcommitted
do not try to re-fix axis label overlaps when current autoangle:=90
N.B. during auto-margin redraw, if the axis fixed its label overlaps by rotating 90 degrees, do not attempt to re-fix its label overlaps as this can lead to infinite redraw loops! Moreover, use ax._prevTickAngles for retrieve "lastAngle". Previous ax._tickAngles was used, but this one gets clear early Axes.drawOne, so it didn't really do anything. (cherry picked from commit 7a8eedf)
1 parent 83f1a36 commit 1fc0223

File tree

1 file changed

+51
-11
lines changed

1 file changed

+51
-11
lines changed

src/plots/cartesian/axes.js

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,6 +1639,25 @@ axes.draw = function(gd, arg, opts) {
16391639
* @param {object} ax (full) axis object
16401640
* @param {object} opts
16411641
* - @param {boolean} skipTitle (set to true to skip axis title draw call)
1642+
*
1643+
* Depends on:
1644+
* - ax._mainSubplot (from linkSubplots)
1645+
* - ax._mainAxis
1646+
* - ax._anchorAxis
1647+
* - ax._subplotsWith
1648+
* - ax._counterDomainMin, ax._counterDomainMax (optionally, from linkSubplots)
1649+
* - ax._tickAngles (on redraw only, old value relinked during supplyDefaults)
1650+
* - ax._mainLinePosition (from lsInner)
1651+
* - ax._mainMirrorPosition
1652+
* - ax._linepositions
1653+
*
1654+
* Fills in:
1655+
* - ax._vals:
1656+
* - ax._gridVals:
1657+
* - ax._selections:
1658+
* - ax._tickAngles:
1659+
* - ax._depth (when required only):
1660+
* - and calls ax.setScale
16421661
*/
16431662
axes.drawOne = function(gd, ax, opts) {
16441663
opts = opts || {};
@@ -1673,6 +1692,8 @@ axes.drawOne = function(gd, ax, opts) {
16731692
// - stash tickLabels selection, so that drawTitle can use it to scoot title
16741693
ax._selections = {};
16751694
// stash tick angle (including the computed 'auto' values) per tick-label class
1695+
// linkup 'previous' tick angles on redraws
1696+
if(ax._tickAngles) ax._prevTickAngles = ax._tickAngles;
16761697
ax._tickAngles = {};
16771698

16781699
var transFn = axes.makeTransFn(ax);
@@ -2420,6 +2441,7 @@ axes.drawZeroLine = function(gd, ax, opts) {
24202441
* - {number} tickangle
24212442
* - {object (optional)} _selections
24222443
* - {object} (optional)} _tickAngles
2444+
* - {object} (optional)} _prevTickAngles
24232445
* @param {object} opts
24242446
* - {array of object} vals (calcTicks output-like)
24252447
* - {d3 selection} layer
@@ -2436,13 +2458,14 @@ axes.drawZeroLine = function(gd, ax, opts) {
24362458
axes.drawLabels = function(gd, ax, opts) {
24372459
opts = opts || {};
24382460

2461+
var fullLayout = gd._fullLayout;
24392462
var axId = ax._id;
24402463
var axLetter = axId.charAt(0);
24412464
var cls = opts.cls || axId + 'tick';
24422465
var vals = opts.vals;
24432466
var labelFns = opts.labelFns;
24442467
var tickAngle = opts.secondary ? 0 : ax.tickangle;
2445-
var lastAngle = (ax._tickAngles || {})[cls];
2468+
var prevAngle = (ax._prevTickAngles || {})[cls];
24462469

24472470
var tickLabels = opts.layer.selectAll('g.' + cls)
24482471
.data(ax.showticklabels ? vals : [], tickDataFn);
@@ -2527,17 +2550,17 @@ axes.drawLabels = function(gd, ax, opts) {
25272550
// do this without waiting, using the last calculated angle to
25282551
// minimize flicker, then do it again when we know all labels are
25292552
// there, putting back the prescribed angle to check for overlaps.
2530-
positionLabels(tickLabels, lastAngle || tickAngle);
2553+
positionLabels(tickLabels, (prevAngle + 1) ? prevAngle : tickAngle);
25312554

25322555
function allLabelsReady() {
25332556
return labelsReady.length && Promise.all(labelsReady);
25342557
}
25352558

2559+
var autoangle = null;
2560+
25362561
function fixLabelOverlaps() {
25372562
positionLabels(tickLabels, tickAngle);
25382563

2539-
var autoangle = null;
2540-
25412564
// check for auto-angling if x labels overlap
25422565
// don't auto-angle at all for log axes with
25432566
// base and digit format
@@ -2604,19 +2627,36 @@ axes.drawLabels = function(gd, ax, opts) {
26042627
positionLabels(tickLabels, autoangle);
26052628
}
26062629
}
2607-
2608-
if(ax._tickAngles) {
2609-
ax._tickAngles[cls] = autoangle === null ?
2610-
(isNumeric(tickAngle) ? tickAngle : 0) :
2611-
autoangle;
2612-
}
26132630
}
26142631

26152632
if(ax._selections) {
26162633
ax._selections[cls] = tickLabels;
26172634
}
26182635

2619-
var done = Lib.syncOrAsync([allLabelsReady, fixLabelOverlaps]);
2636+
var seq = [allLabelsReady];
2637+
2638+
// N.B. during auto-margin redraw, if the axis fixed its label overlaps
2639+
// by rotating 90 degrees, do not attempt to re-fix its label overlaps
2640+
// as this can lead to infinite redraw loops!
2641+
if(fullLayout._redrawFromAutoMarginCount && prevAngle === 90) {
2642+
autoangle = 90;
2643+
seq.push(function() {
2644+
positionLabels(tickLabels, prevAngle);
2645+
});
2646+
} else {
2647+
seq.push(fixLabelOverlaps);
2648+
}
2649+
2650+
// save current tick angle for future redraws
2651+
if(ax._tickAngles) {
2652+
seq.push(function() {
2653+
ax._tickAngles[cls] = autoangle === null ?
2654+
(isNumeric(tickAngle) ? tickAngle : 0) :
2655+
autoangle;
2656+
});
2657+
}
2658+
2659+
var done = Lib.syncOrAsync(seq);
26202660
if(done && done.then) gd._promises.push(done);
26212661
return done;
26222662
};

0 commit comments

Comments
 (0)