Skip to content
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

Fix trace-type update calls on mapbox subplots #4295

Merged
merged 2 commits into from
Oct 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 9 additions & 2 deletions src/plots/mapbox/mapbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,16 @@ proto.updateData = function(calcData) {
trace = calcTrace[0].trace;
traceObj = traceHash[trace.uid];

var didUpdate = false;
if(traceObj) {
traceObj.update(calcTrace);
} else if(trace._module) {
if(traceObj.type === trace.type) {
traceObj.update(calcTrace);
didUpdate = true;
} else {
traceObj.dispose();
}
}
if(!didUpdate && trace._module) {
traceHash[trace.uid] = trace._module.plot(this, calcTrace);
}
archmoj marked this conversation as resolved.
Show resolved Hide resolved
}
Expand Down
1 change: 1 addition & 0 deletions src/traces/choroplethmapbox/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions src/traces/densitymapbox/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions src/traces/scattermapbox/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
26 changes: 26 additions & 0 deletions test/jasmine/tests/densitymapbox_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});