Skip to content

Commit 1d4f7e6

Browse files
committed
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.
1 parent 48c6dfb commit 1d4f7e6

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

src/plots/geo/geo.js

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ function Geo(options, fullLayout) {
5656

5757
this.makeFramework();
5858
this.updateFx(fullLayout.hovermode);
59+
60+
this.traceHash = {};
5961
}
6062

6163
module.exports = Geo;
@@ -152,25 +154,47 @@ function filterData(dataIn) {
152154
}
153155

154156
proto.onceTopojsonIsLoaded = function(geoData, geoLayout) {
155-
var traceData = {};
157+
var i;
156158

157159
this.drawLayout(geoLayout);
158160

159-
for(var i = 0; i < geoData.length; i++) {
161+
var traceHashOld = this.traceHash;
162+
var traceHash = {};
163+
164+
for(i = 0; i < geoData.length; i++) {
160165
var trace = geoData[i];
161166

162-
traceData[trace.type] = traceData[trace.type] || [];
163-
traceData[trace.type].push(trace);
167+
traceHash[trace.type] = traceHash[trace.type] || [];
168+
traceHash[trace.type].push(trace);
164169
}
165170

166-
var traceKeys = Object.keys(traceData);
167-
for(var j = 0; j < traceKeys.length; j++){
168-
var moduleData = traceData[traceKeys[j]];
171+
var moduleNamesOld = Object.keys(traceHashOld);
172+
var moduleNames = Object.keys(traceHash);
173+
174+
// when a trace gets deleted, make sure that its module's
175+
// plot method is called so that it is properly
176+
// removed from the DOM.
177+
for(i = 0; i < moduleNamesOld.length; i++) {
178+
var moduleName = moduleNamesOld[i];
179+
180+
if(moduleNames.indexOf(moduleName) === -1) {
181+
var fakeModule = traceHashOld[moduleName][0];
182+
fakeModule.visible = false;
183+
traceHash[moduleName] = [fakeModule];
184+
}
185+
}
186+
187+
moduleNames = Object.keys(traceHash);
188+
189+
for(i = 0; i < moduleNames.length; i++) {
190+
var moduleData = traceHash[moduleNames[i]];
169191
var _module = moduleData[0]._module;
170192

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

196+
this.traceHash = traceHash;
197+
174198
this.render();
175199
};
176200

0 commit comments

Comments
 (0)