Skip to content

Commit 150ccd3

Browse files
committed
Fixes plotly#7416
Hidden ticklabels don't take up space anymore.
1 parent bcbb64a commit 150ccd3

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

src/plots/cartesian/axes.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3915,11 +3915,24 @@ axes.drawLabels = function(gd, ax, opts) {
39153915
}
39163916
}
39173917

3918+
function removeHiddenLabels() {
3919+
// Remove all hidden labels to prevent them from affecting the layout.
3920+
tickLabels.each(function(d) {
3921+
var thisLabel = d3.select(this);
3922+
var textNode = thisLabel.select('text').node();
3923+
var opacity = window.getComputedStyle(textNode).opacity;
3924+
if (opacity == '0') {
3925+
thisLabel.select('text').text('');
3926+
d3.select(textNode).text('');
3927+
}
3928+
});
3929+
}
3930+
39183931
if(ax._selections) {
39193932
ax._selections[cls] = tickLabels;
39203933
}
39213934

3922-
var seq = [allLabelsReady];
3935+
var seq = [allLabelsReady, removeHiddenLabels];
39233936

39243937
// N.B. during auto-margin redraws, if the axis fixed its label overlaps
39253938
// by rotating 90 degrees, do not attempt to re-fix its label overlaps
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"data": [
3+
{
4+
"x": ["A", "B", "C"],
5+
"y": [0, 40, 80],
6+
"type": "scatter"
7+
},
8+
{
9+
"x": ["A", "B", "C"],
10+
"y": [0, 40, 80],
11+
"type": "scatter",
12+
"xaxis": "x2",
13+
"yaxis": "y2"
14+
}
15+
],
16+
"layout": {
17+
"title": {
18+
"text": "The vertical grid lines in the subplots should be aligned."
19+
},
20+
"width": 600,
21+
"xaxis": {
22+
"anchor": "y"
23+
},
24+
"xaxis2": {
25+
"anchor": "y2"
26+
},
27+
"yaxis": {
28+
"range": [0, 80],
29+
"dtick": 20,
30+
"side": "right",
31+
"ticklabelposition": "inside",
32+
"anchor": "x",
33+
"domain": [0, 0.45]
34+
},
35+
"yaxis2": {
36+
"range": [0, 100],
37+
"dtick": 20,
38+
"side": "right",
39+
"ticklabelposition": "inside",
40+
"anchor": "x2",
41+
"domain": [0.55, 1]
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)