Skip to content

Commit e8a182d

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

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
"has-passive-events": "^1.0.0",
100100
"image-size": "^0.7.5",
101101
"is-mobile": "^2.2.2",
102-
"mapbox-gl": "1.10.1",
102+
"mapbox-gl": "1.13.0",
103103
"matrix-camera-controller": "^2.1.3",
104104
"mouse-change": "^1.4.0",
105105
"mouse-event-offset": "^3.0.2",

src/plots/cartesian/autorange.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,21 @@ 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+
);
237247
}
238248
});
239249
}
@@ -242,7 +252,7 @@ function makePadFn(ax, max) {
242252
morePad += anchorAxis.ticklen || 0;
243253
}
244254

245-
extrappad += morePad;
255+
extrappad = Math.max(extrappad, morePad);
246256
}
247257
}
248258

243 Bytes
Loading
-1.96 KB
Loading

0 commit comments

Comments
 (0)