Skip to content

Commit 1661ce4

Browse files
committed
insiderange case of having multiple anchored axes having insideticklabel
1 parent 7234c08 commit 1661ce4

File tree

5 files changed

+290
-3
lines changed

5 files changed

+290
-3
lines changed

src/plots/cartesian/axes.js

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

3888-
var p0 = anchorAx.d2p(anchorAx.range[index]);
3889-
var p1 = anchorAx.d2p(anchorAx.range[otherIndex]);
3888+
var anchorAxRange = anchorAx.range;
3889+
3890+
var p0 = anchorAx.d2p(anchorAxRange[index]);
3891+
var p1 = anchorAx.d2p(anchorAxRange[otherIndex]);
3892+
3893+
var _tempNewRange = fullLayout._insideTickLabelsUpdaterange[anchorAx._name + '.range'];
3894+
if(_tempNewRange) { // case of having multiple anchored axes having insideticklabel
3895+
var q0 = anchorAx.d2p(_tempNewRange[index]);
3896+
var q1 = anchorAx.d2p(_tempNewRange[otherIndex]);
3897+
3898+
var dir = sgn * (ax._id.charAt(0) === 'y' ? 1 : -1);
3899+
3900+
if(dir * p0 < dir * q0) {
3901+
p0 = q0;
3902+
newRange[index] = anchorAxRange[index] = _tempNewRange[index];
3903+
}
3904+
3905+
if(dir * p1 > dir * q1) {
3906+
p1 = q1;
3907+
newRange[otherIndex] = anchorAxRange[otherIndex] = _tempNewRange[otherIndex];
3908+
}
3909+
}
3910+
38903911
var dist = Math.abs(p1 - p0);
38913912
if(dist - move > 0) {
38923913
dist -= move;
@@ -3898,7 +3919,7 @@ axes.drawLabels = function(gd, ax, opts) {
38983919
if(ax._id.charAt(0) !== 'y') move = -move;
38993920

39003921
newRange[index] = anchorAx.p2d(
3901-
anchorAx.d2p(anchorAx.range[index]) +
3922+
anchorAx.d2p(anchorAxRange[index]) +
39023923
sgn * move
39033924
);
39043925

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)