@@ -338,6 +338,17 @@ describe('mapbox plots', function() {
338
338
} ) ;
339
339
340
340
it ( 'should be able to restyle' , function ( done ) {
341
+ var restyleCnt = 0 ,
342
+ relayoutCnt = 0 ;
343
+
344
+ gd . on ( 'plotly_restyle' , function ( ) {
345
+ restyleCnt ++ ;
346
+ } ) ;
347
+
348
+ gd . on ( 'plotly_relayout' , function ( ) {
349
+ relayoutCnt ++ ;
350
+ } ) ;
351
+
341
352
function assertMarkerColor ( expectations ) {
342
353
return new Promise ( function ( resolve ) {
343
354
setTimeout ( function ( ) {
@@ -360,6 +371,9 @@ describe('mapbox plots', function() {
360
371
return Plotly . restyle ( gd , 'marker.color' , 'green' ) ;
361
372
} )
362
373
. then ( function ( ) {
374
+ expect ( restyleCnt ) . toEqual ( 1 ) ;
375
+ expect ( relayoutCnt ) . toEqual ( 0 ) ;
376
+
363
377
return assertMarkerColor ( [
364
378
[ 0 , 0.5019 , 0 , 1 ] ,
365
379
[ 0 , 0.5019 , 0 , 1 ]
@@ -369,6 +383,9 @@ describe('mapbox plots', function() {
369
383
return Plotly . restyle ( gd , 'marker.color' , 'red' , [ 1 ] ) ;
370
384
} )
371
385
. then ( function ( ) {
386
+ expect ( restyleCnt ) . toEqual ( 2 ) ;
387
+ expect ( relayoutCnt ) . toEqual ( 0 ) ;
388
+
372
389
return assertMarkerColor ( [
373
390
[ 0 , 0.5019 , 0 , 1 ] ,
374
391
[ 1 , 0 , 0 , 1 ]
@@ -378,6 +395,17 @@ describe('mapbox plots', function() {
378
395
} ) ;
379
396
380
397
it ( 'should be able to relayout' , function ( done ) {
398
+ var restyleCnt = 0 ,
399
+ relayoutCnt = 0 ;
400
+
401
+ gd . on ( 'plotly_restyle' , function ( ) {
402
+ restyleCnt ++ ;
403
+ } ) ;
404
+
405
+ gd . on ( 'plotly_relayout' , function ( ) {
406
+ relayoutCnt ++ ;
407
+ } ) ;
408
+
381
409
function assertLayout ( style , center , zoom , dims ) {
382
410
var mapInfo = getMapInfo ( gd ) ;
383
411
@@ -397,22 +425,37 @@ describe('mapbox plots', function() {
397
425
assertLayout ( 'Mapbox Dark' , [ - 4.710 , 19.475 ] , 1.234 , [ 80 , 100 , 908 , 270 ] ) ;
398
426
399
427
Plotly . relayout ( gd , 'mapbox.center' , { lon : 0 , lat : 0 } ) . then ( function ( ) {
428
+ expect ( restyleCnt ) . toEqual ( 0 ) ;
429
+ expect ( relayoutCnt ) . toEqual ( 1 ) ;
430
+
400
431
assertLayout ( 'Mapbox Dark' , [ 0 , 0 ] , 1.234 , [ 80 , 100 , 908 , 270 ] ) ;
401
432
402
433
return Plotly . relayout ( gd , 'mapbox.zoom' , '6' ) ;
403
434
} ) . then ( function ( ) {
435
+ expect ( restyleCnt ) . toEqual ( 0 ) ;
436
+ expect ( relayoutCnt ) . toEqual ( 2 ) ;
437
+
404
438
assertLayout ( 'Mapbox Dark' , [ 0 , 0 ] , 6 , [ 80 , 100 , 908 , 270 ] ) ;
405
439
406
440
return Plotly . relayout ( gd , 'mapbox.style' , 'light' ) ;
407
441
} ) . then ( function ( ) {
442
+ expect ( restyleCnt ) . toEqual ( 0 ) ;
443
+ expect ( relayoutCnt ) . toEqual ( 3 ) ;
444
+
408
445
assertLayout ( 'Mapbox Light' , [ 0 , 0 ] , 6 , [ 80 , 100 , 908 , 270 ] ) ;
409
446
410
447
return Plotly . relayout ( gd , 'mapbox.domain.x' , [ 0 , 0.5 ] ) ;
411
448
} ) . then ( function ( ) {
449
+ expect ( restyleCnt ) . toEqual ( 0 ) ;
450
+ expect ( relayoutCnt ) . toEqual ( 4 ) ;
451
+
412
452
assertLayout ( 'Mapbox Light' , [ 0 , 0 ] , 6 , [ 80 , 100 , 454 , 270 ] ) ;
413
453
414
454
return Plotly . relayout ( gd , 'mapbox.domain.y[0]' , 0.5 ) ;
415
455
} ) . then ( function ( ) {
456
+ expect ( restyleCnt ) . toEqual ( 0 ) ;
457
+ expect ( relayoutCnt ) . toEqual ( 5 ) ;
458
+
416
459
assertLayout ( 'Mapbox Light' , [ 0 , 0 ] , 6 , [ 80 , 100 , 454 , 135 ] ) ;
417
460
418
461
done ( ) ;
@@ -646,9 +689,11 @@ describe('mapbox plots', function() {
646
689
} ) ;
647
690
648
691
it ( 'should respond drag / scroll interactions' , function ( done ) {
649
- var updateData ;
692
+ var relayoutCnt = 0 ,
693
+ updateData ;
650
694
651
695
gd . on ( 'plotly_relayout' , function ( eventData ) {
696
+ relayoutCnt ++ ;
652
697
updateData = eventData ;
653
698
} ) ;
654
699
@@ -657,6 +702,9 @@ describe('mapbox plots', function() {
657
702
return _mouseEvent ( 'mousedown' , p0 , noop ) ;
658
703
} ) . then ( function ( ) {
659
704
return _mouseEvent ( 'mousemove' , p1 , noop ) ;
705
+ } ) . then ( function ( ) {
706
+ // repeat mousemove to simulate long dragging motion
707
+ return _mouseEvent ( 'mousemove' , p1 , noop ) ;
660
708
} ) . then ( function ( ) {
661
709
return _mouseEvent ( 'mouseup' , p1 , noop ) ;
662
710
} ) . then ( function ( ) {
@@ -689,6 +737,7 @@ describe('mapbox plots', function() {
689
737
var p1 = [ pointPos [ 0 ] + 50 , pointPos [ 1 ] - 20 ] ;
690
738
691
739
_drag ( pointPos , p1 , function ( ) {
740
+ expect ( relayoutCnt ) . toEqual ( 1 ) ;
692
741
assertLayout ( [ - 19.651 , 13.751 ] , 1.234 , { withUpdateData : true } ) ;
693
742
694
743
} )
0 commit comments