Skip to content

Commit 4d89d1d

Browse files
committed
apply domain width and height with aspectratio
1 parent 04b14a8 commit 4d89d1d

8 files changed

+626
-4
lines changed

src/traces/funnelarea/plot.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ module.exports = function plot(gd, cdModule) {
3838
var cd0 = cd[0];
3939
var trace = cd0.trace;
4040

41-
setCoords(cd);
41+
setCoords(cd, fullLayout);
4242

4343
plotGroup.each(function() {
4444
var slices = d3.select(this).selectAll('g.slice').data(cd);
@@ -179,12 +179,18 @@ function getBetween(a, b) {
179179
];
180180
}
181181

182-
function setCoords(cd) {
182+
function setCoords(cd, fullLayout) {
183183
if(!cd.length) return;
184184

185185
var cd0 = cd[0];
186186

187+
var size = fullLayout._size;
188+
var domain = cd0.trace.domain;
189+
var width = size.w * Math.abs(domain.x[1] - domain.x[0]);
190+
var height = size.h * Math.abs(domain.y[1] - domain.y[0]);
191+
187192
var aspectratio = cd0.trace.aspectratio;
193+
188194
var h = cd0.trace.baseratio;
189195
if(h > 0.999) h = 0.999; // TODO: may handle this case separately
190196
var h2 = Math.pow(h, 2);
@@ -243,13 +249,13 @@ function setCoords(cd) {
243249
if(cd0.trace.scalegroup) {
244250
r *= Math.sqrt(Math.PI / 4);
245251
r /= Math.sqrt(1 + h);
246-
r *= Math.sqrt((aspectratio < 1) ? 1 / aspectratio : aspectratio);
252+
r *= Math.sqrt((aspectratio < height / width) ? 1 / aspectratio : aspectratio);
247253
}
248254

249255
var rY = (maxY - minY) / 2;
250256
var scaleX = r / lastX;
251257
var scaleY = r / (aspectratio * rY);
252-
if(aspectratio < 1) {
258+
if(aspectratio < height / width) {
253259
scaleX *= aspectratio;
254260
scaleY *= aspectratio;
255261
}
48.1 KB
Loading
45.5 KB
Loading
45.8 KB
Loading
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
{
2+
"data": [
3+
{
4+
"type": "funnelarea",
5+
"values": [6, 5, 4, 3, 2, 1],
6+
"textinfo": "value",
7+
"title": {
8+
"position": "top right",
9+
"text": "1 - 6 no group"
10+
},
11+
"domain": {
12+
"x": [0.8, 1],
13+
"y": [0.8, 1]
14+
}
15+
},
16+
{
17+
"type": "funnelarea",
18+
"values": [16, 15, 14, 13, 12, 11],
19+
"textinfo": "value",
20+
"title": {
21+
"position": "top right",
22+
"text": "11 - 16 no group"
23+
},
24+
"domain": {
25+
"x": [0.8, 1],
26+
"y": [0.5, 0.8]
27+
}
28+
},
29+
{
30+
"type": "funnelarea",
31+
"values": [60, 50, 40, 30, 20, 10],
32+
"textinfo": "value",
33+
"title": {
34+
"position": "top right",
35+
"text": "10 - 60 no group"
36+
},
37+
"domain": {
38+
"x": [0.8, 1],
39+
"y": [0, 0.5]
40+
}
41+
},
42+
{
43+
"type": "funnelarea",
44+
"values": [6, 5, 4, 3, 2, 1],
45+
"textinfo": "value",
46+
"title": {
47+
"position": "top center",
48+
"text": "1 - 6 no group"
49+
},
50+
"domain": {
51+
"x": [0.5, 0.8],
52+
"y": [0.8, 1]
53+
}
54+
},
55+
{
56+
"type": "funnelarea",
57+
"title": {
58+
"position": "top center",
59+
"text": "11 - 16 no group"
60+
},
61+
"values": [16, 15, 14, 13, 12, 11],
62+
"textinfo": "value",
63+
"domain": {
64+
"x": [0.5, 0.8],
65+
"y": [0.5, 0.8]
66+
}
67+
},
68+
{
69+
"type": "funnelarea",
70+
"values": [60, 50, 40, 30, 20, 10],
71+
"textinfo": "value",
72+
"title": {
73+
"position": "top center",
74+
"text": "10 - 60 no group"
75+
},
76+
"domain": {
77+
"x": [0.5, 0.8],
78+
"y": [0, 0.5]
79+
}
80+
},
81+
{
82+
"type": "funnelarea",
83+
"values": [6, 5, 4, 3, 2, 1],
84+
"textinfo": "value",
85+
"title": {
86+
"position": "top left",
87+
"text": "1 - 6 no group"
88+
},
89+
"domain": {
90+
"x": [0, 0.5],
91+
"y": [0.8, 1]
92+
}
93+
},
94+
{
95+
"type": "funnelarea",
96+
"values": [16, 15, 14, 13, 12, 11],
97+
"textinfo": "value",
98+
"title": {
99+
"position": "top left",
100+
"text": "11 - 16 no group"
101+
},
102+
"domain": {
103+
"x": [0, 0.5],
104+
"y": [0.5, 0.8]
105+
}
106+
},
107+
{
108+
"type": "funnelarea",
109+
"values": [60, 50, 40, 30, 20, 10],
110+
"textinfo": "value",
111+
"title": {
112+
"position": "top left",
113+
"text": "10 - 60 no group"
114+
},
115+
"domain": {
116+
"x": [0, 0.5],
117+
"y": [0, 0.5]
118+
}
119+
}
120+
],
121+
"layout": {
122+
"hiddenlabels": ["1", "4"],
123+
"width": 800,
124+
"height": 800
125+
}
126+
}
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
{
2+
"data": [
3+
{
4+
"baseratio": 0,
5+
"aspectratio": 0.5,
6+
"type": "funnelarea",
7+
"values": [6, 5, 4, 3, 2, 1],
8+
"textinfo": "value",
9+
"title": {
10+
"position": "top right",
11+
"text": "1 - 6 no group"
12+
},
13+
"domain": {
14+
"x": [0.8, 1],
15+
"y": [0.8, 1]
16+
}
17+
},
18+
{
19+
"baseratio": 0.5,
20+
"aspectratio": 0.5,
21+
"type": "funnelarea",
22+
"values": [16, 15, 14, 13, 12, 11],
23+
"textinfo": "value",
24+
"title": {
25+
"position": "top right",
26+
"text": "11 - 16 no group"
27+
},
28+
"domain": {
29+
"x": [0.8, 1],
30+
"y": [0.5, 0.8]
31+
}
32+
},
33+
{
34+
"baseratio": 1,
35+
"aspectratio": 0.5,
36+
"type": "funnelarea",
37+
"values": [60, 50, 40, 30, 20, 10],
38+
"textinfo": "value",
39+
"title": {
40+
"position": "top right",
41+
"text": "10 - 60 no group"
42+
},
43+
"domain": {
44+
"x": [0.8, 1],
45+
"y": [0, 0.5]
46+
}
47+
},
48+
{
49+
"baseratio": 0,
50+
"aspectratio": 1,
51+
"type": "funnelarea",
52+
"values": [6, 5, 4, 3, 2, 1],
53+
"textinfo": "value",
54+
"title": {
55+
"position": "top center",
56+
"text": "1 - 6 no group"
57+
},
58+
"domain": {
59+
"x": [0.5, 0.8],
60+
"y": [0.8, 1]
61+
}
62+
},
63+
{
64+
"baseratio": 0.5,
65+
"aspectratio": 1,
66+
"type": "funnelarea",
67+
"title": {
68+
"position": "top center",
69+
"text": "11 - 16 no group"
70+
},
71+
"values": [16, 15, 14, 13, 12, 11],
72+
"textinfo": "value",
73+
"domain": {
74+
"x": [0.5, 0.8],
75+
"y": [0.5, 0.8]
76+
}
77+
},
78+
{
79+
"baseratio": 1,
80+
"aspectratio": 1,
81+
"type": "funnelarea",
82+
"values": [60, 50, 40, 30, 20, 10],
83+
"textinfo": "value",
84+
"title": {
85+
"position": "top center",
86+
"text": "10 - 60 no group"
87+
},
88+
"domain": {
89+
"x": [0.5, 0.8],
90+
"y": [0, 0.5]
91+
}
92+
},
93+
{
94+
"baseratio": 0,
95+
"aspectratio": 2,
96+
"type": "funnelarea",
97+
"values": [6, 5, 4, 3, 2, 1],
98+
"textinfo": "value",
99+
"title": {
100+
"position": "top left",
101+
"text": "1 - 6 no group"
102+
},
103+
"domain": {
104+
"x": [0, 0.5],
105+
"y": [0.8, 1]
106+
}
107+
},
108+
{
109+
"baseratio": 0.5,
110+
"aspectratio": 2,
111+
"type": "funnelarea",
112+
"values": [16, 15, 14, 13, 12, 11],
113+
"textinfo": "value",
114+
"title": {
115+
"position": "top left",
116+
"text": "11 - 16 no group"
117+
},
118+
"domain": {
119+
"x": [0, 0.5],
120+
"y": [0.5, 0.8]
121+
}
122+
},
123+
{
124+
"baseratio": 1,
125+
"aspectratio": 2,
126+
"type": "funnelarea",
127+
"values": [60, 50, 40, 30, 20, 10],
128+
"textinfo": "value",
129+
"title": {
130+
"position": "top left",
131+
"text": "10 - 60 no group"
132+
},
133+
"domain": {
134+
"x": [0, 0.5],
135+
"y": [0, 0.5]
136+
}
137+
}
138+
],
139+
"layout": {
140+
"hiddenlabels": ["1", "4"],
141+
"width": 800,
142+
"height": 800
143+
}
144+
}

0 commit comments

Comments
 (0)