Skip to content

Commit 0fb65dd

Browse files
committed
first pass splom basePlotModule clean step
... the destroy method for regl-scattermatrix instance is broken, see gl-vis/regl-splom#3
1 parent 80dd61e commit 0fb65dd

File tree

3 files changed

+49
-12
lines changed

3 files changed

+49
-12
lines changed

src/plot_api/plot_api.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ exports.newPlot = function(gd, data, layout, config) {
666666
gd = Lib.getGraphDiv(gd);
667667

668668
// remove gl contexts
669-
Plots.cleanPlot([], {}, gd._fullData || {}, gd._fullLayout || {});
669+
Plots.cleanPlot([], {}, gd._fullData || {}, gd._fullLayout || {}, gd.calcdata || []);
670670

671671
Plots.purge(gd);
672672
return exports.plot(gd, data, layout, config);
@@ -3234,11 +3234,12 @@ exports.deleteFrames = function(gd, frameList) {
32343234
exports.purge = function purge(gd) {
32353235
gd = Lib.getGraphDiv(gd);
32363236

3237-
var fullLayout = gd._fullLayout || {},
3238-
fullData = gd._fullData || [];
3237+
var fullLayout = gd._fullLayout || {};
3238+
var fullData = gd._fullData || [];
3239+
var calcdata = gd.calcdata || [];
32393240

32403241
// remove gl contexts
3241-
Plots.cleanPlot([], {}, fullData, fullLayout);
3242+
Plots.cleanPlot([], {}, fullData, fullLayout, calcdata);
32423243

32433244
// purge properties
32443245
Plots.purge(gd);

src/plots/plots.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@ plots.supplyDefaults = function(gd) {
287287
var newFullData = gd._fullData = [];
288288
var newData = gd.data || [];
289289

290+
var oldCalcdata = gd.calcdata || [];
291+
290292
var context = gd._context || {};
291293

292294
var i, j;
@@ -428,7 +430,7 @@ plots.supplyDefaults = function(gd) {
428430
newFullLayout._hasPie = newFullLayout._has('pie');
429431

430432
// clean subplots and other artifacts from previous plot calls
431-
plots.cleanPlot(newFullData, newFullLayout, oldFullData, oldFullLayout);
433+
plots.cleanPlot(newFullData, newFullLayout, oldFullData, oldFullLayout, oldCalcdata);
432434

433435
// relink / initialize subplot axis objects
434436
plots.linkSubplots(newFullData, newFullLayout, oldFullData, oldFullLayout);
@@ -447,10 +449,10 @@ plots.supplyDefaults = function(gd) {
447449
}
448450

449451
// update object references in calcdata
450-
if((gd.calcdata || []).length === newFullData.length) {
452+
if(oldCalcdata === newFullData.length) {
451453
for(i = 0; i < newFullData.length; i++) {
452454
var newTrace = newFullData[i];
453-
var cd0 = gd.calcdata[i][0];
455+
var cd0 = oldCalcdata[i][0];
454456
if(cd0 && cd0.trace) {
455457
if(cd0.trace._hasCalcTransform) {
456458
remapTransformedArrays(cd0, newTrace);
@@ -648,15 +650,15 @@ plots._hasPlotType = function(category) {
648650
return false;
649651
};
650652

651-
plots.cleanPlot = function(newFullData, newFullLayout, oldFullData, oldFullLayout) {
653+
plots.cleanPlot = function(newFullData, newFullLayout, oldFullData, oldFullLayout, oldCalcdata) {
652654
var i, j;
653655

654656
var basePlotModules = oldFullLayout._basePlotModules || [];
655657
for(i = 0; i < basePlotModules.length; i++) {
656658
var _module = basePlotModules[i];
657659

658660
if(_module.clean) {
659-
_module.clean(newFullData, newFullLayout, oldFullData, oldFullLayout);
661+
_module.clean(newFullData, newFullLayout, oldFullData, oldFullLayout, oldCalcdata);
660662
}
661663
}
662664

src/traces/splom/base_plot.js

+37-3
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,43 @@ function showZeroLine(ax) {
186186
);
187187
}
188188

189-
function clean(newFullData, newFullLayout, oldFullData, oldFullLayout) {
190-
// TODO clear regl-splom instances
191-
// TODO clear regl-line2d grid instance!
189+
function clean(newFullData, newFullLayout, oldFullData, oldFullLayout, oldCalcdata) {
190+
var oldModules = oldFullLayout._modules || [];
191+
var newModules = newFullLayout._modules || [];
192+
193+
var hadSplom, hasSplom;
194+
var i;
195+
196+
for(i = 0; i < oldModules.length; i++) {
197+
if(oldModules[i].name === 'splom') {
198+
hadSplom = true;
199+
break;
200+
}
201+
}
202+
for(i = 0; i < newModules.length; i++) {
203+
if(newModules[i].name === 'splom') {
204+
hasSplom = true;
205+
break;
206+
}
207+
}
208+
209+
if(hadSplom && !hasSplom) {
210+
for(i = 0; i < oldCalcdata.length; i++) {
211+
var cd0 = oldCalcdata[i][0];
212+
var trace = cd0.trace;
213+
var scene = cd0.t._scene;
214+
215+
if(trace.type === 'splom' && scene && scene.matrix) {
216+
// this below throws as error
217+
// scene.matrix.destroy();
218+
}
219+
}
220+
}
221+
222+
if(oldFullLayout._splomGrid &&
223+
(!newFullLayout._hasOnlyLargeSploms && oldFullLayout._hasOnlyLargeSploms)) {
224+
oldFullLayout._splomGrid.destroy();
225+
}
192226

193227
Cartesian.clean(newFullData, newFullLayout, oldFullData, oldFullLayout);
194228
}

0 commit comments

Comments
 (0)