Skip to content

Commit df4017a

Browse files
committed
add simple shape for line in scattergl
still missing spline from scatter
1 parent cf40b10 commit df4017a

File tree

5 files changed

+126
-2
lines changed

5 files changed

+126
-2
lines changed

src/traces/scattergl/attributes.js

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ var attrs = module.exports = overrideAll({
5454
line: {
5555
color: scatterLineAttrs.color,
5656
width: scatterLineAttrs.width,
57+
shape: scatterLineAttrs.shape,
58+
smoothing: scatterLineAttrs.smoothing,
5759
dash: {
5860
valType: 'enumerated',
5961
values: Object.keys(DASHES),

src/traces/scattergl/convert.js

+59-2
Original file line numberDiff line numberDiff line change
@@ -393,17 +393,74 @@ 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])) {
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]);
399+
linePositions.push(positions[i * 2 + 1]);
400+
} else {
401+
linePositions.push(NaN);
402+
linePositions.push(NaN);
403+
}
397404
linePositions.push(NaN);
398405
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]);
412+
}
413+
}
414+
linePositions.push(positions[positions.length - 2]);
415+
linePositions.push(positions[positions.length - 1]);
416+
} else if(trace.line.shape === 'hvh') {
417+
linePositions = [];
418+
for(i = 0; i < count - 1; i++) {
419+
if(isNaN(positions[i * 2]) || isNaN(positions[i * 2 + 1]) || isNaN(positions[i * 2 + 2]) || isNaN(positions[i * 2 + 3])) {
420+
if(!isNaN(positions[i * 2]) && !isNaN(positions[i * 2 + 1])) {
421+
linePositions.push(positions[i * 2]);
422+
linePositions.push(positions[i * 2 + 1]);
423+
} else {
424+
linePositions.push(NaN);
425+
linePositions.push(NaN);
426+
}
399427
linePositions.push(NaN);
400428
linePositions.push(NaN);
401429
}
402430
else {
431+
var midPtX = (positions[i * 2] + positions[i * 2 + 2]) / 2;
403432
linePositions.push(positions[i * 2]);
404433
linePositions.push(positions[i * 2 + 1]);
405-
linePositions.push(positions[i * 2 + 2]);
434+
linePositions.push(midPtX);
406435
linePositions.push(positions[i * 2 + 1]);
436+
linePositions.push(midPtX);
437+
linePositions.push(positions[i * 2 + 3]);
438+
}
439+
}
440+
linePositions.push(positions[positions.length - 2]);
441+
linePositions.push(positions[positions.length - 1]);
442+
} else if(trace.line.shape === 'vhv') {
443+
linePositions = [];
444+
for(i = 0; i < count - 1; i++) {
445+
if(isNaN(positions[i * 2]) || isNaN(positions[i * 2 + 1]) || isNaN(positions[i * 2 + 2]) || isNaN(positions[i * 2 + 3])) {
446+
if(!isNaN(positions[i * 2]) && !isNaN(positions[i * 2 + 1])) {
447+
linePositions.push(positions[i * 2]);
448+
linePositions.push(positions[i * 2 + 1]);
449+
} else {
450+
linePositions.push(NaN);
451+
linePositions.push(NaN);
452+
}
453+
linePositions.push(NaN);
454+
linePositions.push(NaN);
455+
}
456+
else {
457+
var midPtY = (positions[i * 2 + 1] + positions[i * 2 + 3]) / 2;
458+
linePositions.push(positions[i * 2]);
459+
linePositions.push(positions[i * 2 + 1]);
460+
linePositions.push(positions[i * 2]);
461+
linePositions.push(midPtY);
462+
linePositions.push(positions[i * 2 + 2]);
463+
linePositions.push(midPtY);
407464
}
408465
}
409466
linePositions.push(positions[positions.length - 2]);

src/traces/scattergl/defaults.js

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ var subTypes = require('../scatter/subtypes');
1717
var handleXYDefaults = require('../scatter/xy_defaults');
1818
var handleMarkerDefaults = require('../scatter/marker_defaults');
1919
var handleLineDefaults = require('../scatter/line_defaults');
20+
var handleLineShapeDefaults = require('../scatter/line_shape_defaults');
2021
var handleFillColorDefaults = require('../scatter/fillcolor_defaults');
2122
var handleTextDefaults = require('../scatter/text_defaults');
2223

@@ -42,6 +43,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
4243
if(subTypes.hasLines(traceOut)) {
4344
coerce('connectgaps');
4445
handleLineDefaults(traceIn, traceOut, defaultColor, layout, coerce);
46+
handleLineShapeDefaults(traceIn, traceOut, coerce);
4547
}
4648

4749
if(subTypes.hasMarkers(traceOut)) {
25.1 KB
Loading

test/image/mocks/gl2d_shape_line.json

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"data": [
3+
{
4+
"x": [1, 2, 3, 4, 5 , 6 , 7 ],
5+
"y": [1, 3, 2, 4,null, 1 , 4 ],
6+
"mode": "lines+markers",
7+
"name": "linear",
8+
"line": {"shape": "linear"},
9+
"type": "scattergl"
10+
},{
11+
"x": [1, 2, 3, 4, 5 , 6 , 7 ],
12+
"y": [6, 8, 7, 9,null, 6, 9 ],
13+
"mode": "lines+markers",
14+
"name": "spline",
15+
"line": {"shape": "spline","smoothing":4},
16+
"type": "scattergl"
17+
},{
18+
"x": [1, 2, 3, 4, 5 , 6 , 7 ],
19+
"y": [11, 13, 12, 14,null, 11, 14 ],
20+
"mode": "lines+markers",
21+
"name": "vhv",
22+
"line": {"shape": "vhv"},
23+
"type": "scattergl"
24+
},{
25+
"x": [1, 2, 3, 4, 5 , 6 , 7 ],
26+
"y": [16, 18, 17, 19,null, 16, 19 ],
27+
"mode": "lines+markers",
28+
"name": "hvh",
29+
"line": {"shape": "hvh"},
30+
"type": "scattergl"
31+
},{
32+
"x": [1, 2, 3, 4, 5 , 6 , 7 ],
33+
"y": [21, 23, 22, 24,null, 21, 24 ],
34+
"mode": "lines+markers",
35+
"name": "vh",
36+
"line": {"shape": "vh"},
37+
"type": "scattergl"
38+
},{
39+
"x": [1, 2, 3, 4, 5 , 6 , 7 ],
40+
"y": [26, 28, 27, 29,null, 26, 29 ],
41+
"mode": "lines+markers",
42+
"name": "hv",
43+
"line": {"shape": "hv"},
44+
"type": "scattergl"
45+
}
46+
],
47+
"layout": {
48+
"margin": {
49+
"b": 100,
50+
"l": 100,
51+
"t": 100,
52+
"r": 100
53+
},
54+
"xaxis": {
55+
"title": "x1"
56+
},
57+
"yaxis": {
58+
"title": "y1"
59+
},
60+
"dragmode": "zoom",
61+
"legend": { "traceorder": "reversed" }
62+
}
63+
}

0 commit comments

Comments
 (0)