8000 Fix for #7416: Hidden ticklabels with ticklabelposition "inside" take up plot space by my-tien · Pull Request #7417 · plotly/plotly.js · GitHub
[go: up one dir, main page]

Skip to content

Fix for #7416: Hidden ticklabels with ticklabelposition "inside" take up plot space #7417

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking 8000 “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Try fixing automargin behavior when setting display: 'none' for hidde…
…n 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.
  • Loading branch information
my-tien committed May 22, 2025
commit a0affddf2d3eac7c7767807a391a00abb984f87c
32 changes: 6 additions & 26 deletions src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2946,42 +2946,22 @@ function calcLabelLevelBbox(ax, cls, mainLinePositionShift) {
bottom = -Infinity;
left = Infinity;
right = -Infinity;
var xAxis = ax._id.charAt(0) === 'x';
ax._selections[cls].each(function() {
var thisLabel = selectTickLabel(this);
var hidden = thisLabel.style('display') === 'none';
// Use parent node <g.(x|y)tick>, to make Drawing.bBox
// retrieve a bbox computed with transform info
//
// To improve perf, it would be nice to use `thisLabel.node()`
// (like in fixLabelOverlaps) instead and use Axes.getPxPosition
// together with the makeLabelFns outputs and `tickangle`
// to compute one bbox per (tick value x tick style)
if (hidden) {
// turn on label display temporarily to calculate its bbox
thisLabel.style('display', null);
if (thisLabel.style('display') !== 'none') {
var bb = Drawing.bBox(thisLabel.node().parentNode);
top = Math.min(top, bb.top);
bottom = Math.max(bottom, bb.bottom);
left = Math.min(left, bb.left);
right = Math.max(right, bb.right);
}
var bb = Drawing.bBox(thisLabel.node().parentNode);
if (hidden) {
selectTickLabel(this).style('display', 'none');
}
var currentTop = bb.top;
var currentBottom = bb.bottom;
var currentLeft = bb.left;
var currentRight = bb.right;
if (hidden) {
if (xAxis) {
currentTop = top;
currentBottom = bottom;
} else {
currentLeft = left;
currentRight = right;
}
}
top = Math.min(top, currentTop);
bottom = Math.max(bottom, currentBottom);
left = Math.min(left, currentLeft);
right = Math.max(right, currentRight);
});
} else {
var dummyCalc = axes.makeLabelFns(ax, mainLinePositionShift);
Expand Down
0