Skip to content

Commit c262d4b

Browse files
committed
store and use ticklabel bounding boxes to increase pad for inside labels
1 parent 7a6fd0f commit c262d4b

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

src/plots/cartesian/autorange.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,14 +225,24 @@ function makePadFn(ax, max) {
225225
anchorAxis.side === 'right'
226226
)
227227
)) {
228-
var fontSize = anchorAxis.tickfont ? anchorAxis.tickfont.size : 12;
229-
var newPad = fontSize * (ax._id.charAt(0) === 'x' ? 4 : 1);
228+
var isX = ax._id.charAt(0) === 'x';
229+
230+
var morePad = 0;
231+
if(anchorAxis._vals) {
232+
// use bounding boxes
233+
morePad = 0;
234+
anchorAxis._vals.forEach(function(t) {
235+
if(t.bb) {
236+
morePad = Math.max(morePad, isX ? t.bb.width : t.bb.height);
237+
}
238+
});
239+
}
230240

231241
if(anchorAxis.ticks === 'inside' && anchorAxis.ticklabelposition === 'inside') {
232-
newPad += anchorAxis.ticklen || 0;
242+
morePad += anchorAxis.ticklen || 0;
233243
}
234244

235-
extrappad = Math.max(extrappad, newPad);
245+
extrappad += morePad;
236246
}
237247
}
238248

src/plots/cartesian/axes.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3140,6 +3140,20 @@ axes.drawLabels = function(gd, ax, opts) {
31403140
});
31413141
}
31423142

3143+
function computeFinalTickLabelBoundingBoxes() {
3144+
tickLabels.each(function(d, i) {
3145+
var thisLabel = selectTickLabel(this);
3146+
ax._vals[i].bb = Drawing.bBox(thisLabel.node());
3147+
});
3148+
}
3149+
3150+
if(
3151+
(ax._anchorAxis || {}).autorange &&
3152+
(ax.ticklabelposition || '').indexOf('inside') !== -1
3153+
) {
3154+
seq.push(computeFinalTickLabelBoundingBoxes);
3155+
}
3156+
31433157
var done = Lib.syncOrAsync(seq);
31443158
if(done && done.then) gd._promises.push(done);
31453159
return done;

0 commit comments

Comments
 (0)