Skip to content

Commit 0de9760

Browse files
committed
cartesian: factor per-subplot plot command
- .. into a plotOne function that works with any sufficiently mocked plotinfo objects and calcdata array
1 parent bedb673 commit 0de9760

File tree

1 file changed

+40
-32
lines changed

1 file changed

+40
-32
lines changed

src/plots/cartesian/index.js

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,16 @@ exports.attributes = require('./attributes');
3030
exports.transitionAxes = require('./transition_axes');
3131

3232
exports.plot = function(gd, traces, transitionOpts, makeOnCompleteCallback) {
33-
var cdSubplot, cd, trace, i, j, k;
34-
3533
var fullLayout = gd._fullLayout,
3634
subplots = Plots.getSubplotIds(fullLayout, 'cartesian'),
3735
calcdata = gd.calcdata,
38-
modules = fullLayout._modules;
36+
i;
3937

38+
// If traces is not provided, then it's a complete replot and missing
39+
// traces are removed
4040
if(!Array.isArray(traces)) {
41-
// If traces is not provided, then it's a complete replot and missing
42-
// traces are removed
4341
traces = [];
42+
4443
for(i = 0; i < calcdata.length; i++) {
4544
traces.push(i);
4645
}
@@ -51,11 +50,12 @@ exports.plot = function(gd, traces, transitionOpts, makeOnCompleteCallback) {
5150
subplotInfo = fullLayout._plots[subplot];
5251

5352
// Get all calcdata for this subplot:
54-
cdSubplot = [];
53+
var cdSubplot = [];
5554
var pcd;
56-
for(j = 0; j < calcdata.length; j++) {
57-
cd = calcdata[j];
58-
trace = cd[0].trace;
55+
56+
for(var j = 0; j < calcdata.length; j++) {
57+
var cd = calcdata[j],
58+
trace = cd[0].trace;
5959

6060
// Skip trace if whitelist provided and it's not whitelisted:
6161
// if (Array.isArray(traces) && traces.indexOf(i) === -1) continue;
@@ -81,37 +81,45 @@ exports.plot = function(gd, traces, transitionOpts, makeOnCompleteCallback) {
8181
}
8282
}
8383

84-
// remove old traces, then redraw everything
85-
// TODO: scatterlayer is manually excluded from this since it knows how
86-
// to update instead of fully removing and redrawing every time. The
87-
// remaining plot traces should also be able to do this. Once implemented,
88-
// we won't need this - which should sometimes be a big speedup.
89-
if(subplotInfo.plot) {
90-
subplotInfo.plot.selectAll('g:not(.scatterlayer)').selectAll('g.trace').remove();
91-
}
84+
plotOne(gd, subplotInfo, cdSubplot, transitionOpts, makeOnCompleteCallback);
85+
}
86+
};
87+
88+
function plotOne(gd, plotinfo, cdSubplot, transitionOpts, makeOnCompleteCallback) {
89+
var fullLayout = gd._fullLayout,
90+
modules = fullLayout._modules;
9291

93-
// Plot all traces for each module at once:
94-
for(j = 0; j < modules.length; j++) {
95-
var _module = modules[j];
92+
// remove old traces, then redraw everything
93+
//
94+
// TODO: scatterlayer is manually excluded from this since it knows how
95+
// to update instead of fully removing and redrawing every time. The
96+
// remaining plot traces should also be able to do this. Once implemented,
97+
// we won't need this - which should sometimes be a big speedup.
98+
if(plotinfo.plot) {
99+
plotinfo.plot.selectAll('g:not(.scatterlayer)').selectAll('g.trace').remove();
100+
}
96101

97-
// skip over non-cartesian trace modules
98-
if(_module.basePlotModule.name !== 'cartesian') continue;
102+
// plot all traces for each module at once
103+
for(var j = 0; j < modules.length; j++) {
104+
var _module = modules[j];
99105

100-
// plot all traces of this type on this subplot at once
101-
var cdModule = [];
102-
for(k = 0; k < cdSubplot.length; k++) {
103-
cd = cdSubplot[k];
106+
// skip over non-cartesian trace modules
107+
if(_module.basePlotModule.name !== 'cartesian') continue;
108+
109+
// plot all traces of this type on this subplot at once
110+
var cdModule = [];
111+
for(var k = 0; k < cdSubplot.length; k++) {
112+
var cd = cdSubplot[k],
104113
trace = cd[0].trace;
105114

106-
if((trace._module === _module) && (trace.visible === true)) {
107-
cdModule.push(cd);
108-
}
115+
if((trace._module === _module) && (trace.visible === true)) {
116+
cdModule.push(cd);
109117
}
110-
111-
_module.plot(gd, subplotInfo, cdModule, transitionOpts, makeOnCompleteCallback);
112118
}
119+
120+
_module.plot(gd, plotinfo, cdModule, transitionOpts, makeOnCompleteCallback);
113121
}
114-
};
122+
}
115123

116124
exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout) {
117125
var oldModules = oldFullLayout._modules || [],

0 commit comments

Comments
 (0)