Skip to content

Commit d8297a0

Browse files
committed
improve line.shape 'vh' by @ErwanMAS
1 parent 54d8240 commit d8297a0

File tree

3 files changed

+139
-48
lines changed

3 files changed

+139
-48
lines changed

src/traces/scattergl/convert.js

+17-13
Original file line numberDiff line numberDiff line change
@@ -393,22 +393,21 @@ function convertLinePositions(gd, trace, positions) {
393393
if(trace.line.shape === 'hv') {
394394
linePositions = [];
395395
for(i = 0; i < count - 1; i++) {
396-
if(isNaN(positions[i * 2]) || isNaN(positions[i * 2 + 1]) || isNaN(positions[i * 2 + 2]) || isNaN(positions[i * 2 + 3])) {
397-
if(!isNaN(positions[i * 2]) && !isNaN(positions[i * 2 + 1])) {
398-
linePositions.push(positions[i * 2]);
396+
if(isNaN(positions[i * 2]) || isNaN(positions[i * 2 + 1])) {
397+
linePositions.push(NaN);
398+
linePositions.push(NaN);
399+
linePositions.push(NaN);
400+
linePositions.push(NaN);
401+
} else {
402+
linePositions.push(positions[i * 2]);
403+
linePositions.push(positions[i * 2 + 1]);
404+
if(!isNaN(positions[i * 2 + 2]) && !isNaN(positions[i * 2 + 3])) {
405+
linePositions.push(positions[i * 2 + 2]);
399406
linePositions.push(positions[i * 2 + 1]);
400407
} else {
401408
linePositions.push(NaN);
402409
linePositions.push(NaN);
403410
}
404-
linePositions.push(NaN);
405-
linePositions.push(NaN);
406-
}
407-
else {
408-
linePositions.push(positions[i * 2]);
409-
linePositions.push(positions[i * 2 + 1]);
410-
linePositions.push(positions[i * 2 + 2]);
411-
linePositions.push(positions[i * 2 + 1]);
412411
}
413412
}
414413
linePositions.push(positions[positions.length - 2]);
@@ -477,8 +476,13 @@ function convertLinePositions(gd, trace, positions) {
477476
else {
478477
linePositions.push(positions[i * 2]);
479478
linePositions.push(positions[i * 2 + 1]);
480-
linePositions.push(positions[i * 2]);
481-
linePositions.push(positions[i * 2 + 3]);
479+
if(!isNaN(positions[i * 2 + 2]) && !isNaN(positions[i * 2 + 3])) {
480+
linePositions.push(positions[i * 2]);
481+
linePositions.push(positions[i * 2 + 3]);
482+
} else {
483+
linePositions.push(NaN);
484+
linePositions.push(NaN);
485+
}
482486
}
483487
}
484488
linePositions.push(positions[positions.length - 2]);
43 KB
Loading

test/image/mocks/gl2d_shape_line.json

+122-35
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,194 @@
11
{
22
"data": [
33
{
4-
"x": [10,11, 12, 13, 14, 15 ,null, 16 , 17 , 18 , 19 ],
4+
"x": [20,21, 22, 23, 24, 25 ,null, 26 , 27 , 28 , 29 ],
55
"y": [null,26, 28, 27, 29,null,null, 26, 30, 30 , null ],
66
"mode": "lines+markers","fill":"tozeroy",
77
"name": "hv",
88
"line": {"shape": "hv"},
99
"type": "scattergl"
1010
},{
11-
"x": [10,11, 12, 13, 14, 15 ,null, 16 , 17 , 18 , 19 ],
11+
"x": [20,21, 22, 23, 24, 25 ,null, 26 , 27 , 28 , 29 ],
1212
"y": [null,21, 23, 22, 24,null,null, 21, 25 , 25 , null ],
1313
"mode": "lines+markers","fill":"tozeroy",
1414
"name": "vh",
1515
"line": {"shape": "vh"},
1616
"type": "scattergl"
1717
},{
18-
"x": [10,11, 12, 13, 14, 15 , null , 16 , 17 , 18 , 19 ],
18+
"x": [20,21, 22, 23, 24, 25 , null , 26 , 27 , 28 , 29 ],
1919
"y": [null,16, 18, 17, 19,null,null , 16, 20 , 20 , null ],
2020
"mode": "lines+markers","fill":"tozeroy",
2121
"name": "hvh",
2222
"line": {"shape": "hvh"},
2323
"type": "scattergl"
2424
},
2525
{
26-
"x": [10,11, 12, 13, 14, 15 ,null, 16 , 17 , 18 , 19 ],
26+
"x": [20,21, 22, 23, 24, 25 ,null, 26 , 27 , 28 , 29 ],
2727
"y": [null,11, 13, 12, 14,null,null, 11, 15 , 15 , null ],
2828
"mode": "lines+markers","fill":"tozeroy",
2929
"name": "vhv",
3030
"line": {"shape": "vhv"},
3131
"type": "scattergl"
3232
},
3333
{
34-
"x": [10,11, 12, 13, 14, 15 ,null, 16 , 17 , 18 , 19 ],
34+
"x": [20,21, 22, 23, 24, 25 ,null, 26 , 27 , 28 , 29 ],
3535
"y": [null,6, 8, 7, 9,null, null, 6, 10 , 10 , null ],
3636
"mode": "lines+markers","fill":"tozeroy",
3737
"name": "spline",
3838
"line": {"shape": "spline","smoothing":4},
3939
"type": "scattergl"
4040
},
4141
{
42-
"x": [10,11, 12, 13, 14, 15 , 16 , 17 , 18 , 19 ],
42+
"x": [20,21, 22, 23, 24, 25 , 26 , 27 , 28 , 29 ],
4343
"y": [null,1, 3, 2, 4,null, 1 , 5 , 5 , null ],
4444
"mode": "lines+markers","fill":"tozeroy",
4545
"name": "linear",
4646
"line": {"shape": "linear"},
4747
"type": "scattergl"
4848
},{
49-
"x": [1, 2, 3, 4, 5 , 6 , 7 , 8 , 9 ],
50-
"y": [26, 28, 27, 29,null, 26, 30, 30 , null ],
49+
"x": [ 1, 2, 3, 4, 5 , 6 , 7 , 8 , 9 , 10, 11 , 12 , null, 14 ],
50+
"y": [26, 28, 27, 29,null ,26 , 30 , 30, null , 27, 28 , 28 , 30, 30 ],
5151
"mode": "lines+markers",
5252
"name": "hv",
5353
"line": {"shape": "hv"},
54-
"type": "scattergl"
54+
"type": "scattergl" , "xaxis": "x", "yaxis": "y"
5555
},{
56-
"x": [1, 2, 3, 4, 5 , 6 , 7 , 8 , 9 ],
57-
"y": [21, 23, 22, 24,null, 21, 25 , 25 , null ],
56+
"x": [ 1, 2, 3, 4, 5 , 6 , 7 , 8 , 9 , 10, 11 , 12 , null, 14 ],
57+
"y": [21, 23, 22, 24,null, 21, 25 , 25 , null , 22, 23 , 23 , 25, 25 ],
5858
"mode": "lines+markers",
5959
"name": "vh",
6060
"line": {"shape": "vh"},
61-
"type": "scattergl"
61+
"type": "scattergl" , "xaxis": "x", "yaxis": "y"
6262
},{
63-
"x": [1, 2, 3, 4, 5 , 6 , 7 , 8 , 9 ],
64-
"y": [16, 18, 17, 19,null, 16, 20 , 20 , null ],
63+
"x": [ 1, 2, 3, 4, 5 , 6 , 7 , 8 , 9 , 10, 11 , 12 , null, 14 ],
64+
"y": [16, 18,17, 19,null ,16 , 20 , 20, null , 17, 18 , 18 , 20, 20 ],
6565
"mode": "lines+markers",
6666
"name": "hvh",
6767
"line": {"shape": "hvh"},
68-
"type": "scattergl"
68+
"type": "scattergl" , "xaxis": "x", "yaxis": "y"
6969
},{
70-
"x": [1, 2, 3, 4, 5 , 6 , 7 , 8 , 9 ],
71-
"y": [11, 13, 12, 14,null, 11, 15 , 15 , null ],
70+
"x": [ 1, 2, 3, 4, 5 , 6 , 7 , 8 , 9 , 10, 11 , 12 , null, 14 ],
71+
"y": [11, 13, 12, 14,null, 11, 15 , 15 , null , 11, 13 , 13 , 15, 15 ],
7272
"mode": "lines+markers",
7373
"name": "vhv",
7474
"line": {"shape": "vhv"},
75-
"type": "scattergl"
75+
"type": "scattergl" , "xaxis": "x", "yaxis": "y"
7676
},{
77-
"x": [1, 2, 3, 4, 5 , 6 , 7 , 8 , 9 ],
78-
"y": [6, 8, 7, 9,null, 6, 10 , 10 , null ],
77+
"x": [ 1, 2, 3, 4, 5 , 6 , 7 , 8 , 9 , 10, 11 , 12 , null, 14 ],
78+
"y": [ 6, 8, 7, 9,null , 6 , 10 , 10, null , 7, 8 , 8 , 10, 10 ],
7979
"mode": "lines+markers",
8080
"name": "spline",
8181
"line": {"shape": "spline","smoothing":4},
82-
"type": "scattergl"
82+
"type": "scattergl" , "xaxis": "x", "yaxis": "y"
8383
},{
84-
"x": [1, 2, 3, 4, 5 , 6 , 7 , 8 , 9 ],
85-
"y": [1, 3, 2, 4,null, 1 , 5 , 5 , null ],
84+
"x": [ 1, 2, 3, 4, 5 , 6 , 7 , 8 , 9 , 10, 11 , 12 , null, 14 ],
85+
"y": [ 1, 3, 2, 4,null, 1, 5 , 5 , null , 1, 3 , 3 , 5, 5 ],
8686
"mode": "lines+markers",
8787
"name": "linear",
8888
"line": {"shape": "linear"},
89-
"type": "scattergl"
89+
"type": "scattergl" , "xaxis": "x", "yaxis": "y"
90+
},{
91+
"x": [20,21, 22, 23, 24, 25 ,null, 26 , 27 , 28 , 29 ],
92+
"y": [null,26, 28, 27, 29,null,null, 26, 30, 30 , null ],
93+
"mode": "lines+markers","fill":"tozeroy",
94+
"name": "hv",
95+
"line": {"shape": "hv"},
96+
"type": "scatter" , "xaxis": "x2", "yaxis": "y2"
97+
},{
98+
"x": [20,21, 22, 23, 24, 25 ,null, 26 , 27 , 28 , 29 ],
99+
"y": [null,21, 23, 22, 24,null,null, 21, 25 , 25 , null ],
100+
"mode": "lines+markers","fill":"tozeroy",
101+
"name": "vh",
102+
"line": {"shape": "vh"},
103+
"type": "scatter" , "xaxis": "x2", "yaxis": "y2"
104+
},{
105+
"x": [20,21, 22, 23, 24, 25 , null , 26 , 27 , 28 , 29 ],
106+
"y": [null,16, 18, 17, 19,null,null , 16, 20 , 20 , null ],
107+
"mode": "lines+markers","fill":"tozeroy",
108+
"name": "hvh",
109+
"line": {"shape": "hvh"},
110+
"type": "scatter" , "xaxis": "x2", "yaxis": "y2"
111+
},
112+
{
113+
"x": [20,21, 22, 23, 24, 25 ,null, 26 , 27 , 28 , 29 ],
114+
"y": [null,11, 13, 12, 14,null,null, 11, 15 , 15 , null ],
115+
"mode": "lines+markers","fill":"tozeroy",
116+
"name": "vhv",
117+
"line": {"shape": "vhv"},
118+
"type": "scatter" , "xaxis": "x2", "yaxis": "y2"
119+
},
120+
{
121+
"x": [20,21, 22, 23, 24, 25 ,null, 26 , 27 , 28 , 29 ],
122+
"y": [null,6, 8, 7, 9,null, null, 6, 10 , 10 , null ],
123+
"mode": "lines+markers","fill":"tozeroy",
124+
"name": "spline",
125+
"line": {"shape": "spline","smoothing":4},
126+
"type": "scatter" , "xaxis": "x2", "yaxis": "y2"
127+
},
128+
{
129+
"x": [20,21, 22, 23, 24, 25 , 26 , 27 , 28 , 29 ],
130+
"y": [null,1, 3, 2, 4,null, 1 , 5 , 5 , null ],
131+
"mode": "lines+markers","fill":"tozeroy",
132+
"name": "linear",
133+
"line": {"shape": "linear"},
134+
"type": "scatter" , "xaxis": "x2", "yaxis": "y2"
135+
},{
136+
"x": [ 1, 2, 3, 4, 5 , 6 , 7 , 8 , 9 , 10, 11 , 12 , null, 14 ],
137+
"y": [26, 28, 27, 29,null ,26 , 30 , 30, null , 27, 28 , 28 , 30, 30 ],
138+
"mode": "lines+markers",
139+
"name": "hv",
140+
"line": {"shape": "hv"},
141+
"type": "scatter" , "xaxis": "x2", "yaxis": "y2"
142+
},{
143+
"x": [ 1, 2, 3, 4, 5 , 6 , 7 , 8 , 9 , 10, 11 , 12 , null, 14 ],
144+
"y": [21, 23, 22, 24,null, 21, 25 , 25 , null , 22, 23 , 23 , 25, 25 ],
145+
"mode": "lines+markers",
146+
"name": "vh",
147+
"line": {"shape": "vh"},
148+
"type": "scatter" , "xaxis": "x2", "yaxis": "y2"
149+
},{
150+
"x": [ 1, 2, 3, 4, 5 , 6 , 7 , 8 , 9 , 10, 11 , 12 , null, 14 ],
151+
"y": [16, 18,17, 19,null ,16 , 20 , 20, null , 17, 18 , 18 , 20, 20 ],
152+
"mode": "lines+markers",
153+
"name": "hvh",
154+
"line": {"shape": "hvh"},
155+
"type": "scatter" , "xaxis": "x2", "yaxis": "y2"
156+
},{
157+
"x": [ 1, 2, 3, 4, 5 , 6 , 7 , 8 , 9 , 10, 11 , 12 , null, 14 ],
158+
"y": [11, 13, 12, 14,null, 11, 15 , 15 , null , 11, 13 , 13 , 15, 15 ],
159+
"mode": "lines+markers",
160+
"name": "vhv",
161+
"line": {"shape": "vhv"},
162+
"type": "scatter" , "xaxis": "x2", "yaxis": "y2"
163+
},{
164+
"x": [ 1, 2, 3, 4, 5 , 6 , 7 , 8 , 9 , 10, 11 , 12 , null, 14 ],
165+
"y": [ 6, 8, 7, 9,null , 6 , 10 , 10, null , 7, 8 , 8 , 10, 10 ],
166+
"mode": "lines+markers",
167+
"name": "spline",
168+
"line": {"shape": "spline","smoothing":4},
169+
"type": "scatter" , "xaxis": "x2", "yaxis": "y2"
170+
},{
171+
"x": [ 1, 2, 3, 4, 5 , 6 , 7 , 8 , 9 , 10, 11 , 12 , null, 14 ],
172+
"y": [ 1, 3, 2, 4,null, 1, 5 , 5 , null , 1, 3 , 3 , 5, 5 ],
173+
"mode": "lines+markers",
174+
"name": "linear",
175+
"line": {"shape": "linear"},
176+
"type": "scatter" , "xaxis": "x2", "yaxis": "y2"
90177
}
91178
],
92179
"layout": {
93180
"margin": {
94-
"b": 100,
95-
"l": 100,
96-
"t": 100,
97-
"r": 100
98-
},
99-
"xaxis": {
100-
"title": "x1"
101-
},
102-
"yaxis": {
103-
"title": "y1"
181+
"b": 40,
182+
"l": 40,
183+
"t": 40,
184+
"r": 40
104185
},
105-
"dragmode": "zoom"
186+
"width": 700,"height": 700,
187+
"grid": {"columns": 1, "rows": 2, "pattern": "independent", "roworder": "bottom to top"} ,
188+
"xaxis": { "title": "GL x" },
189+
"yaxis": { "title": "GL y" },
190+
"xaxis2": { "title": "REG x" },
191+
"yaxis2": { "title": "REG y" },
192+
"dragmode": "zoom"
106193
}
107194
}

0 commit comments

Comments
 (0)