Skip to content

Commit 9473029

Browse files
committed
Fix backwards-compatibility
Previously, although I used [30, 90] as default autotickangles, this did not reproduce old images, since the condition for choosing between the two was also different.
1 parent 7ff8d92 commit 9473029

File tree

3 files changed

+79
-76
lines changed

3 files changed

+79
-76
lines changed

src/plots/cartesian/axes.js

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3479,7 +3479,8 @@ axes.drawLabels = function(gd, ax, opts) {
34793479

34803480
var labelFns = opts.labelFns;
34813481
var tickAngle = opts.secondary ? 0 : ax.tickangle;
3482-
var autoTickAngles = ax.autotickangles || [30, 90];
3482+
3483+
var autoTickAngles = ax.autotickangles;
34833484
var prevAngle = (ax._prevTickAngles || {})[cls];
34843485

34853486
var tickLabels = opts.layer.selectAll('g.' + cls)
@@ -3782,19 +3783,24 @@ axes.drawLabels = function(gd, ax, opts) {
37823783
var pad = !isAligned ? 0 :
37833784
(ax.tickwidth || 0) + 2 * TEXTPAD;
37843785

3785-
var adjacent = tickSpacing;
3786-
var opposite = maxFontSize * 1.25 * maxLines;
3787-
var hypotenuse = Math.sqrt(Math.pow(adjacent, 2) + Math.pow(opposite, 2));
3788-
// sin(angle) = opposite / hypotenuse
3789-
var minAngle = Math.asin(opposite / hypotenuse) * (180 / Math.PI /* to degrees */);
3790-
3791-
var angle = autoTickAngles.find(function(angle) { return Math.abs(angle) >= minAngle; });
3792-
if(angle === undefined) {
3793-
// no angle larger than minAngle, just pick the largest angle
3794-
angle = autoTickAngles.reduce(
3795-
function(currentMax, nextAngle) { return Math.abs(currentMax) < Math.abs(nextAngle) ? nextAngle : currentMax; }
3796-
, autoTickAngles[0]
3797-
);
3786+
// old behavior for backwards-compatibility
3787+
var angle = ((tickSpacing < maxFontSize * 2.5) || ax.type === 'multicategory' || ax._name === 'realaxis') ? 90 : 30;
3788+
// autotickangles
3789+
if(autoTickAngles !== undefined) {
3790+
var adjacent = tickSpacing;
3791+
var opposite = maxFontSize * 1.25 * maxLines;
3792+
var hypotenuse = Math.sqrt(Math.pow(adjacent, 2) + Math.pow(opposite, 2));
3793+
// sin(angle) = opposite / hypotenuse
3794+
var minAngle = Math.asin(opposite / hypotenuse) * (180 / Math.PI /* to degrees */);
3795+
3796+
angle = autoTickAngles.find(function(angle) { return Math.abs(angle) >= minAngle; });
3797+
if(angle === undefined) {
3798+
// no angle larger than minAngle, just pick the largest angle
3799+
angle = autoTickAngles.reduce(
3800+
function(currentMax, nextAngle) { return Math.abs(currentMax) < Math.abs(nextAngle) ? nextAngle : currentMax; }
3801+
, autoTickAngles[0]
3802+
);
3803+
}
37983804
}
37993805
if(prevAngle !== undefined) {
38003806
angle = Math.abs(angle) > Math.abs(prevAngle) ? angle : prevAngle;

src/plots/cartesian/layout_attributes.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -806,17 +806,20 @@ module.exports = {
806806
description: [
807807
'Sets the angle of the tick labels with respect to the horizontal.',
808808
'For example, a `tickangle` of -90 draws the tick labels',
809-
'vertically.'
809+
'vertically. If `tickangle` is auto, the angle will be chosen from',
810+
'autotickangles if provided. If `autotickangles` is not provided,',
811+
'the angle will be 30 or 90 degrees.'
810812
].join(' ')
811813
},
812814
autotickangles: {
813815
valType: 'data_array',
814-
dflt: [30, 90],
816+
dflt: null,
815817
editType: 'ticks',
816818
description: [
817819
'When `tickangle` is set to *auto*, it will be set to the first',
818820
'angle in this array that is large enough to prevent label',
819-
'overlap.'
821+
'overlap. If undefined, tickangle *auto* will instead choose',
822+
'between 30 and 90 degrees.'
820823
].join(' ')
821824
},
822825
tickprefix: {

0 commit comments

Comments
 (0)