Skip to content

Commit 5c6576a

Browse files
committed
fix #2441 - don't attempt to draw empty option items
- refs to regl2d objects are kept even when options objects are emptied e.g. in the case of legend visible toggles, so don't try to redraw regl2d object with old options.
1 parent 3bff26f commit 5c6576a

File tree

2 files changed

+52
-7
lines changed

2 files changed

+52
-7
lines changed

src/traces/scattergl/index.js

+10-7
Original file line numberDiff line numberDiff line change
@@ -556,21 +556,24 @@ function sceneUpdate(gd, subplot) {
556556
scene.draw = function draw() {
557557
var i;
558558
for(i = 0; i < scene.count; i++) {
559-
if(scene.fill2d) scene.fill2d.draw(i);
559+
if(scene.fill2d && scene.fillOptions[i]) {
560+
// must do all fills first
561+
scene.fill2d.draw(i);
562+
}
560563
}
561564
for(i = 0; i < scene.count; i++) {
562-
if(scene.line2d) {
565+
if(scene.line2d && scene.lineOptions[i]) {
563566
scene.line2d.draw(i);
564567
}
565-
if(scene.error2d) {
568+
if(scene.error2d && scene.errorXOptions[i]) {
566569
scene.error2d.draw(i);
570+
}
571+
if(scene.error2d && scene.errorYOptions[i]) {
567572
scene.error2d.draw(i + scene.count);
568573
}
569-
if(scene.scatter2d) {
574+
if(scene.scatter2d && scene.markerOptions[i] && (!scene.selectBatch || !scene.selectBatch[i])) {
570575
// traces in no-selection mode
571-
if(!scene.selectBatch || !scene.selectBatch[i]) {
572-
scene.scatter2d.draw(i);
573-
}
576+
scene.scatter2d.draw(i);
574577
}
575578
}
576579

test/jasmine/tests/gl2d_plot_interact_test.js

+42
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,48 @@ describe('@gl Test gl2d plots', function() {
379379
.then(done);
380380
});
381381

382+
it('should be able to toggle trace with different modes', function(done) {
383+
Plotly.newPlot(gd, [{
384+
// a trace with all regl2d objects
385+
type: 'scattergl',
386+
y: [1, 2, 1],
387+
error_x: {value: 10},
388+
error_y: {value: 10},
389+
fill: 'tozeroy'
390+
}, {
391+
type: 'scattergl',
392+
mode: 'markers',
393+
y: [0, 1, -1]
394+
}])
395+
.then(function() {
396+
var scene = gd._fullLayout._plots.xy._scene;
397+
spyOn(scene.fill2d, 'draw');
398+
spyOn(scene.line2d, 'draw');
399+
spyOn(scene.error2d, 'draw');
400+
spyOn(scene.scatter2d, 'draw');
401+
402+
return Plotly.restyle(gd, 'visible', 'legendonly', [0]);
403+
})
404+
.then(function() {
405+
var scene = gd._fullLayout._plots.xy._scene;
406+
expect(scene.fill2d.draw).toHaveBeenCalledTimes(0);
407+
expect(scene.line2d.draw).toHaveBeenCalledTimes(0);
408+
expect(scene.error2d.draw).toHaveBeenCalledTimes(0);
409+
expect(scene.scatter2d.draw).toHaveBeenCalledTimes(1);
410+
411+
return Plotly.restyle(gd, 'visible', true, [0]);
412+
})
413+
.then(function() {
414+
var scene = gd._fullLayout._plots.xy._scene;
415+
expect(scene.fill2d.draw).toHaveBeenCalledTimes(1);
416+
expect(scene.line2d.draw).toHaveBeenCalledTimes(1);
417+
expect(scene.error2d.draw).toHaveBeenCalledTimes(2, 'twice for x AND y');
418+
expect(scene.scatter2d.draw).toHaveBeenCalledTimes(3, 'both traces have markers');
419+
})
420+
.catch(fail)
421+
.then(done);
422+
});
423+
382424
it('@noCI should display selection of big number of regular points', function(done) {
383425
// generate large number of points
384426
var x = [], y = [], n = 2e2, N = n * n;

0 commit comments

Comments
 (0)