Skip to content

Commit 3f9fe05

Browse files
committed
Modify scatter fill behavior
1 parent 2861127 commit 3f9fe05

File tree

3 files changed

+66
-18
lines changed

3 files changed

+66
-18
lines changed

src/traces/scatter/plot.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ function plotOne(gd, idx, plotinfo, cdscatter, cdscatterAll, element, transition
204204

205205
// initialize line join data / method
206206
var segments = [],
207-
lineSegments = [],
208207
makeUpdate = Lib.noop;
209208

210209
ownFillEl3 = trace._ownFill;
@@ -225,7 +224,7 @@ function plotOne(gd, idx, plotinfo, cdscatter, cdscatterAll, element, transition
225224
else if(line.shape === 'spline') {
226225
pathfn = revpathbase = function(pts) {
227226
var pLast = pts[pts.length - 1];
228-
if(pts[0][0] === pLast[0] && pts[0][1] === pLast[1]) {
227+
if(pts.length > 2 && pts[0][0] === pLast[0] && pts[0][1] === pLast[1]) {
229228
// identical start and end points: treat it as a
230229
// closed curve so we don't get a kink
231230
return Drawing.smoothclosed(pts.slice(1), line.smoothing);
@@ -270,10 +269,6 @@ function plotOne(gd, idx, plotinfo, cdscatter, cdscatterAll, element, transition
270269
pt1 = lastSegment[lastSegment.length - 1];
271270
}
272271

273-
lineSegments = segments.filter(function(s, i) {
274-
return s.length > 1 || i === segments.length - 1 || i === 0;
275-
});
276-
277272
makeUpdate = function(isEnter) {
278273
return function(pts) {
279274
thispath = pathfn(pts);
@@ -312,7 +307,7 @@ function plotOne(gd, idx, plotinfo, cdscatter, cdscatterAll, element, transition
312307
};
313308
}
314309

315-
var lineJoin = tr.selectAll('.js-line').data(lineSegments);
310+
var lineJoin = tr.selectAll('.js-line').data(segments);
316311

317312
transition(lineJoin.exit())
318313
.style('opacity', 0)
Loading

test/image/mocks/scatter_fill_corner_cases.json

Lines changed: 64 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,81 @@
22
"data": [
33
{
44
"x": [1.5],
5-
"y": [1.75],
6-
"fill": "tozeroy"
5+
"y": [1.25],
6+
"fill": "tozeroy",
7+
"showlegend": false
78
},
89
{
910
"x": [0, 1, 2, 3],
10-
"y": [1.5, null, 1.5, 1.5],
11-
"fill": "tozeroy"
11+
"y": [1, null, 1, 1],
12+
"fill": "tozeroy",
13+
"showlegend": false
1214
},
1315
{
1416
"x": [0, 1, 1.5, 2, 2.5, 3],
15-
"y": [1.25, 1.25, null, 1.35, null, 1.25, 1.25],
16-
"fill": "tozeroy"
17+
"y": [0.75, 0.75, null, 0.85, null, 0.75, 0.75],
18+
"fill": "tozeroy",
19+
"showlegend": false
1720
},
1821
{
1922
"x": [0, 1, 2, 3],
20-
"y": [1.0, 1.1, null, 1.0],
21-
"fill": "tozeroy"
23+
"y": [0.5, 0.6, null, 0.5],
24+
"fill": "tozeroy",
25+
"showlegend": false
2226
},
2327
{
2428
"x": [0, 1.5, 3],
25-
"y": [0.75, null, 0.75],
26-
"fill": "tozeroy"
29+
"y": [0.25, null, 0.25],
30+
"fill": "tozeroy",
31+
"showlegend": false
32+
},
33+
{
34+
"x": [1.5],
35+
"y": [1.25],
36+
"fill": "tozeroy",
37+
"line": {"shape": "spline"},
38+
"xaxis": "x2",
39+
"showlegend": false
40+
},
41+
{
42+
"x": [0, 1, 2, 3],
43+
"y": [1, null, 1, 1],
44+
"fill": "tozeroy",
45+
"line": {"shape": "spline"},
46+
"xaxis": "x2",
47+
"showlegend": false
48+
},
49+
{
50+
"x": [0, 1, 1.5, 2, 2.5, 3],
51+
"y": [0.75, 0.75, null, 0.85, null, 0.75, 0.75],
52+
"fill": "tozeroy",
53+
"line": {"shape": "spline"},
54+
"xaxis": "x2",
55+
"showlegend": false
56+
},
57+
{
58+
"x": [0, 1, 2, 3],
59+
"y": [0.5, 0.6, null, 0.5],
60+
"fill": "tozeroy",
61+
"line": {"shape": "spline"},
62+
"xaxis": "x2",
63+
"showlegend": false
64+
},
65+
{
66+
"x": [0, 1.5, 3],
67+
"y": [0.25, null, 0.25],
68+
"fill": "tozeroy",
69+
"line": {"shape": "spline"},
70+
"xaxis": "x2",
71+
"showlegend": false
72+
}
73+
],
74+
"layout": {
75+
"xaxis": {
76+
"domain": [0, 0.45]
77+
},
78+
"xaxis2": {
79+
"domain": [0.55, 1]
2780
}
28-
]
81+
}
2982
}

0 commit comments

Comments
 (0)