Skip to content

Commit

Permalink
better fit based on tick angle - increase pad only when text does not…
Browse files Browse the repository at this point in the history
… fit inside
  • Loading branch information
archmoj committed Nov 19, 2020
1 parent 5ca95d3 commit 8a34a95
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/plots/cartesian/autorange.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,25 @@ function makePadFn(ax, max) {

var morePad = 0;
if(anchorAxis._vals) {
var A = (anchorAxis._tickAngles[anchorAxis._id + 'tick'] || 0) * Math.PI / 180;
var cosA = Math.abs(Math.cos(A));
var sinA = Math.abs(Math.sin(A));

// use bounding boxes
morePad = 0;
anchorAxis._vals.forEach(function(t) {
if(t.bb) {
morePad = Math.max(morePad, isX ? t.bb.width : t.bb.height);
var w = t.bb.width;
var h = t.bb.height;

morePad = Math.max(morePad, isX ?
Math.max(w * cosA, h * sinA) :
Math.max(h * cosA, w * sinA)
);

var fontSize = anchorAxis.tickfont ? anchorAxis.tickfont.size : 12;
// add extra pad around label
morePad += fontSize / 5;
}
});
}
Expand All @@ -242,7 +256,7 @@ function makePadFn(ax, max) {
morePad += anchorAxis.ticklen || 0;
}

extrappad += morePad;
extrappad = Math.max(extrappad, morePad);
}
}

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.

0 comments on commit 8a34a95

Please sign in to comment.