Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/plots/gl2d/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,17 @@ exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout)
var oldSceneKeys = Plots.getSubplotIds(oldFullLayout, 'gl2d');

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

if(!!oldSubplot._scene2d && (!newFullLayout[xaName] || !newFullLayout[yaName])) {
// old subplot wasn't gl2d; nothing to do
if(!oldSubplot._scene2d) continue;

// if no traces are present, delete gl2d subplot
var subplotData = Plots.getSubplotData(newFullData, 'gl2d', id);
if(subplotData.length === 0) {
oldSubplot._scene2d.destroy();
delete oldFullLayout._plots[id];
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/plots/plots.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ plots.getSubplotIds = function getSubplotIds(layout, type) {
if(type === 'cartesian' && (!layout._has || !layout._has('cartesian'))) return [];
if(type === 'gl2d' && (!layout._has || !layout._has('gl2d'))) return [];
if(type === 'cartesian' || type === 'gl2d') {
return Object.keys(layout._plots);
return Object.keys(layout._plots || {});
}

var idRegex = _module.idRegex,
Expand Down
39 changes: 38 additions & 1 deletion test/jasmine/tests/gl_plot_interact_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ describe('Test gl plot interactions', function() {
expect(gd._fullLayout._plots.xy._scene2d.glplot).toBeDefined();

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

done();
});
Expand Down Expand Up @@ -580,4 +580,41 @@ describe('Test gl plot side effects', function() {
});
});
});

it('should be able to replot from a blank graph', function(done) {
var gd = createGraphDiv();

function assert(cnt) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe change the name of this. I know it's not really node code, but at a glance without seeing the function, it could be mistaken for the node assert.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

var nodes = d3.selectAll('canvas');
expect(nodes.size()).toEqual(cnt);
}

var data = [{
type: 'scattergl',
x: [1, 2, 3],
y: [2, 1, 2]
}];

Plotly.plot(gd, []).then(function() {
assert(0);

return Plotly.plot(gd, data);
}).then(function() {
assert(1);

return Plotly.purge(gd);
}).then(function() {
assert(0);

return Plotly.plot(gd, data);
}).then(function() {
assert(1);

return Plotly.deleteTraces(gd, [0]);
}).then(function() {
assert(0);

return Plotly.purge(gd);
}).then(done);
});
});