@@ -3,6 +3,7 @@ var Plots = require('@src/plots/plots');
3
3
var Lib = require ( '@src/lib' ) ;
4
4
5
5
var convertModule = require ( '@src/traces/choroplethmapbox/convert' ) ;
6
+ var MAPBOX_ACCESS_TOKEN = require ( '@build/credentials.json' ) . MAPBOX_ACCESS_TOKEN ;
6
7
7
8
var createGraphDiv = require ( '../assets/create_graph_div' ) ;
8
9
var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
@@ -519,7 +520,7 @@ describe('@noCI Test choroplethmapbox hover:', function() {
519
520
520
521
if ( ! fig . layout ) fig . layout = { } ;
521
522
if ( ! fig . layout . mapbox ) fig . layout . mapbox = { } ;
522
- fig . layout . mapbox . accesstoken = require ( '@build/credentials.json' ) . MAPBOX_ACCESS_TOKEN ;
523
+ fig . layout . mapbox . accesstoken = MAPBOX_ACCESS_TOKEN ;
523
524
524
525
var pos = s . pos || [ 270 , 220 ] ;
525
526
@@ -579,3 +580,133 @@ describe('@noCI Test choroplethmapbox hover:', function() {
579
580
} ) ;
580
581
} ) ;
581
582
} ) ;
583
+
584
+ describe ( '@noCI Test choroplethmapbox interactions:' , function ( ) {
585
+ var gd ;
586
+
587
+ var geojson = {
588
+ type : 'Feature' ,
589
+ id : 'AL' ,
590
+ geometry : {
591
+ type : 'Polygon' ,
592
+ coordinates : [ [
593
+ [ - 87.359296 , 35.00118 ] , [ - 85.606675 , 34.984749 ] , [ - 85.431413 , 34.124869 ] , [ - 85.184951 , 32.859696 ] ,
594
+ [ - 85.069935 , 32.580372 ] , [ - 84.960397 , 32.421541 ] , [ - 85.004212 , 32.322956 ] , [ - 84.889196 , 32.262709 ] ,
595
+ [ - 85.058981 , 32.13674 ] , [ - 85.053504 , 32.01077 ] , [ - 85.141136 , 31.840985 ] , [ - 85.042551 , 31.539753 ] ,
596
+ [ - 85.113751 , 31.27686 ] , [ - 85.004212 , 31.003013 ] , [ - 85.497137 , 30.997536 ] , [ - 87.600282 , 30.997536 ] ,
597
+ [ - 87.633143 , 30.86609 ] , [ - 87.408589 , 30.674397 ] , [ - 87.446927 , 30.510088 ] , [ - 87.37025 , 30.427934 ] ,
598
+ [ - 87.518128 , 30.280057 ] , [ - 87.655051 , 30.247195 ] , [ - 87.90699 , 30.411504 ] , [ - 87.934375 , 30.657966 ] ,
599
+ [ - 88.011052 , 30.685351 ] , [ - 88.10416 , 30.499135 ] , [ - 88.137022 , 30.318396 ] , [ - 88.394438 , 30.367688 ] ,
600
+ [ - 88.471115 , 31.895754 ] , [ - 88.241084 , 33.796253 ] , [ - 88.098683 , 34.891641 ] , [ - 88.202745 , 34.995703 ] ,
601
+ [ - 87.359296 , 35.00118 ]
602
+ ] ]
603
+ }
604
+ } ;
605
+
606
+ beforeEach ( function ( ) {
607
+ gd = createGraphDiv ( ) ;
608
+ } ) ;
609
+
610
+ afterEach ( function ( done ) {
611
+ Plotly . purge ( gd ) ;
612
+ destroyGraphDiv ( ) ;
613
+ setTimeout ( done , 200 ) ;
614
+ } ) ;
615
+
616
+ it ( '@gl should be able to add and remove traces' , function ( done ) {
617
+ function _assert ( msg , exp ) {
618
+ var map = gd . _fullLayout . mapbox . _subplot . map ;
619
+ var layers = map . getStyle ( ) . layers ;
620
+
621
+ expect ( layers . length ) . toBe ( exp . layerCnt , 'total # of layers |' + msg ) ;
622
+ }
623
+
624
+ var trace0 = {
625
+ type : 'choroplethmapbox' ,
626
+ locations : [ 'AL' ] ,
627
+ z : [ 10 ] ,
628
+ geojson : geojson
629
+ } ;
630
+
631
+ var trace1 = {
632
+ type : 'choroplethmapbox' ,
633
+ locations : [ 'AL' ] ,
634
+ z : [ 1 ] ,
635
+ geojson : geojson ,
636
+ marker : { opacity : 0.3 }
637
+ } ;
638
+
639
+ Plotly . plot ( gd ,
640
+ [ trace0 , trace1 ] ,
641
+ { mapbox : { style : 'basic' } } ,
642
+ { mapboxAccessToken : MAPBOX_ACCESS_TOKEN }
643
+ )
644
+ . then ( function ( ) {
645
+ _assert ( 'base' , { layerCnt : 24 } ) ;
646
+ } )
647
+ . then ( function ( ) { return Plotly . deleteTraces ( gd , [ 0 ] ) ; } )
648
+ . then ( function ( ) {
649
+ _assert ( 'w/o trace0' , { layerCnt : 22 } ) ;
650
+ } )
651
+ . then ( function ( ) { return Plotly . addTraces ( gd , [ trace0 ] ) ; } )
652
+ . then ( function ( ) {
653
+ _assert ( 'after adding trace0' , { layerCnt : 24 } ) ;
654
+ } )
655
+ . catch ( failTest )
656
+ . then ( done ) ;
657
+ } ) ;
658
+
659
+ it ( '@gl should be able to restyle *below*' , function ( done ) {
660
+ function getLayerIds ( ) {
661
+ var subplot = gd . _fullLayout . mapbox . _subplot ;
662
+ var layers = subplot . map . getStyle ( ) . layers ;
663
+ var layerIds = layers . map ( function ( l ) { return l . id ; } ) ;
664
+ return layerIds ;
665
+ }
666
+
667
+ Plotly . plot ( gd , [ {
668
+ type : 'choroplethmapbox' ,
669
+ locations : [ 'AL' ] ,
670
+ z : [ 10 ] ,
671
+ geojson : geojson ,
672
+ uid : 'a'
673
+ } ] )
674
+ . then ( function ( ) {
675
+ expect ( getLayerIds ( ) ) . withContext ( 'default *below*' ) . toEqual ( [
676
+ 'background' , 'landuse_overlay_national_park' , 'landuse_park' ,
677
+ 'waterway' , 'water' ,
678
+ 'a-layer-fill' , 'a-layer-line' ,
679
+ 'building' , 'tunnel_minor' , 'tunnel_major' , 'road_minor' , 'road_major' ,
680
+ 'bridge_minor case' , 'bridge_major case' , 'bridge_minor' , 'bridge_major' ,
681
+ 'admin_country' , 'poi_label' , 'road_major_label' ,
682
+ 'place_label_other' , 'place_label_city' , 'country_label'
683
+ ] ) ;
684
+ } )
685
+ . then ( function ( ) { return Plotly . restyle ( gd , 'below' , '' ) ; } )
686
+ . then ( function ( ) {
687
+ expect ( getLayerIds ( ) ) . withContext ( 'default *below*' ) . toEqual ( [
688
+ 'background' , 'landuse_overlay_national_park' , 'landuse_park' ,
689
+ 'waterway' , 'water' ,
690
+ 'building' , 'tunnel_minor' , 'tunnel_major' , 'road_minor' , 'road_major' ,
691
+ 'bridge_minor case' , 'bridge_major case' , 'bridge_minor' , 'bridge_major' ,
692
+ 'admin_country' , 'poi_label' , 'road_major_label' ,
693
+ 'place_label_other' , 'place_label_city' , 'country_label' ,
694
+ 'a-layer-fill' , 'a-layer-line'
695
+ ] ) ;
696
+ } )
697
+ . then ( function ( ) { return Plotly . restyle ( gd , 'below' , 'place_label_other' ) ; } )
698
+ . then ( function ( ) {
699
+ expect ( getLayerIds ( ) ) . withContext ( 'default *below*' ) . toEqual ( [
700
+ 'background' , 'landuse_overlay_national_park' , 'landuse_park' ,
701
+ 'waterway' , 'water' ,
702
+ 'building' , 'tunnel_minor' , 'tunnel_major' , 'road_minor' , 'road_major' ,
703
+ 'bridge_minor case' , 'bridge_major case' , 'bridge_minor' , 'bridge_major' ,
704
+ 'admin_country' , 'poi_label' , 'road_major_label' ,
705
+ 'a-layer-fill' , 'a-layer-line' ,
706
+ 'place_label_other' , 'place_label_city' , 'country_label' ,
707
+ ] ) ;
708
+ } )
709
+ . catch ( failTest )
710
+ . then ( done ) ;
711
+ } , 5 * jasmine . DEFAULT_TIMEOUT_INTERVAL ) ;
712
+ } ) ;
0 commit comments