8000 Sanitize orphan subplot logic and 'last trace' deletion by etpinard · Pull Request #268 · plotly/plotly.js · GitHub
[go: up one dir, main page]

Skip to content

Sanitize orphan subplot logic and 'last trace' deletion #268

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

Closed
wants to merge 19 commits into from
Closed
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
make removing geo trace work:
- by keeping track of traces in each geo from call to call,
- make sure that its module's plot method is called
  so that it is properly removed from the DOM.
  • Loading branch information
etpinard committed Feb 19, 2016
commit 0a6991e8a93a1cfb13765f8595fc34c79525f27b
38 changes: 31 additions & 7 deletions src/plots/geo/geo.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ function Geo(options, fullLayout) {

this.makeFramework();
this.updateFx(fullLayout.hovermode);

this.traceHash = {};
}

module.exports = Geo;
Expand Down Expand Up @@ -152,25 +154,47 @@ function filterData(dataIn) {
}

proto.onceTopojsonIsLoaded = function(geoData, geoLayout) {
var traceData = {};
var i;

this.drawLayout(geoLayout);

for(var i = 0; i < geoData.length; i++) {
var traceHashOld = this.traceHash;
var traceHash = {};

for(i = 0; i < geoData.length; i++) {
var trace = geoData[i];

traceData[trace.type] = traceData[trace.type] || [];
traceData[trace.type].push(trace);
traceHash[trace.type] = traceHash[trace.type] || [];
traceHash[trace.type].push(trace);
}

var traceKeys = Object.keys(traceData);
for(var j = 0; j < traceKeys.length; j++){
var moduleData = traceData[traceKeys[j]];
var moduleNamesOld = Object.keys(traceHashOld);
var moduleNames = Object.keys(traceHash);

// when a trace gets deleted, make sure that its module's
// plot method is called so that it is properly
// removed from the DOM.
for(i = 0; i < moduleNamesOld.length; i++) {
var moduleName = moduleNamesOld[i];

if(moduleNames.indexOf(moduleName) === -1) {
var fakeModule = traceHashOld[moduleName][0];
fakeModule.visible = false;
traceHash[moduleName] = [fakeModule];
}
}

moduleNames = Object.keys(traceHash);

for(i = 0; i < moduleNames.length; i++) {
var moduleData = traceHash[moduleNames[i]];
var _module = moduleData[0]._module;

_module.plot(this, filterData(moduleData), geoLayout);
}

this.traceHash = traceHash;

this.render();
};

Expand Down
0