Skip to content

Commit

Permalink
- only coerce autotickangles for x axes with auto tickangle
Browse files Browse the repository at this point in the history
- start with the first autotickangle entry, not 0
- move radian calculation closer to its use
  • Loading branch information
alexcjohnson committed Jan 26, 2024
1 parent f544c2a commit 7d8e607
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
14 changes: 8 additions & 6 deletions src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3472,16 +3472,13 @@ axes.drawLabels = function(gd, ax, opts) {

var fullLayout = gd._fullLayout;
var axId = ax._id;
var axLetter = axId.charAt(0);
var cls = opts.cls || axId + 'tick';

var vals = opts.vals.filter(function(d) { return d.text; });

var labelFns = opts.labelFns;
var tickAngle = opts.secondary ? 0 : ax.tickangle;

var autoTickAnglesRadians = (ax.autotickangles || [0, 30, 90])
.map(function(degrees) { return degrees * Math.PI / 180; });
var prevAngle = (ax._prevTickAngles || {})[cls];

var tickLabels = opts.layer.selectAll('g.' + cls)
Expand Down Expand Up @@ -3722,10 +3719,10 @@ axes.drawLabels = function(gd, ax, opts) {
// check for auto-angling if x labels overlap
// don't auto-angle at all for log axes with
// base and digit format
if(vals.length && axLetter === 'x' && !isNumeric(tickAngle) &&
if(vals.length && ax.autotickangles &&
(ax.type !== 'log' || String(ax.dtick).charAt(0) !== 'D')
) {
autoangle = 0;
autoangle = ax.autotickangles[0];

var maxFontSize = 0;
var lbbArray = [];
Expand Down Expand Up @@ -3789,7 +3786,12 @@ axes.drawLabels = function(gd, ax, opts) {
var opposite = maxFontSize * 1.25 * maxLines;
var hypotenuse = Math.sqrt(Math.pow(adjacent, 2) + Math.pow(opposite, 2));
var maxCos = adjacent / hypotenuse;
var angleRadians = autoTickAnglesRadians.find(function(angle) { return Math.abs(Math.cos(angle)) <= maxCos; });
var autoTickAnglesRadians = ax.autotickangles.map(
function(degrees) { return degrees * Math.PI / 180; }
);
var angleRadians = autoTickAnglesRadians.find(
function(angle) { return Math.abs(Math.cos(angle)) <= maxCos; }
);
if(angleRadians === undefined) {
// no angle with smaller cosine than maxCos, just pick the angle with smallest cosine
angleRadians = autoTickAnglesRadians.reduce(
Expand Down
3 changes: 2 additions & 1 deletion src/plots/cartesian/layout_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
visibleDflt: visibleDflt,
reverseDflt: reverseDflt,
autotypenumbersDflt: autotypenumbersDflt,
splomStash: ((layoutOut._splomAxes || {})[axLetter] || {})[axId]
splomStash: ((layoutOut._splomAxes || {})[axLetter] || {})[axId],
noAutotickangles: axLetter === 'y'
};

coerce('uirevision', layoutOut.uirevision);
Expand Down
4 changes: 2 additions & 2 deletions src/plots/cartesian/tick_label_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ module.exports = function handleTickLabelDefaults(containerIn, containerOut, coe
}

if(!options.noAng) {
coerce('tickangle');
if(!options.noAutotickangles) {
var tickAngle = coerce('tickangle');
if(!options.noAutotickangles && tickAngle === 'auto') {
coerce('autotickangles');
}
}
Expand Down

0 comments on commit 7d8e607

Please sign in to comment.