Skip to content

Commit

Permalink
store and use ticklabel bounding boxes to increase pad for inside labels
Browse files Browse the repository at this point in the history
  • Loading branch information
archmoj committed Nov 18, 2020
1 parent 7a6fd0f commit c262d4b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/plots/cartesian/autorange.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,24 @@ function makePadFn(ax, max) {
anchorAxis.side === 'right'
)
)) {
var fontSize = anchorAxis.tickfont ? anchorAxis.tickfont.size : 12;
var newPad = fontSize * (ax._id.charAt(0) === 'x' ? 4 : 1);
var isX = ax._id.charAt(0) === 'x';

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

if(anchorAxis.ticks === 'inside' && anchorAxis.ticklabelposition === 'inside') {
newPad += anchorAxis.ticklen || 0;
morePad += anchorAxis.ticklen || 0;
}

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

Expand Down
14 changes: 14 additions & 0 deletions src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3140,6 +3140,20 @@ axes.drawLabels = function(gd, ax, opts) {
});
}

function computeFinalTickLabelBoundingBoxes() {
tickLabels.each(function(d, i) {
var thisLabel = selectTickLabel(this);
ax._vals[i].bb = Drawing.bBox(thisLabel.node());
});
}

if(
(ax._anchorAxis || {}).autorange &&
(ax.ticklabelposition || '').indexOf('inside') !== -1
) {
seq.push(computeFinalTickLabelBoundingBoxes);
}

var done = Lib.syncOrAsync(seq);
if(done && done.then) gd._promises.push(done);
return done;
Expand Down

0 comments on commit c262d4b

Please sign in to comment.