Skip to content

Commit 6ae6283

Browse files
committed
DRY up scatter / scattergl fill ordering in linkTraces
1 parent 075bd14 commit 6ae6283

File tree

3 files changed

+13
-23
lines changed

3 files changed

+13
-23
lines changed

src/traces/scatter/link_traces.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,16 @@ module.exports = function linkTraces(gd, plotinfo, cdscatter) {
7575
}
7676
}
7777

78+
if(trace.fill && (
79+
trace.fill.substr(0, 6) === 'tozero' || trace.fill === 'toself' ||
80+
(trace.fill.substr(0, 2) === 'to' && !trace._prevtrace))
81+
) {
82+
trace._ownfill = true;
83+
}
84+
7885
prevtraces[group] = trace;
7986
} else {
80-
trace._prevtrace = trace._nexttrace = null;
87+
trace._prevtrace = trace._nexttrace = trace._ownfill = null;
8188
}
8289
}
8390

src/traces/scatter/plot.js

+3-12
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,10 @@ function createFills(gd, traceJoin, plotinfo) {
9393
var trace = d[0].trace;
9494

9595
var fillData = [];
96-
if(trace.fill && (trace.fill.substr(0, 6) === 'tozero' || trace.fill === 'toself' ||
97-
(trace.fill.substr(0, 2) === 'to' && !trace._prevtrace))
98-
) {
99-
fillData = ['_ownFill'];
100-
}
101-
if(trace._nexttrace) {
102-
// make the fill-to-next path now for the NEXT trace, so it shows
103-
// behind both lines.
104-
fillData.push('_nextFill');
105-
}
96+
if(trace._ownfill) fillData.push('_ownFill');
97+
if(trace._nexttrace) fillData.push('_nextFill');
10698

107-
var fillJoin = fills.selectAll('g')
108-
.data(fillData, identity);
99+
var fillJoin = fills.selectAll('g').data(fillData, identity);
109100

110101
fillJoin.enter().append('g');
111102

src/traces/scattergl/index.js

+2-10
Original file line numberDiff line numberDiff line change
@@ -436,16 +436,8 @@ function plot(gd, subplot, cdata) {
436436
var last, j;
437437

438438
var fillData = [];
439-
if(trace.fill && (trace.fill.substr(0, 6) === 'tozero' || trace.fill === 'toself' ||
440-
(trace.fill.substr(0, 2) === 'to' && !trace._prevtrace))
441-
) {
442-
fillData.push(i)
443-
}
444-
if(trace._nexttrace) {
445-
// make the fill-to-next path now for the NEXT trace, so it shows
446-
// behind both lines.
447-
fillData.push(i + 1);
448-
}
439+
if(trace._ownfill) fillData.push(i);
440+
if(trace._nexttrace) fillData.push(i + 1);
449441
if(fillData.length) scene.fillOrder[i] = fillData;
450442

451443
var pos = [], srcPos = (lineOptions && lineOptions.positions) || stash.positions;

0 commit comments

Comments
 (0)