Skip to content

Commit 5bdc38f

Browse files
committed
add Plotly.purge method:
- built on top of Plots.purge. - In addition, clears <div class="plot-container"> - In addition, clears gl contexts using Plots.cleanPlot
1 parent 1395210 commit 5bdc38f

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/core.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ exports.prependTraces = Plotly.prependTraces;
2828
exports.addTraces = Plotly.addTraces;
2929
exports.deleteTraces = Plotly.deleteTraces;
3030
exports.moveTraces = Plotly.moveTraces;
31+
exports.purge = Plotly.purge;
3132
exports.setPlotConfig = require('./plot_api/set_plot_config');
3233
exports.register = Plotly.register;
3334

src/plot_api/plot_api.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2394,6 +2394,26 @@ Plotly.relayout = function relayout(gd, astr, val) {
23942394
});
23952395
};
23962396

2397+
Plotly.purge = function purge(gd) {
2398+
gd = getGraphDiv(gd);
2399+
2400+
var fullLayout = gd._fullLayout || {},
2401+
fullData = gd._fullData || [];
2402+
2403+
// remove gl contexts
2404+
Plots.cleanPlot([], {}, fullData, fullLayout);
2405+
2406+
// purge properties
2407+
Plots.purge(gd);
2408+
2409+
// remove plot container
2410+
if(fullLayout._container) fullLayout._container.remove();
2411+
2412+
// other stuff to delete ???
2413+
2414+
return gd;
2415+
};
2416+
23972417
/**
23982418
* Reduce all reserved margin objects to a single required margin reservation.
23992419
*
@@ -2493,7 +2513,7 @@ function makePlotFramework(gd) {
24932513
// Make the svg container
24942514
fullLayout._paperdiv = fullLayout._container.selectAll('.svg-container').data([0]);
24952515
fullLayout._paperdiv.enter().append('div')
2496-
.classed('svg-container',true)
2516+
.classed('svg-container', true)
24972517
.style('position','relative');
24982518

24992519
// Initial autosize

0 commit comments

Comments
 (0)