Skip to content

Commit 8a34a95

Browse files
committed
better fit based on tick angle - increase pad only when text does not fit inside
1 parent 5ca95d3 commit 8a34a95

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

src/plots/cartesian/autorange.js

+16-2
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,25 @@ function makePadFn(ax, max) {
229229

230230
var morePad = 0;
231231
if(anchorAxis._vals) {
232+
var A = (anchorAxis._tickAngles[anchorAxis._id + 'tick'] || 0) * Math.PI / 180;
233+
var cosA = Math.abs(Math.cos(A));
234+
var sinA = Math.abs(Math.sin(A));
235+
232236
// use bounding boxes
233237
morePad = 0;
234238
anchorAxis._vals.forEach(function(t) {
235239
if(t.bb) {
236-
morePad = Math.max(morePad, isX ? t.bb.width : t.bb.height);
240+
var w = t.bb.width;
241+
var h = t.bb.height;
242+
243+
morePad = Math.max(morePad, isX ?
244+
Math.max(w * cosA, h * sinA) :
245+
Math.max(h * cosA, w * sinA)
246+
);
247+
248+
var fontSize = anchorAxis.tickfont ? anchorAxis.tickfont.size : 12;
249+
// add extra pad around label
250+
morePad += fontSize / 5;
237251
}
238252
});
239253
}
@@ -242,7 +256,7 @@ function makePadFn(ax, max) {
242256
morePad += anchorAxis.ticklen || 0;
243257
}
244258

245-
extrappad += morePad;
259+
extrappad = Math.max(extrappad, morePad);
246260
}
247261
}
248262

-636 Bytes
Loading
-1.39 KB
Loading

0 commit comments

Comments
 (0)