@@ -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
12551335describe ( '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