Skip to content

Commit f170161

Browse files
committed
Merge pull request #570 from plotly/gl2d-replot
fix gl2d replot
2 parents 12c2d8c + 5033fd9 commit f170161

File tree

3 files changed

+48
-6
lines changed

3 files changed

+48
-6
lines changed

src/plots/gl2d/index.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,17 @@ exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout)
6969
var oldSceneKeys = Plots.getSubplotIds(oldFullLayout, 'gl2d');
7070

7171
for(var i = 0; i < oldSceneKeys.length; i++) {
72-
var oldSubplot = oldFullLayout._plots[oldSceneKeys[i]],
73-
xaName = oldSubplot.xaxis._name,
74-
yaName = oldSubplot.yaxis._name;
72+
var id = oldSceneKeys[i],
73+
oldSubplot = oldFullLayout._plots[id];
7574

76-
if(!!oldSubplot._scene2d && (!newFullLayout[xaName] || !newFullLayout[yaName])) {
75+
// old subplot wasn't gl2d; nothing to do
76+
if(!oldSubplot._scene2d) continue;
77+
78+
// if no traces are present, delete gl2d subplot
79+
var subplotData = Plots.getSubplotData(newFullData, 'gl2d', id);
80+
if(subplotData.length === 0) {
7781
oldSubplot._scene2d.destroy();
82+
delete oldFullLayout._plots[id];
7883
}
7984
}
8085
};

src/plots/plots.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ plots.getSubplotIds = function getSubplotIds(layout, type) {
193193
if(type === 'cartesian' && (!layout._has || !layout._has('cartesian'))) return [];
194194
if(type === 'gl2d' && (!layout._has || !layout._has('gl2d'))) return [];
195195
if(type === 'cartesian' || type === 'gl2d') {
196-
return Object.keys(layout._plots);
196+
return Object.keys(layout._plots || {});
197197
}
198198

199199
var idRegex = _module.idRegex,

test/jasmine/tests/gl_plot_interact_test.js

+38-1
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ describe('Test gl plot interactions', function() {
539539
expect(gd._fullLayout._plots.xy._scene2d.glplot).toBeDefined();
540540

541541
Plots.cleanPlot([], {}, gd._fullData, gd._fullLayout);
542-
expect(gd._fullLayout._plots.xy._scene2d.glplot).toBe(null);
542+
expect(gd._fullLayout._plots).toEqual({});
543543

544544
done();
545545
});
@@ -580,4 +580,41 @@ describe('Test gl plot side effects', function() {
580580
});
581581
});
582582
});
583+
584+
it('should be able to replot from a blank graph', function(done) {
585+
var gd = createGraphDiv();
586+
587+
function countCanvases(cnt) {
588+
var nodes = d3.selectAll('canvas');
589+
expect(nodes.size()).toEqual(cnt);
590+
}
591+
592+
var data = [{
593+
type: 'scattergl',
594+
x: [1, 2, 3],
595+
y: [2, 1, 2]
596+
}];
597+
598+
Plotly.plot(gd, []).then(function() {
599+
countCanvases(0);
600+
601+
return Plotly.plot(gd, data);
602+
}).then(function() {
603+
countCanvases(1);
604+
605+
return Plotly.purge(gd);
606+
}).then(function() {
607+
countCanvases(0);
608+
609+
return Plotly.plot(gd, data);
610+
}).then(function() {
611+
countCanvases(1);
612+
613+
return Plotly.deleteTraces(gd, [0]);
614+
}).then(function() {
615+
countCanvases(0);
616+
617+
return Plotly.purge(gd);
618+
}).then(done);
619+
});
583620
});

0 commit comments

Comments
 (0)