8000 A slightly less ambitious take on orphan subplots and 'delete last trace' by etpinard · Pull Request #289 · plotly/plotly.js · GitHub
[go: up one dir, main page]

Skip to content

A slightly less ambitious take on orphan subplots and 'delete last trace' #289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Feb 29, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
generalize cleanScenes step:
- ensures the deleted geos are only properly removed from the DOM.
- ensures the deleted contour, heatmap and colorbar
  are properly removed
  • Loading branch information
etpinard committed Feb 26, 2016
commit d9ed49686c0c415500e53bd61bb9e0dffdfe0030
13 changes: 13 additions & 0 deletions src/plots/geo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,16 @@ exports.plot = function plotGeo(gd) {
geo.plot(fullGeoData, fullLayout, gd._promises);
}
};

exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout) {
var oldGeoKeys = Plots.getSubplotIds(oldFullLayout, 'geo');

for(var i = 0; i < oldGeoKeys.length; i++) {
var oldGeoKey = oldGeoKeys[i];
var oldGeo = oldFullLayout[oldGeoKey]._geo;

if(!newFullLayout[oldGeoKey] && !!oldGeo) {
oldGeo.geoDiv.remove();
}
}
};
12 changes: 12 additions & 0 deletions src/plots/gl3d/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ exports.plot = function plotGl3d(gd) {
}
};

exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout) {
var oldSceneKeys = Plots.getSubplotIds(oldFullLayout, 'gl3d');

for(var i = 0; i < oldSceneKeys.length; i++) {
var oldSceneKey = oldSceneKeys[i];

if(!newFullLayout[oldSceneKey] && !!oldFullLayout[oldSceneKey]._scene) {
oldFullLayout[oldSceneKey]._scene.destroy();
}
}
};

// clean scene ids, 'scene1' -> 'scene'
exports.cleanId = function cleanId(id) {
if (!id.match(/^scene[0-9]*$/)) return;
Expand Down
45 changes: 38 additions & 7 deletions src/plots/plots.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,8 @@ plots.supplyDefaults = function(gd) {
// finally, fill in the pieces of layout that may need to look at data
plots.supplyLayoutModuleDefaults(newLayout, newFullLayout, newFullData);

cleanScenes(newFullLayout, oldFullLayout);
// clean subplots and other artifacts from previous plot calls
cleanPlot(newFullData, newFullLayout, oldFullData, oldFullLayout);

/*
* Relink functions and underscore attributes to promote consistency between
Expand Down Expand Up @@ -475,16 +476,46 @@ plots.supplyDefaults = function(gd) {
}
};

function cleanScenes(newFullLayout, oldFullLayout) {
var oldSceneKeys = plots.getSubplotIds(oldFullLayout, 'gl3d');
function cleanPlot(newFullData, newFullLayout, oldFullData, oldFullLayout) {
var i, j;

for(var i = 0; i < oldSceneKeys.length; i++) {
var oldSceneKey = oldSceneKeys[i];
if(!newFullLayout[oldSceneKey] && !!oldFullLayout[oldSceneKey]._scene) {
oldFullLayout[oldSceneKey]._scene.destroy();
var plotTypes = Object.keys(subplotsRegistry);
for(i = 0; i < plotTypes.length; i++) {
var _module = subplotsRegistry[plotTypes[i]];

if(_module.clean) {
_module.clean(newFullData, newFullLayout, oldFullData, oldFullLayout);
}
}

var hasPaper = !!oldFullLayout._paper;
var hasInfoLayer = !!oldFullLayout._infolayer;

oldLoop:
for(i = 0; i < oldFullData.length; i++) {
var oldTrace = oldFullData[i],
oldUid = oldTrace.uid;

for(j = 0; j < newFullData.length; j++) {
var newTrace = newFullData[j];

if(oldUid === newTrace.uid) continue oldLoop;
}

// clean old heatmap and contour traces
if(hasPaper) {
oldFullLayout._paper.selectAll(
'.hm' + oldUid +
',.contour' + oldUid +
',#clip' + oldUid
).remove();
}

// clean old colorbars
if(hasInfoLayer) {
oldFullLayout._infolayer.selectAll('.cb' + oldUid).remove();
}
}
}

/**
Expand Down
0