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

Commit c4660aa

Browse files
committed
Cherry pick commits from "More auto-margin fixes (some of them temporary) plotly#4216"
Commits: - do not try to re-fix axis label overlaps when current autoangle:=90 1fc0223 (upstream 7a8eedf) - Add (large) upper bound on the number of redraw calls 83f1a36 (upstream 631014a)
1 parent 1fc0223 commit c4660aa

19 files changed

+2816
-2957
lines changed

dist/plotly-basic.js

Lines changed: 64 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
/**
2-
* plotly.js (basic) v1.49.2-tulip.0
3-
* Copyright 2012-2019, Plotly, Inc.
4-
* All rights reserved.
5-
* Licensed under the MIT license
6-
*/
71
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Plotly = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(_dereq_,module,exports){
82
'use strict';
93

@@ -51323,6 +51317,25 @@ axes.draw = function(gd, arg, opts) {
5132351317
* @param {object} ax (full) axis object
5132451318
* @param {object} opts
5132551319
* - @param {boolean} skipTitle (set to true to skip axis title draw call)
51320+
*
51321+
* Depends on:
51322+
* - ax._mainSubplot (from linkSubplots)
51323+
* - ax._mainAxis
51324+
* - ax._anchorAxis
51325+
* - ax._subplotsWith
51326+
* - ax._counterDomainMin, ax._counterDomainMax (optionally, from linkSubplots)
51327+
* - ax._tickAngles (on redraw only, old value relinked during supplyDefaults)
51328+
* - ax._mainLinePosition (from lsInner)
51329+
* - ax._mainMirrorPosition
51330+
* - ax._linepositions
51331+
*
51332+
* Fills in:
51333+
* - ax._vals:
51334+
* - ax._gridVals:
51335+
* - ax._selections:
51336+
* - ax._tickAngles:
51337+
* - ax._depth (when required only):
51338+
* - and calls ax.setScale
5132651339
*/
5132751340
axes.drawOne = function(gd, ax, opts) {
5132851341
opts = opts || {};
@@ -51357,6 +51370,8 @@ axes.drawOne = function(gd, ax, opts) {
5135751370
// - stash tickLabels selection, so that drawTitle can use it to scoot title
5135851371
ax._selections = {};
5135951372
// stash tick angle (including the computed 'auto' values) per tick-label class
51373+
// linkup 'previous' tick angles on redraws
51374+
if(ax._tickAngles) ax._prevTickAngles = ax._tickAngles;
5136051375
ax._tickAngles = {};
5136151376

5136251377
var transFn = axes.makeTransFn(ax);
@@ -52104,6 +52119,7 @@ axes.drawZeroLine = function(gd, ax, opts) {
5210452119
* - {number} tickangle
5210552120
* - {object (optional)} _selections
5210652121
* - {object} (optional)} _tickAngles
52122+
* - {object} (optional)} _prevTickAngles
5210752123
* @param {object} opts
5210852124
* - {array of object} vals (calcTicks output-like)
5210952125
* - {d3 selection} layer
@@ -52120,13 +52136,14 @@ axes.drawZeroLine = function(gd, ax, opts) {
5212052136
axes.drawLabels = function(gd, ax, opts) {
5212152137
opts = opts || {};
5212252138

52139+
var fullLayout = gd._fullLayout;
5212352140
var axId = ax._id;
5212452141
var axLetter = axId.charAt(0);
5212552142
var cls = opts.cls || axId + 'tick';
5212652143
var vals = opts.vals;
5212752144
var labelFns = opts.labelFns;
5212852145
var tickAngle = opts.secondary ? 0 : ax.tickangle;
52129-
var lastAngle = (ax._tickAngles || {})[cls];
52146+
var prevAngle = (ax._prevTickAngles || {})[cls];
5213052147

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

5221652233
function allLabelsReady() {
5221752234
return labelsReady.length && Promise.all(labelsReady);
5221852235
}
5221952236

52237+
var autoangle = null;
52238+
5222052239
function fixLabelOverlaps() {
5222152240
positionLabels(tickLabels, tickAngle);
5222252241

52223-
var autoangle = null;
52224-
5222552242
// check for auto-angling if x labels overlap
5222652243
// don't auto-angle at all for log axes with
5222752244
// base and digit format
@@ -52288,19 +52305,36 @@ axes.drawLabels = function(gd, ax, opts) {
5228852305
positionLabels(tickLabels, autoangle);
5228952306
}
5229052307
}
52291-
52292-
if(ax._tickAngles) {
52293-
ax._tickAngles[cls] = autoangle === null ?
52294-
(isNumeric(tickAngle) ? tickAngle : 0) :
52295-
autoangle;
52296-
}
5229752308
}
5229852309

5229952310
if(ax._selections) {
5230052311
ax._selections[cls] = tickLabels;
5230152312
}
5230252313

52303-
var done = Lib.syncOrAsync([allLabelsReady, fixLabelOverlaps]);
52314+
var seq = [allLabelsReady];
52315+
52316+
// N.B. during auto-margin redraw, if the axis fixed its label overlaps
52317+
// by rotating 90 degrees, do not attempt to re-fix its label overlaps
52318+
// as this can lead to infinite redraw loops!
52319+
if(fullLayout._redrawFromAutoMarginCount && prevAngle === 90) {
52320+
autoangle = 90;
52321+
seq.push(function() {
52322+
positionLabels(tickLabels, prevAngle);
52323+
});
52324+
} else {
52325+
seq.push(fixLabelOverlaps);
52326+
}
52327+
52328+
// save current tick angle for future redraws
52329+
if(ax._tickAngles) {
52330+
seq.push(function() {
52331+
ax._tickAngles[cls] = autoangle === null ?
52332+
(isNumeric(tickAngle) ? tickAngle : 0) :
52333+
autoangle;
52334+
});
52335+
}
52336+
52337+
var done = Lib.syncOrAsync(seq);
5230452338
if(done && done.then) gd._promises.push(done);
5230552339
return done;
5230652340
};
@@ -62076,7 +62110,19 @@ plots.doAutoMargin = function(gd) {
6207662110
} else {
6207762111
fullLayout._redrawFromAutoMarginCount = 1;
6207862112
}
62079-
return Registry.call('plot', gd);
62113+
62114+
// Always allow at least one redraw and give each margin-push
62115+
// call 3 loops to converge. Of course, for most cases this way too many,
62116+
// but let's keep things on the safe side until we fix our
62117+
// auto-margin pipeline problems:
62118+
// https://github.com/plotly/plotly.js/issues/2704
62119+
var maxNumberOfRedraws = 3 * (1 + Object.keys(pushMarginIds).length);
62120+
62121+
if(fullLayout._redrawFromAutoMarginCount < maxNumberOfRedraws) {
62122+
return Registry.call('plot', gd);
62123+
} else {
62124+
Lib.warn('Too many auto-margin redraws.');
62125+
}
6208062126
}
6208162127
};
6208262128

dist/plotly-basic.min.js

Lines changed: 1 addition & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/plotly-cartesian.js

Lines changed: 64 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
/**
2-
* plotly.js (cartesian) v1.49.2-tulip.0
3-
* Copyright 2012-2019, Plotly, Inc.
4-
* All rights reserved.
5-
* Licensed under the MIT license
6-
*/
71
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Plotly = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(_dereq_,module,exports){
82
'use strict';
93

@@ -51473,6 +51467,25 @@ axes.draw = function(gd, arg, opts) {
5147351467
* @param {object} ax (full) axis object
5147451468
* @param {object} opts
5147551469
* - @param {boolean} skipTitle (set to true to skip axis title draw call)
51470+
*
51471+
* Depends on:
51472+
* - ax._mainSubplot (from linkSubplots)
51473+
* - ax._mainAxis
51474+
* - ax._anchorAxis
51475+
* - ax._subplotsWith
51476+
* - ax._counterDomainMin, ax._counterDomainMax (optionally, from linkSubplots)
51477+
* - ax._tickAngles (on redraw only, old value relinked during supplyDefaults)
51478+
* - ax._mainLinePosition (from lsInner)
51479+
* - ax._mainMirrorPosition
51480+
* - ax._linepositions
51481+
*
51482+
* Fills in:
51483+
* - ax._vals:
51484+
* - ax._gridVals:
51485+
* - ax._selections:
51486+
* - ax._tickAngles:
51487+
* - ax._depth (when required only):
51488+
* - and calls ax.setScale
5147651489
*/
5147751490
axes.drawOne = function(gd, ax, opts) {
5147851491
opts = opts || {};
@@ -51507,6 +51520,8 @@ axes.drawOne = function(gd, ax, opts) {
5150751520
// - stash tickLabels selection, so that drawTitle can use it to scoot title
5150851521
ax._selections = {};
5150951522
// stash tick angle (including the computed 'auto' values) per tick-label class
51523+
// linkup 'previous' tick angles on redraws
51524+
if(ax._tickAngles) ax._prevTickAngles = ax._tickAngles;
5151051525
ax._tickAngles = {};
5151151526

5151251527
var transFn = axes.makeTransFn(ax);
@@ -52254,6 +52269,7 @@ axes.drawZeroLine = function(gd, ax, opts) {
5225452269
* - {number} tickangle
5225552270
* - {object (optional)} _selections
5225652271
* - {object} (optional)} _tickAngles
52272+
* - {object} (optional)} _prevTickAngles
5225752273
* @param {object} opts
5225852274
* - {array of object} vals (calcTicks output-like)
5225952275
* - {d3 selection} layer
@@ -52270,13 +52286,14 @@ axes.drawZeroLine = function(gd, ax, opts) {
5227052286
axes.drawLabels = function(gd, ax, opts) {
5227152287
opts = opts || {};
5227252288

52289+
var fullLayout = gd._fullLayout;
5227352290
var axId = ax._id;
5227452291
var axLetter = axId.charAt(0);
5227552292
var cls = opts.cls || axId + 'tick';
5227652293
var vals = opts.vals;
5227752294
var labelFns = opts.labelFns;
5227852295
var tickAngle = opts.secondary ? 0 : ax.tickangle;
52279-
var lastAngle = (ax._tickAngles || {})[cls];
52296+
var prevAngle = (ax._prevTickAngles || {})[cls];
5228052297

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

5236652383
function allLabelsReady() {
5236752384
return labelsReady.length && Promise.all(labelsReady);
5236852385
}
5236952386

52387+
var autoangle = null;
52388+
5237052389
function fixLabelOverlaps() {
5237152390
positionLabels(tickLabels, tickAngle);
5237252391

52373-
var autoangle = null;
52374-
5237552392
// check for auto-angling if x labels overlap
5237652393
// don't auto-angle at all for log axes with
5237752394
// base and digit format
@@ -52438,19 +52455,36 @@ axes.drawLabels = function(gd, ax, opts) {
5243852455
positionLabels(tickLabels, autoangle);
5243952456
}
5244052457
}
52441-
52442-
if(ax._tickAngles) {
52443-
ax._tickAngles[cls] = autoangle === null ?
52444-
(isNumeric(tickAngle) ? tickAngle : 0) :
52445-
autoangle;
52446-
}
5244752458
}
5244852459

5244952460
if(ax._selections) {
5245052461
ax._selections[cls] = tickLabels;
5245152462
}
5245252463

52453-
var done = Lib.syncOrAsync([allLabelsReady, fixLabelOverlaps]);
52464+
var seq = [allLabelsReady];
52465+
52466+
// N.B. during auto-margin redraw, if the axis fixed its label overlaps
52467+
// by rotating 90 degrees, do not attempt to re-fix its label overlaps
52468+
// as this can lead to infinite redraw loops!
52469+
if(fullLayout._redrawFromAutoMarginCount && prevAngle === 90) {
52470+
autoangle = 90;
52471+
seq.push(function() {
52472+
positionLabels(tickLabels, prevAngle);
52473+
});
52474+
} else {
52475+
seq.push(fixLabelOverlaps);
52476+
}
52477+
52478+
// save current tick angle for future redraws
52479+
if(ax._tickAngles) {
52480+
seq.push(function() {
52481+
ax._tickAngles[cls] = autoangle === null ?
52482+
(isNumeric(tickAngle) ? tickAngle : 0) :
52483+
autoangle;
52484+
});
52485+
}
52486+
52487+
var done = Lib.syncOrAsync(seq);
5245452488
if(done && done.then) gd._promises.push(done);
5245552489
return done;
5245652490
};
@@ -62226,7 +62260,19 @@ plots.doAutoMargin = function(gd) {
6222662260
} else {
6222762261
fullLayout._redrawFromAutoMarginCount = 1;
6222862262
}
62229-
return Registry.call('plot', gd);
62263+
62264+
// Always allow at least one redraw and give each margin-push
62265+
// call 3 loops to converge. Of course, for most cases this way too many,
62266+
// but let's keep things on the safe side until we fix our
62267+
// auto-margin pipeline problems:
62268+
// https://github.com/plotly/plotly.js/issues/2704
62269+
var maxNumberOfRedraws = 3 * (1 + Object.keys(pushMarginIds).length);
62270+
62271+
if(fullLayout._redrawFromAutoMarginCount < maxNumberOfRedraws) {
62272+
return Registry.call('plot', gd);
62273+
} else {
62274+
Lib.warn('Too many auto-margin redraws.');
62275+
}
6223062276
}
6223162277
};
6223262278

dist/plotly-cartesian.min.js

Lines changed: 1 addition & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)