@@ -295,9 +295,10 @@ describe('mapbox plots', function() {
295
295
} ) . then ( function ( ) {
296
296
expect ( countVisibleTraces ( gd , modes ) ) . toEqual ( 2 ) ;
297
297
298
- mock . data [ 0 ] . visible = false ;
298
+ var mockCopy = Lib . extendDeep ( { } , mock ) ;
299
+ mockCopy . data [ 0 ] . visible = false ;
299
300
300
- return Plotly . newPlot ( gd , mock . data , mock . layout ) ;
301
+ return Plotly . newPlot ( gd , mockCopy . data , mockCopy . layout ) ;
301
302
} ) . then ( function ( ) {
302
303
expect ( countVisibleTraces ( gd , modes ) ) . toEqual ( 1 ) ;
303
304
@@ -344,6 +345,17 @@ describe('mapbox plots', function() {
344
345
} ) ;
345
346
346
347
it ( 'should be able to restyle' , function ( done ) {
348
+ var restyleCnt = 0 ,
349
+ relayoutCnt = 0 ;
350
+
351
+ gd . on ( 'plotly_restyle' , function ( ) {
352
+ restyleCnt ++ ;
353
+ } ) ;
354
+
355
+ gd . on ( 'plotly_relayout' , function ( ) {
356
+ relayoutCnt ++ ;
357
+ } ) ;
358
+
347
359
function assertMarkerColor ( expectations ) {
348
360
return new Promise ( function ( resolve ) {
349
361
setTimeout ( function ( ) {
@@ -366,6 +378,9 @@ describe('mapbox plots', function() {
366
378
return Plotly . restyle ( gd , 'marker.color' , 'green' ) ;
367
379
} )
368
380
. then ( function ( ) {
381
+ expect ( restyleCnt ) . toEqual ( 1 ) ;
382
+ expect ( relayoutCnt ) . toEqual ( 0 ) ;
383
+
369
384
return assertMarkerColor ( [
370
385
[ 0 , 0.5019 , 0 , 1 ] ,
371
386
[ 0 , 0.5019 , 0 , 1 ]
@@ -375,6 +390,9 @@ describe('mapbox plots', function() {
375
390
return Plotly . restyle ( gd , 'marker.color' , 'red' , [ 1 ] ) ;
376
391
} )
377
392
. then ( function ( ) {
393
+ expect ( restyleCnt ) . toEqual ( 2 ) ;
394
+ expect ( relayoutCnt ) . toEqual ( 0 ) ;
395
+
378
396
return assertMarkerColor ( [
379
397
[ 0 , 0.5019 , 0 , 1 ] ,
380
398
[ 1 , 0 , 0 , 1 ]
@@ -384,6 +402,17 @@ describe('mapbox plots', function() {
384
402
} ) ;
385
403
386
404
it ( 'should be able to relayout' , function ( done ) {
405
+ var restyleCnt = 0 ,
406
+ relayoutCnt = 0 ;
407
+
408
+ gd . on ( 'plotly_restyle' , function ( ) {
409
+ restyleCnt ++ ;
410
+ } ) ;
411
+
412
+ gd . on ( 'plotly_relayout' , function ( ) {
413
+ relayoutCnt ++ ;
414
+ } ) ;
415
+
387
416
function assertLayout ( style , center , zoom , dims ) {
388
417
var mapInfo = getMapInfo ( gd ) ;
389
418
@@ -403,22 +432,37 @@ describe('mapbox plots', function() {
403
432
assertLayout ( 'Mapbox Dark' , [ - 4.710 , 19.475 ] , 1.234 , [ 80 , 100 , 908 , 270 ] ) ;
404
433
405
434
Plotly . relayout ( gd , 'mapbox.center' , { lon : 0 , lat : 0 } ) . then ( function ( ) {
435
+ expect ( restyleCnt ) . toEqual ( 0 ) ;
436
+ expect ( relayoutCnt ) . toEqual ( 1 ) ;
437
+
406
438
assertLayout ( 'Mapbox Dark' , [ 0 , 0 ] , 1.234 , [ 80 , 100 , 908 , 270 ] ) ;
407
439
408
440
return Plotly . relayout ( gd , 'mapbox.zoom' , '6' ) ;
409
441
} ) . then ( function ( ) {
442
+ expect ( restyleCnt ) . toEqual ( 0 ) ;
443
+ expect ( relayoutCnt ) . toEqual ( 2 ) ;
444
+
410
445
assertLayout ( 'Mapbox Dark' , [ 0 , 0 ] , 6 , [ 80 , 100 , 908 , 270 ] ) ;
411
446
412
447
return Plotly . relayout ( gd , 'mapbox.style' , 'light' ) ;
413
448
} ) . then ( function ( ) {
449
+ expect ( restyleCnt ) . toEqual ( 0 ) ;
450
+ expect ( relayoutCnt ) . toEqual ( 3 ) ;
451
+
414
452
assertLayout ( 'Mapbox Light' , [ 0 , 0 ] , 6 , [ 80 , 100 , 908 , 270 ] ) ;
415
453
416
454
return Plotly . relayout ( gd , 'mapbox.domain.x' , [ 0 , 0.5 ] ) ;
417
455
} ) . then ( function ( ) {
456
+ expect ( restyleCnt ) . toEqual ( 0 ) ;
457
+ expect ( relayoutCnt ) . toEqual ( 4 ) ;
458
+
418
459
assertLayout ( 'Mapbox Light' , [ 0 , 0 ] , 6 , [ 80 , 100 , 454 , 270 ] ) ;
419
460
420
461
return Plotly . relayout ( gd , 'mapbox.domain.y[0]' , 0.5 ) ;
421
462
} ) . then ( function ( ) {
463
+ expect ( restyleCnt ) . toEqual ( 0 ) ;
464
+ expect ( relayoutCnt ) . toEqual ( 5 ) ;
465
+
422
466
assertLayout ( 'Mapbox Light' , [ 0 , 0 ] , 6 , [ 80 , 100 , 454 , 135 ] ) ;
423
467
424
468
done ( ) ;
@@ -652,9 +696,11 @@ describe('mapbox plots', function() {
652
696
} ) ;
653
697
654
698
it ( 'should respond drag / scroll interactions' , function ( done ) {
655
- var updateData ;
699
+ var relayoutCnt = 0 ,
700
+ updateData ;
656
701
657
702
gd . on ( 'plotly_relayout' , function ( eventData ) {
703
+ relayoutCnt ++ ;
658
704
updateData = eventData ;
659
705
} ) ;
660
706
@@ -663,6 +709,9 @@ describe('mapbox plots', function() {
663
709
return _mouseEvent ( 'mousedown' , p0 , noop ) ;
664
710
} ) . then ( function ( ) {
665
711
return _mouseEvent ( 'mousemove' , p1 , noop ) ;
712
+ } ) . then ( function ( ) {
713
+ // repeat mousemove to simulate long dragging motion
714
+ return _mouseEvent ( 'mousemove' , p1 , noop ) ;
666
715
} ) . then ( function ( ) {
667
716
return _mouseEvent ( 'mouseup' , p1 , noop ) ;
668
717
} ) . then ( function ( ) {
@@ -695,6 +744,7 @@ describe('mapbox plots', function() {
695
744
var p1 = [ pointPos [ 0 ] + 50 , pointPos [ 1 ] - 20 ] ;
696
745
697
746
_drag ( pointPos , p1 , function ( ) {
747
+ expect ( relayoutCnt ) . toEqual ( 1 ) ;
698
748
assertLayout ( [ - 19.651 , 13.751 ] , 1.234 , { withUpdateData : true } ) ;
699
749
700
750
} )
0 commit comments