Skip to content

Commit a0affdd

Browse files
committed
Try fixing automargin behavior when setting display: 'none' for hidden labels
This is a second attempt after 846c0ab in which I tried to restore the previous behavior of calcLabelLevelBbox. I now think the hidden label should not contribute to the resulting bbox at all, because it's hidden. This will break baseline tests but should be the correct behavior.
1 parent 65fed4a commit a0affdd

File tree

1 file changed

+6
-26
lines changed

1 file changed

+6
-26
lines changed

src/plots/cartesian/axes.js

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2946,42 +2946,22 @@ function calcLabelLevelBbox(ax, cls, mainLinePositionShift) {
29462946
bottom = -Infinity;
29472947
left = Infinity;
29482948
right = -Infinity;
2949-
var xAxis = ax._id.charAt(0) === 'x';
29502949
ax._selections[cls].each(function() {
29512950
var thisLabel = selectTickLabel(this);
2952-
var hidden = thisLabel.style('display') === 'none';
29532951
// Use parent node <g.(x|y)tick>, to make Drawing.bBox
29542952
// retrieve a bbox computed with transform info
29552953
//
29562954
// To improve perf, it would be nice to use `thisLabel.node()`
29572955
// (like in fixLabelOverlaps) instead and use Axes.getPxPosition
29582956
// together with the makeLabelFns outputs and `tickangle`
29592957
// to compute one bbox per (tick value x tick style)
2960-
if (hidden) {
2961-
// turn on label display temporarily to calculate its bbox
2962-
thisLabel.style('display', null);
2958+
if (thisLabel.style('display') !== 'none') {
2959+
var bb = Drawing.bBox(thisLabel.node().parentNode);
2960+
top = Math.min(top, bb.top);
2961+
bottom = Math.max(bottom, bb.bottom);
2962+
left = Math.min(left, bb.left);
2963+
right = Math.max(right, bb.right);
29632964
}
2964-
var bb = Drawing.bBox(thisLabel.node().parentNode);
2965-
if (hidden) {
2966-
selectTickLabel(this).style('display', 'none');
2967-
}
2968-
var currentTop = bb.top;
2969-
var currentBottom = bb.bottom;
2970-
var currentLeft = bb.left;
2971-
var currentRight = bb.right;
2972-
if (hidden) {
2973-
if (xAxis) {
2974-
currentTop = top;
2975-
currentBottom = bottom;
2976-
} else {
2977-
currentLeft = left;
2978-
currentRight = right;
2979-
}
2980-
}
2981-
top = Math.min(top, currentTop);
2982-
bottom = Math.max(bottom, currentBottom);
2983-
left = Math.min(left, currentLeft);
2984-
right = Math.max(right, currentRight);
29852965
});
29862966
} else {
29872967
var dummyCalc = axes.makeLabelFns(ax, mainLinePositionShift);

0 commit comments

Comments
 (0)