Skip to content

Commit 41ad08a

Browse files
committed
push trace module into fullLayout._modules even if visible:false
- so that gl-based trace can call their plot methods w/ an empty array of traces and just work. - update and improve scatterlg visibility tests to reflect that `restyle(gd,visible,false)` no longer clear the context
1 parent 69dc0c4 commit 41ad08a

File tree

5 files changed

+18
-6
lines changed

5 files changed

+18
-6
lines changed

src/plots/cartesian/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ function plotOne(gd, plotinfo, cdSubplot, transitionOpts, makeOnCompleteCallback
216216
var className = (_module.layerName || name + 'layer');
217217
var plotMethod = _module.plot;
218218

219-
// plot all traces of this type on this subplot at once
219+
// plot all visible traces of this type on this subplot at once
220220
cdModuleAndOthers = getModuleCalcData(cdSubplot, plotMethod);
221221
cdModule = cdModuleAndOthers[0];
222222
// don't need to search the found traces again - in fact we need to NOT

src/plots/get_data.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ exports.getModuleCalcData = function(calcdata, arg1) {
6969
for(var i = 0; i < calcdata.length; i++) {
7070
var cd = calcdata[i];
7171
var trace = cd[0].trace;
72+
// N.B. 'legendonly' traces do not make it pass here
7273
if(trace.visible !== true) continue;
7374

7475
// group calcdata trace not by 'module' (as the name of this function

src/plots/plots.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ plots._hasPlotType = function(category) {
696696
if(basePlotModules[i].name === category) return true;
697697
}
698698

699-
// check trace modules
699+
// check trace modules (including non-visible:true)
700700
var modules = this._modules || [];
701701
for(i = 0; i < modules.length; i++) {
702702
var name = modules[i].name;
@@ -912,7 +912,7 @@ plots.supplyDataDefaults = function(dataIn, dataOut, layout, fullLayout) {
912912
var _module = fullTrace._module;
913913
if(!_module) return;
914914

915-
if(fullTrace.visible === true) Lib.pushUnique(modules, _module);
915+
Lib.pushUnique(modules, _module);
916916
Lib.pushUnique(basePlotModules, fullTrace._module.basePlotModule);
917917

918918
cnt++;

test/jasmine/tests/cartesian_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ describe('restyle', function() {
197197
return Plotly.restyle(gd, {visible: 'legendonly'}, 1);
198198
})
199199
.then(function() {
200-
expect(!!gd._fullLayout._plots.x2y2._scene).toBe(false);
200+
expect(!!gd._fullLayout._plots.x2y2._scene).toBe(true);
201201
return Plotly.restyle(gd, {visible: true}, 1);
202202
})
203203
.then(function() {

test/jasmine/tests/gl2d_plot_interact_test.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,27 +358,38 @@ describe('@gl Test gl2d plots', function() {
358358
var _mock = Lib.extendDeep({}, mock);
359359
_mock.data[0].line.width = 5;
360360

361+
function assertDrawCall(msg, exp) {
362+
var draw = gd._fullLayout._plots.xy._scene.scatter2d.draw;
363+
expect(draw).toHaveBeenCalledTimes(exp, msg);
364+
draw.calls.reset();
365+
}
366+
361367
Plotly.plot(gd, _mock)
362368
.then(delay(30))
363369
.then(function() {
370+
spyOn(gd._fullLayout._plots.xy._scene.scatter2d, 'draw');
364371
return Plotly.restyle(gd, 'visible', 'legendonly');
365372
})
366373
.then(function() {
367-
expect(gd.querySelector('.gl-canvas-context')).toBe(null);
374+
expect(readPixel(gd.querySelector('.gl-canvas-context'), 108, 100)[0]).toBe(0);
375+
assertDrawCall('legendonly', 0);
368376

369377
return Plotly.restyle(gd, 'visible', true);
370378
})
371379
.then(function() {
372380
expect(readPixel(gd.querySelector('.gl-canvas-context'), 108, 100)[0]).not.toBe(0);
381+
assertDrawCall('back to visible', 1);
373382

374383
return Plotly.restyle(gd, 'visible', false);
375384
})
376385
.then(function() {
377-
expect(gd.querySelector('.gl-canvas-context')).toBe(null);
386+
expect(readPixel(gd.querySelector('.gl-canvas-context'), 108, 100)[0]).toBe(0);
387+
assertDrawCall('visible false', 0);
378388

379389
return Plotly.restyle(gd, 'visible', true);
380390
})
381391
.then(function() {
392+
assertDrawCall('back up', 1);
382393
expect(readPixel(gd.querySelector('.gl-canvas-context'), 108, 100)[0]).not.toBe(0);
383394
})
384395
.catch(failTest)

0 commit comments

Comments
 (0)