Skip to content

Commit

Permalink
Merge pull request #5332 from plotly/improve-inside-ticklabel-autorange
Browse files Browse the repository at this point in the history
Simplify autorange pipeline for inside ticklabels
  • Loading branch information
archmoj authored Dec 9, 2020
2 parents 9291457 + c45ae12 commit 4a3fc8e
Show file tree
Hide file tree
Showing 11 changed files with 2 additions and 41 deletions.
43 changes: 2 additions & 41 deletions src/plots/cartesian/autorange.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,10 @@ function makePadFn(fullLayout, ax, max) {
if(axReverse) max = !max;
}

var A = 0;
var B = 0;
var zero = 0;
if(!isLinked(fullLayout, ax._id)) {
A = padInsideLabelsOnAnchorAxis(ax, max);
B = padInsideLabelsOnThisAxis(ax, max);
zero = padInsideLabelsOnAnchorAxis(ax, max);
}

var zero = Math.max(A, B);
extrappad = Math.max(zero, extrappad);

// domain-constrained axes: base extrappad on the unconstrained
Expand All @@ -248,41 +244,6 @@ function makePadFn(fullLayout, ax, max) {

var TEXTPAD = 3;

function padInsideLabelsOnThisAxis(ax, max) {
var ticklabelposition = ax.ticklabelposition || '';
var has = function(str) {
return ticklabelposition.indexOf(str) !== -1;
};

if(!has('inside')) return 0;
var isTop = has('top');
var isLeft = has('left');
var isRight = has('right');
var isBottom = has('bottom');
var isAligned = isBottom || isLeft || isTop || isRight;

if(
(max && (isLeft || isBottom)) ||
(!max && (isRight || isTop))
) {
return 0;
}

// increase padding to make more room for inside tick labels of the axis
var fontSize = ax.tickfont ? ax.tickfont.size : 12;
var isX = ax._id.charAt(0) === 'x';
var pad = (isX ? 1.2 : 0.6) * fontSize;

if(isAligned) {
pad *= 2;
pad += (ax.tickwidth || 0) / 2;
}

pad += TEXTPAD;

return pad;
}

function padInsideLabelsOnAnchorAxis(ax, max) {
var pad = 0;
var anchorAxis = ax._anchorAxis || {};
Expand Down
Binary file modified test/image/baselines/ticklabelposition-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/ticklabelposition-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/ticklabelposition-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/ticklabelposition-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/ticklabelposition-5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/ticklabelposition-6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/ticklabelposition-a.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/ticklabelposition-b.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/ticklabelposition-c.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/ticklabelposition-d.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4a3fc8e

Please sign in to comment.