Skip to content

Commit 5025fbc

Browse files
authored
Merge pull request #6817 from plotly/insiderange-multiple-axes
Respect `insiderange` when multiple overlaid axes having `insideticklabel`
2 parents 0d6bca6 + 18f6ab7 commit 5025fbc

File tree

6 files changed

+291
-3
lines changed

6 files changed

+291
-3
lines changed

draftlogs/6817_fix.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Respect `insiderange` when multiple overlaid axes having `insideticklabel` [[#6817](https://github.com/plotly/plotly.js/pull/6817)]

src/plots/cartesian/axes.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3905,8 +3905,29 @@ axes.drawLabels = function(gd, ax, opts) {
39053905
var newRange = [];
39063906
newRange[otherIndex] = anchorAx.range[otherIndex];
39073907

3908-
var p0 = anchorAx.d2p(anchorAx.range[index]);
3909-
var p1 = anchorAx.d2p(anchorAx.range[otherIndex]);
3908+
var anchorAxRange = anchorAx.range;
3909+
3910+
var p0 = anchorAx.d2p(anchorAxRange[index]);
3911+
var p1 = anchorAx.d2p(anchorAxRange[otherIndex]);
3912+
3913+
var _tempNewRange = fullLayout._insideTickLabelsUpdaterange[anchorAx._name + '.range'];
3914+
if(_tempNewRange) { // case of having multiple anchored axes having insideticklabel
3915+
var q0 = anchorAx.d2p(_tempNewRange[index]);
3916+
var q1 = anchorAx.d2p(_tempNewRange[otherIndex]);
3917+
3918+
var dir = sgn * (ax._id.charAt(0) === 'y' ? 1 : -1);
3919+
3920+
if(dir * p0 < dir * q0) {
3921+
p0 = q0;
3922+
newRange[index] = anchorAxRange[index] = _tempNewRange[index];
3923+
}
3924+
3925+
if(dir * p1 > dir * q1) {
3926+
p1 = q1;
3927+
newRange[otherIndex] = anchorAxRange[otherIndex] = _tempNewRange[otherIndex];
3928+
}
3929+
}
3930+
39103931
var dist = Math.abs(p1 - p0);
39113932
if(dist - move > 0) {
39123933
dist -= move;
@@ -3918,7 +3939,7 @@ axes.drawLabels = function(gd, ax, opts) {
39183939
if(ax._id.charAt(0) !== 'y') move = -move;
39193940

39203941
newRange[index] = anchorAx.p2d(
3921-
anchorAx.d2p(anchorAx.range[index]) +
3942+
anchorAx.d2p(anchorAxRange[index]) +
39223943
sgn * move
39233944
);
39243945

Loading
Loading
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
{
2+
"data": [{
3+
"type": "bar",
4+
"xaxis": "x",
5+
"yaxis": "y",
6+
"y": [1000, 10, 100, 1]
7+
}, {
8+
"xaxis": "x",
9+
"yaxis": "y11",
10+
"y": [1000, 10, 100, 1]
11+
}, {
12+
"type": "bar",
13+
"xaxis": "x2",
14+
"yaxis": "y2",
15+
"y": [1000, 10, 100, 1]
16+
}, {
17+
"xaxis": "x2",
18+
"yaxis": "y12",
19+
"y": [1000, 10, 100, 1]
20+
}, {
21+
"type": "bar",
22+
"xaxis": "x3",
23+
"yaxis": "y3",
24+
"x": [2000, 2001, 2002, 2003],
25+
"y": [1000, 10, 100, 1]
26+
}, {
27+
"xaxis": "x3",
28+
"yaxis": "y13",
29+
"x": [2000, 2001, 2002, 2003],
30+
"y": [1000, 10, 100, 1]
31+
}, {
32+
"type": "bar",
33+
"xaxis": "x4",
34+
"yaxis": "y4",
35+
"x": [2000, 2001, 2002, 2003],
36+
"y": [1000, 10, 100, 1]
37+
}, {
38+
"xaxis": "x4",
39+
"yaxis": "y14",
40+
"x": [2000, 2001, 2002, 2003],
41+
"y": [1000, 10, 100, 1]
42+
}],
43+
"layout": {
44+
"template": {
45+
"layout": {
46+
"yaxis": {
47+
"range": [-100, 1100],
48+
"ticks": "inside",
49+
"ticklabelposition": "inside",
50+
"ticklen": 8,
51+
"tickwidth": 3,
52+
"gridcolor": "white"
53+
}
54+
}
55+
},
56+
"xaxis": {
57+
"insiderange": [1, 2],
58+
"anchor": "y",
59+
"domain": [0, 0.45],
60+
"gridcolor": "white"
61+
},
62+
"yaxis": {
63+
"anchor": "x",
64+
"domain": [0, 0.45],
65+
"side": "right"
66+
},
67+
"yaxis11": {
68+
"anchor": "x",
69+
"overlaying": "y",
70+
"side": "left"
71+
},
72+
"xaxis2": {
73+
"insiderange": [2, 1],
74+
"anchor": "y2",
75+
"domain": [0, 0.45],
76+
"gridcolor": "white"
77+
},
78+
"yaxis2": {
79+
"anchor": "x2",
80+
"domain": [0.55, 1],
81+
"side": "left"
82+
},
83+
"yaxis12": {
84+
"anchor": "x2",
85+
"overlaying": "y2",
86+
"side": "right"
87+
},
88+
"xaxis3": {
89+
"type": "date",
90+
"insiderange": ["2001-01", "2002-01"],
91+
"anchor": "y3",
92+
"domain": [0.55, 1],
93+
"gridcolor": "white"
94+
},
95+
"yaxis3": {
96+
"anchor": "x3",
97+
"domain": [0, 0.45],
98+
"side": "right"
99+
},
100+
"yaxis13": {
101+
"anchor": "x3",
102+
"overlaying": "y3",
103+
"side": "left"
104+
},
105+
"xaxis4": {
106+
"type": "date",
107+
"insiderange": ["2002-01", "2001-01"],
108+
"anchor": "y4",
109+
"domain": [0.55, 1],
110+
"gridcolor": "white"
111+
},
112+
"yaxis4": {
113+
"anchor": "x4",
114+
"domain": [0.55, 1],
115+
"side": "left"
116+
},
117+
"yaxis14": {
118+
"anchor": "x4",
119+
"overlaying": "y4",
120+
"side": "right"
121+
},
122+
"plot_bgcolor": "lightblue",
123+
"showlegend": false,
124+
"width": 900,
125+
"height": 900,
126+
"margin": {
127+
"t": 60,
128+
"b": 60,
129+
"l": 60,
130+
"r": 60
131+
}
132+
}
133+
}
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
{
2+
"data": [{
3+
"type": "bar", "orientation": "h",
4+
"yaxis": "y",
5+
"xaxis": "x",
6+
"x": [1000, 10, 100, 1]
7+
}, {
8+
"yaxis": "y",
9+
"xaxis": "x11",
10+
"x": [1000, 10, 100, 1]
11+
}, {
12+
"type": "bar", "orientation": "h",
13+
"yaxis": "y2",
14+
"xaxis": "x2",
15+
"x": [1000, 10, 100, 1]
16+
}, {
17+
"yaxis": "y2",
18+
"xaxis": "x12",
19+
"x": [1000, 10, 100, 1]
20+
}, {
21+
"type": "bar", "orientation": "h",
22+
"yaxis": "y3",
23+
"xaxis": "x3",
24+
"y": [2000, 2001, 2002, 2003],
25+
"x": [1000, 10, 100, 1]
26+
}, {
27+
"yaxis": "y3",
28+
"xaxis": "x13",
29+
"y": [2000, 2001, 2002, 2003],
30+
"x": [1000, 10, 100, 1]
31+
}, {
32+
"type": "bar", "orientation": "h",
33+
"yaxis": "y4",
34+
"xaxis": "x4",
35+
"y": [2000, 2001, 2002, 2003],
36+
"x": [1000, 10, 100, 1]
37+
}, {
38+
"yaxis": "y4",
39+
"xaxis": "x14",
40+
"y": [2000, 2001, 2002, 2003],
41+
"x": [1000, 10, 100, 1]
42+
}],
43+
"layout": {
44+
"template": {
45+
"layout": {
46+
"xaxis": {
47+
"range": [-100, 1100],
48+
"ticks": "inside",
49+
"ticklabelposition": "inside",
50+
"ticklen": 8,
51+
"tickwidth": 3,
52+
"gridcolor": "white"
53+
}
54+
}
55+
},
56+
"yaxis": {
57+
"insiderange": [1, 2],
58+
"anchor": "x",
59+
"domain": [0, 0.45],
60+
"gridcolor": "white"
61+
},
62+
"xaxis": {
63+
"anchor": "y",
64+
"domain": [0, 0.45],
65+
"side": "top"
66+
},
67+
"xaxis11": {
68+
"anchor": "y",
69+
"overlaying": "x",
70+
"side": "bottom"
71+
},
72+
"yaxis2": {
73+
"insiderange": [2, 1],
74+
"anchor": "x2",
75+
"domain": [0, 0.45],
76+
"gridcolor": "white"
77+
},
78+
"xaxis2": {
79+
"anchor": "y2",
80+
"domain": [0.55, 1],
81+
"side": "bottom"
82+
},
83+
"xaxis12": {
84+
"anchor": "y2",
85+
"overlaying": "x2",
86+
"side": "top"
87+
},
88+
"yaxis3": {
89+
"type": "date",
90+
"insiderange": ["2001-01", "2002-01"],
91+
"anchor": "x3",
92+
"domain": [0.55, 1],
93+
"gridcolor": "white"
94+
},
95+
"xaxis3": {
96+
"anchor": "y3",
97+
"domain": [0, 0.45],
98+
"side": "top"
99+
},
100+
"xaxis13": {
101+
"anchor": "y3",
102+
"overlaying": "x3",
103+
"side": "bottom"
104+
},
105+
"yaxis4": {
106+
"type": "date",
107+
"insiderange": ["2002-01", "2001-01"],
108+
"anchor": "x4",
109+
"domain": [0.55, 1],
110+
"gridcolor": "white"
111+
},
112+
"xaxis4": {
113+
"anchor": "y4",
114+
"domain": [0.55, 1],
115+
"side": "bottom"
116+
},
117+
"xaxis14": {
118+
"anchor": "y4",
119+
"overlaying": "x4",
120+
"side": "top"
121+
},
122+
"plot_bgcolor": "lightblue",
123+
"showlegend": false,
124+
"width": 900,
125+
"height": 900,
126+
"margin": {
127+
"t": 60,
128+
"b": 60,
129+
"l": 60,
130+
"r": 60
131+
}
132+
}
133+
}

0 commit comments

Comments
 (0)