Skip to content

Commit d47276f

Browse files
committed
make visible trace module -> layer data a 1D loop w/ + indexOf + sort
- I don't see the need to optimize here using e.g a lookup object. traceLayerClasses.length ~ 10, and fullLayout._modules.length < 20, most often 1 or 2.
1 parent 3bef9a9 commit d47276f

File tree

1 file changed

+24
-26
lines changed

1 file changed

+24
-26
lines changed

src/plots/cartesian/index.js

+24-26
Original file line numberDiff line numberDiff line change
@@ -189,36 +189,34 @@ function plotOne(gd, plotinfo, cdSubplot, transitionOpts, makeOnCompleteCallback
189189

190190
var layerData = [];
191191

192-
for(var i = 0; i < traceLayerClasses.length; i++) {
193-
var className = traceLayerClasses[i];
194-
195-
for(var j = 0; j < modules.length; j++) {
196-
_module = modules[j];
197-
198-
if(_module.basePlotModule.name === 'cartesian' &&
199-
(_module.layerName || _module.name + 'layer') === className
200-
) {
201-
var plotMethod = _module.plot;
202-
203-
// plot all traces of this type on this subplot at once
204-
cdModuleAndOthers = getModuleCalcData(cdSubplot, plotMethod);
205-
cdModule = cdModuleAndOthers[0];
206-
// don't need to search the found traces again - in fact we need to NOT
207-
// so that if two modules share the same plotter we don't double-plot
208-
cdSubplot = cdModuleAndOthers[1];
209-
210-
if(cdModule.length) {
211-
layerData.push({
212-
className: className,
213-
plotMethod: plotMethod,
214-
cdModule: cdModule
215-
});
216-
}
217-
break;
192+
for(var i = 0; i < modules.length; i++) {
193+
_module = modules[i];
194+
var name = _module.name;
195+
196+
if(Registry.modules[name].categories.svg) {
197+
var className = (_module.layerName || name + 'layer');
198+
var plotMethod = _module.plot;
199+
200+
// plot all traces of this type on this subplot at once
201+
cdModuleAndOthers = getModuleCalcData(cdSubplot, plotMethod);
202+
cdModule = cdModuleAndOthers[0];
203+
// don't need to search the found traces again - in fact we need to NOT
204+
// so that if two modules share the same plotter we don't double-plot
205+
cdSubplot = cdModuleAndOthers[1];
206+
207+
if(cdModule.length) {
208+
layerData.push({
209+
i: traceLayerClasses.indexOf(className),
210+
className: className,
211+
plotMethod: plotMethod,
212+
cdModule: cdModule
213+
});
218214
}
219215
}
220216
}
221217

218+
layerData.sort(function(a, b) { return a.i - b.i; });
219+
222220
var layers = plotinfo.plot.selectAll('g.mlayer')
223221
.data(layerData, function(d) { return d.className; });
224222

0 commit comments

Comments
 (0)