Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions src/plots/plots.js
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,9 @@ plots.purge = function(gd) {
if(fullLayout._glcontainer !== undefined) fullLayout._glcontainer.remove();
if(fullLayout._geocontainer !== undefined) fullLayout._geocontainer.remove();

// remove modebar
if(fullLayout._modeBar) fullLayout._modeBar.destroy();

// data and layout
delete gd.data;
delete gd.layout;
Expand Down
48 changes: 48 additions & 0 deletions test/jasmine/tests/plots_test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var Plotly = require('@src/plotly');
var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');

describe('Test Plotly.Plots', function () {
'use strict';
Expand Down Expand Up @@ -298,4 +300,50 @@ describe('Test Plotly.Plots', function () {
});

});

describe('Plotly.Plots.purge', function () {
var gd;

beforeEach(function (done) {
gd = createGraphDiv();
Plotly.plot(gd, [{ x: [1,2,3], y: [2,3,4] }], {}).then(done);
});

afterEach(destroyGraphDiv);

it('should unset everything in the gd except _context', function () {
var expectedKeys = [
'_ev', 'on', 'once', 'removeListener', 'removeAllListeners',
'emit', '_context', '_replotPending', '_mouseDownTime',
'_hmpixcount', '_hmlumcount'
];

Plotly.Plots.purge(gd);
expect(Object.keys(gd)).toEqual(expectedKeys);
Copy link
Contributor

Choose a reason for hiding this comment

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

@mdtusz great test 🎉 thanks for doing this.

expect(gd.data).toBeUndefined();
expect(gd.layout).toBeUndefined();
expect(gd._fullData).toBeUndefined();
expect(gd._fullLayout).toBeUndefined();
expect(gd.calcdata).toBeUndefined();
expect(gd.framework).toBeUndefined();
expect(gd.empty).toBeUndefined();
expect(gd.fid).toBeUndefined();
expect(gd.undoqueue).toBeUndefined();
expect(gd.undonum).toBeUndefined();
expect(gd.autoplay).toBeUndefined();
expect(gd.changed).toBeUndefined();
expect(gd._modules).toBeUndefined();
expect(gd._tester).toBeUndefined();
expect(gd._testref).toBeUndefined();
expect(gd._promises).toBeUndefined();
expect(gd._redrawTimer).toBeUndefined();
expect(gd._replotting).toBeUndefined();
expect(gd.firstscatter).toBeUndefined();
expect(gd.hmlumcount).toBeUndefined();
expect(gd.hmpixcount).toBeUndefined();
expect(gd.numboxes).toBeUndefined();
expect(gd._hoverTimer).toBeUndefined();
expect(gd._lastHoverTime).toBeUndefined();
});
});
});