From e89eb06cd5847200f42a80439b01fa29e3e01904 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Tue, 22 Oct 2019 14:11:18 -0400 Subject: [PATCH 1/2] fix trace-type update calls on mapbox subplots --- src/plots/mapbox/mapbox.js | 7 ++++++- src/traces/choroplethmapbox/plot.js | 1 + src/traces/densitymapbox/plot.js | 1 + src/traces/scattermapbox/plot.js | 1 + test/jasmine/tests/densitymapbox_test.js | 26 ++++++++++++++++++++++++ 5 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/plots/mapbox/mapbox.js b/src/plots/mapbox/mapbox.js index bc798ca3ae2..6606dba0d1a 100644 --- a/src/plots/mapbox/mapbox.js +++ b/src/plots/mapbox/mapbox.js @@ -316,7 +316,12 @@ proto.updateData = function(calcData) { traceObj = traceHash[trace.uid]; if(traceObj) { - traceObj.update(calcTrace); + if(traceObj.type === trace.type) { + traceObj.update(calcTrace); + } else { + traceObj.dispose(); + traceHash[trace.uid] = trace._module.plot(this, calcTrace); + } } else if(trace._module) { traceHash[trace.uid] = trace._module.plot(this, calcTrace); } diff --git a/src/traces/choroplethmapbox/plot.js b/src/traces/choroplethmapbox/plot.js index f6e236e2027..3fbb9026cce 100644 --- a/src/traces/choroplethmapbox/plot.js +++ b/src/traces/choroplethmapbox/plot.js @@ -13,6 +13,7 @@ var convertOnSelect = require('./convert').convertOnSelect; var LAYER_PREFIX = require('../../plots/mapbox/constants').traceLayerPrefix; function ChoroplethMapbox(subplot, uid) { + this.type = 'choroplethmapbox'; this.subplot = subplot; this.uid = uid; diff --git a/src/traces/densitymapbox/plot.js b/src/traces/densitymapbox/plot.js index 9a6a5a55403..c4b26c8af7b 100644 --- a/src/traces/densitymapbox/plot.js +++ b/src/traces/densitymapbox/plot.js @@ -12,6 +12,7 @@ var convert = require('./convert'); var LAYER_PREFIX = require('../../plots/mapbox/constants').traceLayerPrefix; function DensityMapbox(subplot, uid) { + this.type = 'densitymapbox'; this.subplot = subplot; this.uid = uid; diff --git a/src/traces/scattermapbox/plot.js b/src/traces/scattermapbox/plot.js index 55c2e910dcb..2fa66fc0ca7 100644 --- a/src/traces/scattermapbox/plot.js +++ b/src/traces/scattermapbox/plot.js @@ -13,6 +13,7 @@ var LAYER_PREFIX = require('../../plots/mapbox/constants').traceLayerPrefix; var ORDER = ['fill', 'line', 'circle', 'symbol']; function ScatterMapbox(subplot, uid) { + this.type = 'scattermapbox'; this.subplot = subplot; this.uid = uid; diff --git a/test/jasmine/tests/densitymapbox_test.js b/test/jasmine/tests/densitymapbox_test.js index 9503d3ab506..3fb5f67e61f 100644 --- a/test/jasmine/tests/densitymapbox_test.js +++ b/test/jasmine/tests/densitymapbox_test.js @@ -497,4 +497,30 @@ describe('@noCI Test densitymapbox interactions:', function() { .catch(failTest) .then(done); }, 5 * jasmine.DEFAULT_TIMEOUT_INTERVAL); + + it('@gl should be able to restyle from and to *scattermapbox*', function(done) { + function _assert(msg, exp) { + var traceHash = gd._fullLayout.mapbox._subplot.traceHash; + expect(Object.keys(traceHash).length).toBe(1, 'one visible trace| ' + msg); + for(var k in traceHash) { + expect(traceHash[k].type).toBe(exp, 'trace type| ' + msg); + } + } + + Plotly.plot(gd, [{ + type: 'densitymapbox', + lon: [10, 20, 30], + lat: [15, 25, 35], + z: [1, 20, 5] + }], {}, { + mapboxAccessToken: MAPBOX_ACCESS_TOKEN + }) + .then(function() { _assert('after first', 'densitymapbox'); }) + .then(function() { return Plotly.restyle(gd, 'type', 'scattermapbox'); }) + .then(function() { _assert('after restyle to scattermapbox', 'scattermapbox'); }) + .then(function() { return Plotly.restyle(gd, 'type', 'densitymapbox'); }) + .then(function() { _assert('back to densitymapbox', 'densitymapbox'); }) + .catch(failTest) + .then(done); + }, 5 * jasmine.DEFAULT_TIMEOUT_INTERVAL); }); From 5427dc047bb3e2e58333b1662b8e74d1f20f7557 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Tue, 22 Oct 2019 14:56:38 -0400 Subject: [PATCH 2/2] mojtaba-proof logic --- src/plots/mapbox/mapbox.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/plots/mapbox/mapbox.js b/src/plots/mapbox/mapbox.js index 6606dba0d1a..c8ab4b1e650 100644 --- a/src/plots/mapbox/mapbox.js +++ b/src/plots/mapbox/mapbox.js @@ -315,14 +315,16 @@ proto.updateData = function(calcData) { trace = calcTrace[0].trace; traceObj = traceHash[trace.uid]; + var didUpdate = false; if(traceObj) { if(traceObj.type === trace.type) { traceObj.update(calcTrace); + didUpdate = true; } else { traceObj.dispose(); - traceHash[trace.uid] = trace._module.plot(this, calcTrace); } - } else if(trace._module) { + } + if(!didUpdate && trace._module) { traceHash[trace.uid] = trace._module.plot(this, calcTrace); } }