Skip to content

Commit 4abc139

Browse files
committed
fix #3831 - reset viewInitial stash on *geo.scope* updates
1 parent e26f8f4 commit 4abc139

File tree

2 files changed

+84
-2
lines changed

2 files changed

+84
-2
lines changed

src/plots/geo/geo.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ function Geo(opts) {
4242
this.topojson = null;
4343

4444
this.projection = null;
45+
this.scope = null;
4546
this.viewInitial = null;
4647
this.fitScale = null;
4748
this.bounds = null;
@@ -133,9 +134,10 @@ proto.update = function(geoCalcData, fullLayout) {
133134
}
134135
}
135136

136-
if(!this.viewInitial) {
137+
if(!this.viewInitial || this.scope !== geoLayout.scope) {
137138
this.saveViewInitial(geoLayout);
138139
}
140+
this.scope = geoLayout.scope;
139141

140142
this.updateBaseLayers(fullLayout, geoLayout);
141143
this.updateDims(fullLayout, geoLayout);

test/jasmine/tests/geo_test.js

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1250,6 +1250,86 @@ describe('Test geo interactions', function() {
12501250
.catch(failTest)
12511251
.then(done);
12521252
});
1253+
1254+
it('should reset viewInitial when update *scope*', function(done) {
1255+
var gd = createGraphDiv();
1256+
1257+
function _assertViewInitial(msg, exp) {
1258+
var viewInitial = gd._fullLayout.geo._subplot.viewInitial;
1259+
1260+
expect(Object.keys(viewInitial).length)
1261+
.toBe(Object.keys(exp).length, 'same # of viewInitial keys |' + msg);
1262+
1263+
for(var k in viewInitial) {
1264+
expect(viewInitial[k]).toBe(exp[k], k + ' |' + msg);
1265+
}
1266+
}
1267+
1268+
var figWorld = {
1269+
data: [{
1270+
type: 'choropleth',
1271+
locationmode: 'country names',
1272+
locations: ['canada', 'china', 'russia'],
1273+
z: ['10', '20', '15']
1274+
}],
1275+
layout: {geo: {scope: 'world'}}
1276+
};
1277+
var figUSA = {
1278+
data: [{
1279+
type: 'choropleth',
1280+
locationmode: 'USA-states',
1281+
locations: ['CA', 'CO', 'NY'],
1282+
z: ['10', '20', '15']
1283+
}],
1284+
layout: {geo: {scope: 'usa'}}
1285+
};
1286+
var figNA = {
1287+
data: [{
1288+
type: 'choropleth',
1289+
locationmode: 'country names',
1290+
locations: ['Canada', 'USA', 'Mexico'],
1291+
z: ['10', '20', '15']
1292+
}],
1293+
layout: {geo: {scope: 'north america'}}
1294+
};
1295+
1296+
Plotly.react(gd, figWorld)
1297+
.then(function() {
1298+
_assertViewInitial('world scope', {
1299+
'center.lon': 0,
1300+
'center.lat': 0,
1301+
'projection.scale': 1,
1302+
'projection.rotation.lon': 0
1303+
});
1304+
})
1305+
.then(function() { return Plotly.react(gd, figUSA); })
1306+
.then(function() {
1307+
_assertViewInitial('react to usa scope', {
1308+
'center.lon': -96.6,
1309+
'center.lat': 38.7,
1310+
'projection.scale': 1
1311+
});
1312+
})
1313+
.then(function() { return Plotly.react(gd, figNA); })
1314+
.then(function() {
1315+
_assertViewInitial('react to NA scope', {
1316+
'center.lon': -112.5,
1317+
'center.lat': 45,
1318+
'projection.scale': 1
1319+
});
1320+
})
1321+
.then(function() { return Plotly.react(gd, figWorld); })
1322+
.then(function() {
1323+
_assertViewInitial('react back to world scope', {
1324+
'center.lon': 0,
1325+
'center.lat': 0,
1326+
'projection.scale': 1,
1327+
'projection.rotation.lon': 0
1328+
});
1329+
})
1330+
.catch(failTest)
1331+
.then(done);
1332+
});
12531333
});
12541334

12551335
describe('Test event property of interactions on a geo plot:', function() {
@@ -1999,7 +2079,7 @@ describe('Test geo zoom/pan/drag interactions:', function() {
19992079
.then(done);
20002080
});
20012081

2002-
it('should guard againt undefined projection.invert result in some projections', function(done) {
2082+
it('should guard against undefined projection.invert result in some projections', function(done) {
20032083
// e.g. aitoff
20042084
var fig = Lib.extendDeep({}, require('@mocks/geo_aitoff-sinusoidal.json'));
20052085
fig.layout.dragmode = 'pan';

0 commit comments

Comments
 (0)