Skip to content

Commit e0add44

Browse files
committed
Merge pull request #125 from plotly/modebar-destructor
Destroy modebar in purge step
2 parents 4248c00 + d38a61b commit e0add44

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

src/plots/plots.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,9 @@ plots.purge = function(gd) {
682682
if(fullLayout._glcontainer !== undefined) fullLayout._glcontainer.remove();
683683
if(fullLayout._geocontainer !== undefined) fullLayout._geocontainer.remove();
684684

685+
// remove modebar
686+
if(fullLayout._modeBar) fullLayout._modeBar.destroy();
687+
685688
// data and layout
686689
delete gd.data;
687690
delete gd.layout;

test/jasmine/tests/plots_test.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
var Plotly = require('@src/plotly');
2+
var createGraphDiv = require('../assets/create_graph_div');
3+
var destroyGraphDiv = require('../assets/destroy_graph_div');
24

35
describe('Test Plotly.Plots', function () {
46
'use strict';
@@ -298,4 +300,50 @@ describe('Test Plotly.Plots', function () {
298300
});
299301

300302
});
303+
304+
describe('Plotly.Plots.purge', function () {
305+
var gd;
306+
307+
beforeEach(function (done) {
308+
gd = createGraphDiv();
309+
Plotly.plot(gd, [{ x: [1,2,3], y: [2,3,4] }], {}).then(done);
310+
});
311+
312+
afterEach(destroyGraphDiv);
313+
314+
it('should unset everything in the gd except _context', function () {
315+
var expectedKeys = [
316+
'_ev', 'on', 'once', 'removeListener', 'removeAllListeners',
317+
'emit', '_context', '_replotPending', '_mouseDownTime',
318+
'_hmpixcount', '_hmlumcount'
319+
];
320+
321+
Plotly.Plots.purge(gd);
322+
expect(Object.keys(gd)).toEqual(expectedKeys);
323+
expect(gd.data).toBeUndefined();
324+
expect(gd.layout).toBeUndefined();
325+
expect(gd._fullData).toBeUndefined();
326+
expect(gd._fullLayout).toBeUndefined();
327+
expect(gd.calcdata).toBeUndefined();
328+
expect(gd.framework).toBeUndefined();
329+
expect(gd.empty).toBeUndefined();
330+
expect(gd.fid).toBeUndefined();
331+
expect(gd.undoqueue).toBeUndefined();
332+
expect(gd.undonum).toBeUndefined();
333+
expect(gd.autoplay).toBeUndefined();
334+
expect(gd.changed).toBeUndefined();
335+
expect(gd._modules).toBeUndefined();
336+
expect(gd._tester).toBeUndefined();
337+
expect(gd._testref).toBeUndefined();
338+
expect(gd._promises).toBeUndefined();
339+
expect(gd._redrawTimer).toBeUndefined();
340+
expect(gd._replotting).toBeUndefined();
341+
expect(gd.firstscatter).toBeUndefined();
342+
expect(gd.hmlumcount).toBeUndefined();
343+
expect(gd.hmpixcount).toBeUndefined();
344+
expect(gd.numboxes).toBeUndefined();
345+
expect(gd._hoverTimer).toBeUndefined();
346+
expect(gd._lastHoverTime).toBeUndefined();
347+
});
348+
});
301349
});

0 commit comments

Comments
 (0)