From d0a350606afb01920d1784a3b7b16dbd3b315637 Mon Sep 17 00:00:00 2001 From: Mojtaba Samimi Date: Wed, 19 Oct 2022 13:48:53 -0400 Subject: [PATCH 1/5] ensure updateOnSelect on choroplethmapbox - addressing dash 1097 --- src/traces/choroplethmapbox/index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/traces/choroplethmapbox/index.js b/src/traces/choroplethmapbox/index.js index 5c1f1ce8f43..323406c3c69 100644 --- a/src/traces/choroplethmapbox/index.js +++ b/src/traces/choroplethmapbox/index.js @@ -13,7 +13,12 @@ module.exports = { styleOnSelect: function(_, cd) { if(cd) { var trace = cd[0].trace; - trace._glTrace.updateOnSelect(cd); + if( + trace._glTrace && + trace._glTrace.updateOnSelect + ) { + trace._glTrace.updateOnSelect(cd); + } } }, From e6c883a3d5fe7ec91e26f9b751d9755e0ab459f7 Mon Sep 17 00:00:00 2001 From: Mojtaba Samimi Date: Fri, 21 Oct 2022 08:49:37 -0400 Subject: [PATCH 2/5] Revert "ensure updateOnSelect on choroplethmapbox - addressing dash 1097" This reverts commit d0a350606afb01920d1784a3b7b16dbd3b315637. --- src/traces/choroplethmapbox/index.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/traces/choroplethmapbox/index.js b/src/traces/choroplethmapbox/index.js index 323406c3c69..5c1f1ce8f43 100644 --- a/src/traces/choroplethmapbox/index.js +++ b/src/traces/choroplethmapbox/index.js @@ -13,12 +13,7 @@ module.exports = { styleOnSelect: function(_, cd) { if(cd) { var trace = cd[0].trace; - if( - trace._glTrace && - trace._glTrace.updateOnSelect - ) { - trace._glTrace.updateOnSelect(cd); - } + trace._glTrace.updateOnSelect(cd); } }, From 3ef486357e307d80cf488f9537ac77d9a7e80c73 Mon Sep 17 00:00:00 2001 From: Mojtaba Samimi Date: Fri, 21 Oct 2022 08:50:10 -0400 Subject: [PATCH 3/5] link to _glTrace for hover similar to scattermapbox --- src/traces/choroplethmapbox/plot.js | 3 +++ src/traces/scattermapbox/plot.js | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/traces/choroplethmapbox/plot.js b/src/traces/choroplethmapbox/plot.js index 874cf7c6cae..5cf3da2894b 100644 --- a/src/traces/choroplethmapbox/plot.js +++ b/src/traces/choroplethmapbox/plot.js @@ -26,6 +26,9 @@ var proto = ChoroplethMapbox.prototype; proto.update = function(calcTrace) { this._update(convert(calcTrace)); + + // link ref for quick update during selections + calcTrace[0].trace._glTrace = this; }; proto.updateOnSelect = function(calcTrace) { diff --git a/src/traces/scattermapbox/plot.js b/src/traces/scattermapbox/plot.js index 2814c7b6430..a04b3e5f222 100644 --- a/src/traces/scattermapbox/plot.js +++ b/src/traces/scattermapbox/plot.js @@ -130,7 +130,7 @@ proto.update = function update(calcTrace) { this.clusterEnabled = hasCluster; } - // link ref for quick update during selections + // link ref for quick update during selections calcTrace[0].trace._glTrace = this; }; From 464718c5580c6c2752bc0646491ce4d5262915a7 Mon Sep 17 00:00:00 2001 From: Mojtaba Samimi Date: Fri, 21 Oct 2022 10:33:24 -0400 Subject: [PATCH 4/5] add jasmine tests to lock issue 6346 --- test/jasmine/tests/select_test.js | 63 ++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/test/jasmine/tests/select_test.js b/test/jasmine/tests/select_test.js index 421516a5f7c..f8782aa82ce 100644 --- a/test/jasmine/tests/select_test.js +++ b/test/jasmine/tests/select_test.js @@ -30,7 +30,7 @@ function _newPlot(gd, arg2, arg3, arg4) { if(!fig.layout) fig.layout = {}; if(!fig.layout.newselection) fig.layout.newselection = {}; fig.layout.newselection.mode = 'gradual'; - // complex ouline creation are mainly tested in "gradual" mode here + // complex ouline creation are mainly tested in 'gradual' mode here return Plotly.newPlot(gd, fig); } @@ -3030,6 +3030,67 @@ describe('Test select box and lasso per trace:', function() { .then(done, done.fail); }); }); + + it('@gl should work on choroplethmapbox traces after adding a new trace on top:', function(done) { + var assertPoints = makeAssertPoints(['location', 'z']); + var assertRanges = makeAssertRanges('mapbox'); + var assertLassoPoints = makeAssertLassoPoints('mapbox'); + var assertSelectedPoints = makeAssertSelectedPoints(); + + var fig = Lib.extendDeep({}, require('@mocks/mapbox_choropleth0.json')); + + fig.data[0].locations.push(null); + + fig.layout.dragmode = 'select'; + fig.config = { + mapboxAccessToken: require('@build/credentials.json').MAPBOX_ACCESS_TOKEN + }; + addInvisible(fig); + + var hasCssTransform = false; + + _newPlot(gd, fig) + .then(function() { + // add a scatter points on top + fig.data[3] = { + type: 'scattermapbox', + marker: { size: 40 }, + lon: [-70], + lat: [40] + }; + + return Plotly.react(gd, fig); + }) + .then(function() { + return _run(hasCssTransform, + [[150, 150], [300, 300]], + function() { + assertPoints([['NY', 10]]); + assertRanges([[-83.38, 46.13], [-74.06, 39.29]]); + assertSelectedPoints({0: [0], 3: []}); + }, + null, BOXEVENTS, 'choroplethmapbox select' + ); + }) + .then(function() { + return Plotly.relayout(gd, 'dragmode', 'lasso'); + }) + .then(function() { + return _run(hasCssTransform, + [[300, 200], [300, 300], [400, 300], [400, 200], [300, 200]], + function() { + assertPoints([['MA', 20], []]); + assertSelectedPoints({0: [1], 3: [0]}); + assertLassoPoints([ + [-74.06, 43.936], [-74.06, 39.293], [-67.84, 39.293], + [-67.84, 43.936], [-74.06, 43.936] + ]); + }, + null, LASSOEVENTS, 'choroplethmapbox lasso' + ); + }) + .then(done, done.fail); + }, LONG_TIMEOUT_INTERVAL); }); describe('Test that selections persist:', function() { From 126e53551c30ad3ed1e7686e0970d5eed1fda4d1 Mon Sep 17 00:00:00 2001 From: Mojtaba Samimi Date: Fri, 21 Oct 2022 10:36:07 -0400 Subject: [PATCH 5/5] draft log for PR 6345 --- draftlogs/6345_fix.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 draftlogs/6345_fix.md diff --git a/draftlogs/6345_fix.md b/draftlogs/6345_fix.md new file mode 100644 index 00000000000..75bb1dc6b63 --- /dev/null +++ b/draftlogs/6345_fix.md @@ -0,0 +1 @@ + - Fix `choroplethmapbox` selection when adding new traces on top [[#6345](https://github.com/plotly/plotly.js/pull/6345)]