@@ -1216,7 +1216,7 @@ describe('Test geo interactions', function() {
1216
1216
}
1217
1217
1218
1218
gd . calcdata = undefined ;
1219
- Plotly . plot ( gd ) ;
1219
+ Plotly . newPlot ( gd , gd . data , gd . layout ) ;
1220
1220
i ++ ;
1221
1221
} , INTERVAL ) ;
1222
1222
} ) ;
@@ -1247,7 +1247,7 @@ describe('Test geo interactions', function() {
1247
1247
}
1248
1248
1249
1249
gd . calcdata = undefined ;
1250
- Plotly . plot ( gd ) ;
1250
+ Plotly . newPlot ( gd , gd . data , gd . layout ) ;
1251
1251
i ++ ;
1252
1252
} , INTERVAL ) ;
1253
1253
} ) ;
@@ -1278,7 +1278,7 @@ describe('Test geo interactions', function() {
1278
1278
}
1279
1279
1280
1280
gd . calcdata = undefined ;
1281
- Plotly . plot ( gd ) ;
1281
+ Plotly . newPlot ( gd , gd . data , gd . layout ) ;
1282
1282
i ++ ;
1283
1283
} , INTERVAL ) ;
1284
1284
} ) ;
@@ -1293,7 +1293,8 @@ describe('Test geo interactions', function() {
1293
1293
trace1 . locations . shift ( ) ;
1294
1294
1295
1295
gd . calcdata = undefined ;
1296
- Plotly . plot ( gd ) . then ( function ( ) {
1296
+ Plotly . newPlot ( gd , gd . data , gd . layout )
1297
+ . then ( function ( ) {
1297
1298
expect ( countTraces ( 'scattergeo' ) ) . toBe ( 1 ) ;
1298
1299
expect ( countTraces ( 'choropleth' ) ) . toBe ( 1 ) ;
1299
1300
@@ -1319,7 +1320,8 @@ describe('Test geo interactions', function() {
1319
1320
trace1 . z = zQueue ;
1320
1321
1321
1322
gd . calcdata = undefined ;
1322
- Plotly . plot ( gd ) . then ( function ( ) {
1323
+ Plotly . newPlot ( gd , gd . data , gd . layout )
1324
+ . then ( function ( ) {
1323
1325
expect ( countTraces ( 'scattergeo' ) ) . toBe ( 1 ) ;
1324
1326
expect ( countTraces ( 'choropleth' ) ) . toBe ( 1 ) ;
1325
1327
@@ -2108,16 +2110,16 @@ describe('Test geo zoom/pan/drag interactions:', function() {
2108
2110
var eventData ;
2109
2111
var dblClickCnt = 0 ;
2110
2112
2111
- afterEach ( destroyGraphDiv ) ;
2113
+ beforeEach ( function ( ) { gd = createGraphDiv ( ) ; } ) ;
2112
2114
2113
- function plot ( fig ) {
2114
- gd = createGraphDiv ( ) ;
2115
+ afterEach ( destroyGraphDiv ) ;
2115
2116
2117
+ var newPlot = function ( fig ) {
2116
2118
return Plotly . newPlot ( gd , fig ) . then ( function ( ) {
2117
2119
gd . on ( 'plotly_relayout' , function ( d ) { eventData = d ; } ) ;
2118
2120
gd . on ( 'plotly_doubleclick' , function ( ) { dblClickCnt ++ ; } ) ;
2119
2121
} ) ;
2120
- }
2122
+ } ;
2121
2123
2122
2124
function assertEventData ( msg , eventKeys ) {
2123
2125
if ( eventKeys === 'dblclick' ) {
@@ -2196,7 +2198,7 @@ describe('Test geo zoom/pan/drag interactions:', function() {
2196
2198
}
2197
2199
2198
2200
it ( '- base case' , function ( done ) {
2199
- plot ( fig ) . then ( function ( ) {
2201
+ newPlot ( fig ) . then ( function ( ) {
2200
2202
_assert ( 'base' , [
2201
2203
[ - 90 , 0 ] , [ - 90 , 0 ] , 1
2202
2204
] , [
@@ -2261,7 +2263,7 @@ describe('Test geo zoom/pan/drag interactions:', function() {
2261
2263
it ( '- fitbounds case' , function ( done ) {
2262
2264
fig . layout . geo . fitbounds = 'locations' ;
2263
2265
2264
- plot ( fig ) . then ( function ( ) {
2266
+ newPlot ( fig ) . then ( function ( ) {
2265
2267
_assert ( 'base' , [
2266
2268
[ undefined , 0 ] , [ undefined , undefined ] , undefined
2267
2269
] , [
@@ -2345,7 +2347,7 @@ describe('Test geo zoom/pan/drag interactions:', function() {
2345
2347
}
2346
2348
2347
2349
it ( '- base case' , function ( done ) {
2348
- plot ( fig ) . then ( function ( ) {
2350
+ newPlot ( fig ) . then ( function ( ) {
2349
2351
_assert ( 'base' , [
2350
2352
[ - 75 , 45 ] , 1
2351
2353
] , [
@@ -2408,7 +2410,7 @@ describe('Test geo zoom/pan/drag interactions:', function() {
2408
2410
it ( '- fitbounds case' , function ( done ) {
2409
2411
fig . layout . geo . fitbounds = 'locations' ;
2410
2412
2411
- plot ( fig ) . then ( function ( ) {
2413
+ newPlot ( fig ) . then ( function ( ) {
2412
2414
_assert ( 'base' , [
2413
2415
[ undefined , undefined ] , undefined
2414
2416
] , [
@@ -2496,7 +2498,7 @@ describe('Test geo zoom/pan/drag interactions:', function() {
2496
2498
}
2497
2499
2498
2500
it ( '- base case' , function ( done ) {
2499
- plot ( fig ) . then ( function ( ) {
2501
+ newPlot ( fig ) . then ( function ( ) {
2500
2502
_assert ( 'base' , [
2501
2503
[ 15 , 57.5 ] , 1 ,
2502
2504
] , [
@@ -2549,7 +2551,7 @@ describe('Test geo zoom/pan/drag interactions:', function() {
2549
2551
it ( '- fitbounds case' , function ( done ) {
2550
2552
fig . layout . geo . fitbounds = 'locations' ;
2551
2553
2552
- plot ( fig ) . then ( function ( ) {
2554
+ newPlot ( fig ) . then ( function ( ) {
2553
2555
_assert ( 'base' , [
2554
2556
[ undefined , undefined ] , undefined ,
2555
2557
] , [
@@ -2631,7 +2633,7 @@ describe('Test geo zoom/pan/drag interactions:', function() {
2631
2633
assertEventData ( msg , eventKeys ) ;
2632
2634
}
2633
2635
2634
- plot ( fig ) . then ( function ( ) {
2636
+ newPlot ( fig ) . then ( function ( ) {
2635
2637
_assert ( 'base' , [
2636
2638
[ - 96.6 , 38.7 ] , 1 ,
2637
2639
] , [
@@ -2689,7 +2691,7 @@ describe('Test geo zoom/pan/drag interactions:', function() {
2689
2691
fig . layout . width = 700 ;
2690
2692
fig . layout . height = 500 ;
2691
2693
2692
- plot ( fig )
2694
+ newPlot ( fig )
2693
2695
. then ( function ( ) { return scroll ( [ 131 , 159 ] , [ - 200 , 200 ] ) ; } )
2694
2696
. then ( function ( ) {
2695
2697
// scrolling outside subplot frame should log errors,
@@ -2719,7 +2721,7 @@ describe('Test geo zoom/pan/drag interactions:', function() {
2719
2721
assertEventData ( msg , eventKeys ) ;
2720
2722
}
2721
2723
2722
- plot ( fig )
2724
+ newPlot ( fig )
2723
2725
. then ( function ( ) {
2724
2726
_assert ( 'base' , [ 1 ] , [ 101.9 ] , undefined ) ;
2725
2727
} )
@@ -2730,12 +2732,24 @@ describe('Test geo zoom/pan/drag interactions:', function() {
2730
2732
[ 'geo.projection.rotation.lon' , 'geo.center.lon' , 'geo.center.lat' , 'geo.projection.scale' ]
2731
2733
) ;
2732
2734
} )
2733
- . then ( function ( ) { return Plotly . plot ( gd , [ ] , { } , { scrollZoom : false } ) ; } )
2735
+ . then ( function ( ) {
2736
+ return newPlot ( {
2737
+ data : gd . data ,
2738
+ layout : gd . layout ,
2739
+ config : { scrollZoom : false }
2740
+ } ) ;
2741
+ } )
2734
2742
. then ( function ( ) { return scroll ( [ 200 , 250 ] , [ - 200 , - 200 ] ) ; } )
2735
2743
. then ( function ( ) {
2736
2744
_assert ( 'with scrollZoom:false' , [ 1.3 ] , [ 134.4 ] , undefined ) ;
2737
2745
} )
2738
- . then ( function ( ) { return Plotly . plot ( gd , [ ] , { } , { scrollZoom : 'geo' } ) ; } )
2746
+ . then ( function ( ) {
2747
+ return newPlot ( {
2748
+ data : gd . data ,
2749
+ layout : gd . layout ,
2750
+ config : { scrollZoom : 'geo' }
2751
+ } ) ;
2752
+ } )
2739
2753
. then ( function ( ) { return scroll ( [ 200 , 250 ] , [ - 200 , - 200 ] ) ; } )
2740
2754
. then ( function ( ) {
2741
2755
_assert ( 'with scrollZoom:geo' ,
@@ -2745,44 +2759,59 @@ describe('Test geo zoom/pan/drag interactions:', function() {
2745
2759
} )
2746
2760
. then ( done , done . fail ) ;
2747
2761
} ) ;
2762
+ } ) ;
2748
2763
2749
- describe ( 'plotly_relayouting' , function ( ) {
2750
- var mocks = {
2751
- 'non-clipped' : require ( '@mocks/geo_winkel-tripel' ) ,
2752
- 'clipped' : require ( '@mocks/geo_orthographic' ) ,
2753
- 'scoped' : require ( '@mocks/geo_europe-bubbles' )
2754
- } ;
2755
- [ 'non-clipped' , 'clipped' , 'scoped' ] . forEach ( function ( zoomHandler ) {
2756
- [ 'pan' ] . forEach ( function ( dragmode ) {
2757
- it ( 'should emit events on ' + dragmode + ' for ' + zoomHandler , function ( done ) {
2758
- var events = [ ] ; var path = [ [ 300 , 300 ] , [ 350 , 300 ] , [ 350 , 400 ] ] ;
2759
- var relayoutCnt = 0 ; var relayoutEvent ;
2760
- var fig = Lib . extendDeep ( { } , mocks [ zoomHandler ] ) ;
2761
- fig . layout . dragmode = dragmode ;
2762
- fig . layout . width = 700 ;
2763
- fig . layout . height = 500 ;
2764
-
2765
- gd = createGraphDiv ( ) ;
2766
- Plotly . newPlot ( gd , fig )
2767
- . then ( function ( ) {
2768
- gd . on ( 'plotly_relayout' , function ( e ) {
2769
- relayoutCnt ++ ;
2770
- relayoutEvent = e ;
2771
- } ) ;
2772
- gd . on ( 'plotly_relayouting' , function ( e ) {
2773
- events . push ( e ) ;
2774
- } ) ;
2775
- return drag ( { path : path , noCover : true } ) ;
2776
- } )
2777
- . then ( function ( ) {
2778
- expect ( events . length ) . toEqual ( path . length - 1 ) ;
2779
- expect ( relayoutCnt ) . toEqual ( 1 ) ;
2780
- Object . keys ( relayoutEvent ) . sort ( ) . forEach ( function ( key ) {
2781
- expect ( Object . keys ( events [ 0 ] ) ) . toContain ( key ) ;
2782
- } ) ;
2783
- } )
2784
- . then ( done , done . fail ) ;
2785
- } ) ;
2764
+ describe ( 'plotly_relayouting' , function ( ) {
2765
+ var gd ;
2766
+ var events ;
2767
+ var relayoutCnt ;
2768
+ var relayoutEvent ;
2769
+
2770
+ beforeEach ( function ( ) { gd = createGraphDiv ( ) ; } ) ;
2771
+
2772
+ afterEach ( destroyGraphDiv ) ;
2773
+
2774
+ var newPlot = function ( fig ) {
2775
+ events = [ ] ;
2776
+ relayoutCnt = 0 ;
2777
+
2778
+ return Plotly . newPlot ( gd , fig ) . then ( function ( ) {
2779
+ gd . on ( 'plotly_relayout' , function ( e ) {
2780
+ relayoutCnt ++ ;
2781
+ relayoutEvent = e ;
2782
+ } ) ;
2783
+ gd . on ( 'plotly_relayouting' , function ( e ) {
2784
+ events . push ( e ) ;
2785
+ } ) ;
2786
+ } ) ;
2787
+ } ;
2788
+
2789
+ var mocks = {
2790
+ 'non-clipped' : require ( '@mocks/geo_winkel-tripel' ) ,
2791
+ 'clipped' : require ( '@mocks/geo_orthographic' ) ,
2792
+ 'scoped' : require ( '@mocks/geo_europe-bubbles' )
2793
+ } ;
2794
+ [ 'non-clipped' , 'clipped' , 'scoped' ] . forEach ( function ( zoomHandler ) {
2795
+ [ 'pan' ] . forEach ( function ( dragmode ) {
2796
+ it ( 'should emit events on ' + dragmode + ' for ' + zoomHandler , function ( done ) {
2797
+ var path = [ [ 300 , 300 ] , [ 350 , 300 ] , [ 350 , 400 ] ] ;
2798
+ var fig = Lib . extendDeep ( { } , mocks [ zoomHandler ] ) ;
2799
+ fig . layout . dragmode = dragmode ;
2800
+ fig . layout . width = 700 ;
2801
+ fig . layout . height = 500 ;
2802
+
2803
+ newPlot ( fig )
2804
+ . then ( function ( ) {
2805
+ return drag ( { path : path , noCover : true } ) ;
2806
+ } )
2807
+ . then ( function ( ) {
2808
+ expect ( events . length ) . toEqual ( path . length - 1 ) ;
2809
+ expect ( relayoutCnt ) . toEqual ( 1 ) ;
2810
+ Object . keys ( relayoutEvent ) . sort ( ) . forEach ( function ( key ) {
2811
+ expect ( Object . keys ( events [ 0 ] ) ) . toContain ( key ) ;
2812
+ } ) ;
2813
+ } )
2814
+ . then ( done , done . fail ) ;
2786
2815
} ) ;
2787
2816
} ) ;
2788
2817
} ) ;
0 commit comments