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

Commit

Permalink
do not try to re-fix axis label overlaps when current autoangle:=90
Browse files Browse the repository at this point in the history
 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)
  • Loading branch information
etpinard authored and petii committed Apr 26, 2022
1 parent 83f1a36 commit 1fc0223
Showing 1 changed file with 51 additions and 11 deletions.
62 changes: 51 additions & 11 deletions src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -1639,6 +1639,25 @@ axes.draw = function(gd, arg, opts) {
* @param {object} ax (full) axis object
* @param {object} opts
* - @param {boolean} skipTitle (set to true to skip axis title draw call)
*
* Depends on:
* - ax._mainSubplot (from linkSubplots)
* - ax._mainAxis
* - ax._anchorAxis
* - ax._subplotsWith
* - ax._counterDomainMin, ax._counterDomainMax (optionally, from linkSubplots)
* - ax._tickAngles (on redraw only, old value relinked during supplyDefaults)
* - ax._mainLinePosition (from lsInner)
* - ax._mainMirrorPosition
* - ax._linepositions
*
* Fills in:
* - ax._vals:
* - ax._gridVals:
* - ax._selections:
* - ax._tickAngles:
* - ax._depth (when required only):
* - and calls ax.setScale
*/
axes.drawOne = function(gd, ax, opts) {
opts = opts || {};
Expand Down Expand Up @@ -1673,6 +1692,8 @@ axes.drawOne = function(gd, ax, opts) {
// - stash tickLabels selection, so that drawTitle can use it to scoot title
ax._selections = {};
// stash tick angle (including the computed 'auto' values) per tick-label class
// linkup 'previous' tick angles on redraws
if(ax._tickAngles) ax._prevTickAngles = ax._tickAngles;
ax._tickAngles = {};

var transFn = axes.makeTransFn(ax);
Expand Down Expand Up @@ -2420,6 +2441,7 @@ axes.drawZeroLine = function(gd, ax, opts) {
* - {number} tickangle
* - {object (optional)} _selections
* - {object} (optional)} _tickAngles
* - {object} (optional)} _prevTickAngles
* @param {object} opts
* - {array of object} vals (calcTicks output-like)
* - {d3 selection} layer
Expand All @@ -2436,13 +2458,14 @@ axes.drawZeroLine = function(gd, ax, opts) {
axes.drawLabels = function(gd, ax, opts) {
opts = opts || {};

var fullLayout = gd._fullLayout;
var axId = ax._id;
var axLetter = axId.charAt(0);
var cls = opts.cls || axId + 'tick';
var vals = opts.vals;
var labelFns = opts.labelFns;
var tickAngle = opts.secondary ? 0 : ax.tickangle;
var lastAngle = (ax._tickAngles || {})[cls];
var prevAngle = (ax._prevTickAngles || {})[cls];

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

function allLabelsReady() {
return labelsReady.length && Promise.all(labelsReady);
}

var autoangle = null;

function fixLabelOverlaps() {
positionLabels(tickLabels, tickAngle);

var autoangle = null;

// check for auto-angling if x labels overlap
// don't auto-angle at all for log axes with
// base and digit format
Expand Down Expand Up @@ -2604,19 +2627,36 @@ axes.drawLabels = function(gd, ax, opts) {
positionLabels(tickLabels, autoangle);
}
}

if(ax._tickAngles) {
ax._tickAngles[cls] = autoangle === null ?
(isNumeric(tickAngle) ? tickAngle : 0) :
autoangle;
}
}

if(ax._selections) {
ax._selections[cls] = tickLabels;
}

var done = Lib.syncOrAsync([allLabelsReady, fixLabelOverlaps]);
var seq = [allLabelsReady];

// 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!
if(fullLayout._redrawFromAutoMarginCount && prevAngle === 90) {
autoangle = 90;
seq.push(function() {
positionLabels(tickLabels, prevAngle);
});
} else {
seq.push(fixLabelOverlaps);
}

// save current tick angle for future redraws
if(ax._tickAngles) {
seq.push(function() {
ax._tickAngles[cls] = autoangle === null ?
(isNumeric(tickAngle) ? tickAngle : 0) :
autoangle;
});
}

var done = Lib.syncOrAsync(seq);
if(done && done.then) gd._promises.push(done);
return done;
};
Expand Down

0 comments on commit 1fc0223

Please sign in to comment.