Skip to content

Faster trace visibility toggling #2837

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
2 changes: 1 addition & 1 deletion src/plots/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = {
values: [true, false, 'legendonly'],
role: 'info',
dflt: true,
editType: 'calc',
editType: 'plot',
description: [
'Determines whether or not this trace is visible.',
'If *legendonly*, the trace is not drawn,',
Expand Down
2 changes: 1 addition & 1 deletion src/plots/cartesian/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ function plotOne(gd, plotinfo, cdSubplot, transitionOpts, makeOnCompleteCallback
var className = (_module.layerName || name + 'layer');
var plotMethod = _module.plot;

// plot all traces of this type on this subplot at once
// plot all visible traces of this type on this subplot at once
cdModuleAndOthers = getModuleCalcData(cdSubplot, plotMethod);
cdModule = cdModuleAndOthers[0];
// don't need to search the found traces again - in fact we need to NOT
Expand Down
2 changes: 1 addition & 1 deletion src/plots/cartesian/type_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function getFirstNonEmptyTrace(data, id, axLetter) {

if(trace.type === 'splom' &&
trace._length > 0 &&
trace['_' + axLetter + 'axes'][id]
(trace['_' + axLetter + 'axes'] || {})[id]
) {
return trace;
}
Expand Down
1 change: 1 addition & 0 deletions src/plots/get_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ exports.getModuleCalcData = function(calcdata, arg1) {
for(var i = 0; i < calcdata.length; i++) {
var cd = calcdata[i];
var trace = cd[0].trace;
// N.B. 'legendonly' traces do not make it pass here
if(trace.visible !== true) continue;

// group calcdata trace not by 'module' (as the name of this function
Expand Down
19 changes: 12 additions & 7 deletions src/plots/plots.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ var extraFormatKeys = [
* gd._fullLayout._modules
* is a list of all the trace modules required to draw the plot.
*
* gd._fullLayout._visibleModules
* subset of _modules, a list of modules corresponding to visible:true traces.
*
* gd._fullLayout._basePlotModules
* is a list of all the plot modules required to draw the plot.
*
Expand Down Expand Up @@ -378,6 +381,7 @@ plots.supplyDefaults = function(gd, opts) {

// clear the lists of trace and baseplot modules, and subplots
newFullLayout._modules = [];
newFullLayout._visibleModules = [];
newFullLayout._basePlotModules = [];
var subplots = newFullLayout._subplots = emptySubplotLists();

Expand Down Expand Up @@ -420,7 +424,7 @@ plots.supplyDefaults = function(gd, opts) {
newFullLayout._has = plots._hasPlotType.bind(newFullLayout);

// special cases that introduce interactions between traces
var _modules = newFullLayout._modules;
var _modules = newFullLayout._visibleModules;
for(i = 0; i < _modules.length; i++) {
var _module = _modules[i];
if(_module.cleanData) _module.cleanData(newFullData);
Expand Down Expand Up @@ -696,7 +700,7 @@ plots._hasPlotType = function(category) {
if(basePlotModules[i].name === category) return true;
}

// check trace modules
// check trace modules (including non-visible:true)
var modules = this._modules || [];
for(i = 0; i < modules.length; i++) {
var name = modules[i].name;
Expand Down Expand Up @@ -898,6 +902,7 @@ plots.clearExpandedTraceDefaultColors = function(trace) {

plots.supplyDataDefaults = function(dataIn, dataOut, layout, fullLayout) {
var modules = fullLayout._modules;
var visibleModules = fullLayout._visibleModules;
var basePlotModules = fullLayout._basePlotModules;
var cnt = 0;
var colorCnt = 0;
Expand All @@ -912,9 +917,9 @@ plots.supplyDataDefaults = function(dataIn, dataOut, layout, fullLayout) {
var _module = fullTrace._module;
if(!_module) return;

if(fullTrace.visible === true) Lib.pushUnique(modules, _module);
Lib.pushUnique(modules, _module);
if(fullTrace.visible === true) Lib.pushUnique(visibleModules, _module);
Lib.pushUnique(basePlotModules, fullTrace._module.basePlotModule);

cnt++;

// TODO: do we really want color not to increment for explicitly invisible traces?
Expand Down Expand Up @@ -1475,7 +1480,7 @@ plots.supplyLayoutModuleDefaults = function(layoutIn, layoutOut, fullData, trans
}

// trace module layout defaults
var modules = layoutOut._modules;
var modules = layoutOut._visibleModules;
for(i = 0; i < modules.length; i++) {
_module = modules[i];

Expand Down Expand Up @@ -1579,7 +1584,7 @@ plots.purge = function(gd) {
};

plots.style = function(gd) {
var _modules = gd._fullLayout._modules;
var _modules = gd._fullLayout._visibleModules;
var styleModules = [];
var i;

Expand Down Expand Up @@ -2567,7 +2572,7 @@ function clearAxesCalc(axList) {
plots.doSetPositions = function(gd) {
var fullLayout = gd._fullLayout;
var subplots = fullLayout._subplots.cartesian;
var modules = fullLayout._modules;
var modules = fullLayout._visibleModules;
var methods = [];
var i, j;

Expand Down
Loading