@@ -650,9 +650,9 @@ describe('legend interaction', function() {
650
650
done ( ) ;
651
651
} ) ;
652
652
} ) ;
653
- afterAll ( function ( ) {
654
- destroyGraphDiv ( ) ;
655
- } ) ;
653
+
654
+ afterAll ( destroyGraphDiv ) ;
655
+
656
656
describe ( 'single click' , function ( ) {
657
657
it ( 'should hide slice' , function ( done ) {
658
658
legendItem . dispatchEvent ( new MouseEvent ( 'mousedown' ) ) ;
@@ -663,9 +663,11 @@ describe('legend interaction', function() {
663
663
done ( ) ;
664
664
} , DBLCLICKDELAY + 20 ) ;
665
665
} ) ;
666
+
666
667
it ( 'should fade legend item' , function ( ) {
667
668
expect ( + legendItem . parentNode . style . opacity ) . toBeLessThan ( 1 ) ;
668
669
} ) ;
670
+
669
671
it ( 'should unhide slice' , function ( done ) {
670
672
legendItem . dispatchEvent ( new MouseEvent ( 'mousedown' ) ) ;
671
673
legendItem . dispatchEvent ( new MouseEvent ( 'mouseup' ) ) ;
@@ -674,6 +676,7 @@ describe('legend interaction', function() {
674
676
done ( ) ;
675
677
} , DBLCLICKDELAY + 20 ) ;
676
678
} ) ;
679
+
677
680
it ( 'should unfade legend item' , function ( ) {
678
681
expect ( + legendItem . parentNode . style . opacity ) . toBe ( 1 ) ;
679
682
} ) ;
@@ -691,6 +694,7 @@ describe('legend interaction', function() {
691
694
done ( ) ;
692
695
} , 20 ) ;
693
696
} ) ;
697
+
694
698
it ( 'should fade other legend items' , function ( ) {
695
699
var legendItemi ;
696
700
for ( var i = 0 ; i < legendItems . length ; i ++ ) {
@@ -702,6 +706,7 @@ describe('legend interaction', function() {
702
706
}
703
707
}
704
708
} ) ;
709
+
705
710
it ( 'should unhide all slices' , function ( done ) {
706
711
legendItem . dispatchEvent ( new MouseEvent ( 'mousedown' ) ) ;
707
712
legendItem . dispatchEvent ( new MouseEvent ( 'mouseup' ) ) ;
@@ -712,6 +717,7 @@ describe('legend interaction', function() {
712
717
done ( ) ;
713
718
} , 20 ) ;
714
719
} ) ;
720
+
715
721
it ( 'should unfade legend items' , function ( ) {
716
722
var legendItemi ;
717
723
for ( var i = 0 ; i < legendItems . length ; i ++ ) {
@@ -721,6 +727,7 @@ describe('legend interaction', function() {
721
727
} ) ;
722
728
} ) ;
723
729
} ) ;
730
+
724
731
describe ( 'non-pie chart' , function ( ) {
725
732
var mockCopy , gd , legendItems , legendItem ;
726
733
var testEntry = 2 ;
@@ -736,9 +743,8 @@ describe('legend interaction', function() {
736
743
done ( ) ;
737
744
} ) ;
738
745
} ) ;
739
- afterAll ( function ( ) {
740
- destroyGraphDiv ( ) ;
741
- } ) ;
746
+
747
+ afterAll ( destroyGraphDiv ) ;
742
748
743
749
describe ( 'single click' , function ( ) {
744
750
it ( 'should hide series' , function ( done ) {
@@ -749,9 +755,11 @@ describe('legend interaction', function() {
749
755
done ( ) ;
750
756
} , DBLCLICKDELAY + 20 ) ;
751
757
} ) ;
758
+
752
759
it ( 'should fade legend item' , function ( ) {
753
760
expect ( + legendItem . parentNode . style . opacity ) . toBeLessThan ( 1 ) ;
754
761
} ) ;
762
+
755
763
it ( 'should unhide series' , function ( done ) {
756
764
legendItem . dispatchEvent ( new MouseEvent ( 'mousedown' ) ) ;
757
765
legendItem . dispatchEvent ( new MouseEvent ( 'mouseup' ) ) ;
@@ -760,10 +768,12 @@ describe('legend interaction', function() {
760
768
done ( ) ;
761
769
} , DBLCLICKDELAY + 20 ) ;
762
770
} ) ;
771
+
763
772
it ( 'should unfade legend item' , function ( ) {
764
773
expect ( + legendItem . parentNode . style . opacity ) . toBe ( 1 ) ;
765
774
} ) ;
766
775
} ) ;
776
+
767
777
describe ( 'double click' , function ( ) {
768
778
it ( 'should hide series' , function ( done ) {
769
779
legendItem . dispatchEvent ( new MouseEvent ( 'mousedown' ) ) ;
@@ -781,6 +791,7 @@ describe('legend interaction', function() {
781
791
done ( ) ;
782
792
} , 20 ) ;
783
793
} ) ;
794
+
784
795
it ( 'should fade legend item' , function ( ) {
785
796
var legendItemi ;
786
797
for ( var i = 0 ; i < legendItems . length ; i ++ ) {
@@ -792,6 +803,7 @@ describe('legend interaction', function() {
792
803
}
793
804
}
794
805
} ) ;
806
+
795
807
it ( 'should unhide series' , function ( done ) {
796
808
legendItem . dispatchEvent ( new MouseEvent ( 'mousedown' ) ) ;
797
809
legendItem . dispatchEvent ( new MouseEvent ( 'mouseup' ) ) ;
@@ -804,6 +816,7 @@ describe('legend interaction', function() {
804
816
done ( ) ;
805
817
} , 20 ) ;
806
818
} ) ;
819
+
807
820
it ( 'should unfade legend items' , function ( ) {
808
821
var legendItemi ;
809
822
for ( var i = 0 ; i < legendItems . length ; i ++ ) {
@@ -813,4 +826,60 @@ describe('legend interaction', function() {
813
826
} ) ;
814
827
} ) ;
815
828
} ) ;
829
+
830
+ describe ( 'carpet plots' , function ( ) {
831
+ afterAll ( destroyGraphDiv ) ;
832
+
833
+ function _click ( index ) {
834
+ var item = d3 . selectAll ( 'rect.legendtoggle' ) [ 0 ] [ index || 0 ] ;
835
+ return new Promise ( function ( resolve ) {
836
+ item . dispatchEvent ( new MouseEvent ( 'mousedown' ) ) ;
837
+ item . dispatchEvent ( new MouseEvent ( 'mouseup' ) ) ;
838
+ setTimeout ( resolve , DBLCLICKDELAY + 20 ) ;
839
+ } ) ;
840
+ }
841
+
842
+ function _dblclick ( index ) {
843
+ var item = d3 . selectAll ( 'rect.legendtoggle' ) [ 0 ] [ index || 0 ] ;
844
+ return new Promise ( function ( resolve ) {
845
+ item . dispatchEvent ( new MouseEvent ( 'mousedown' ) ) ;
846
+ item . dispatchEvent ( new MouseEvent ( 'mouseup' ) ) ;
847
+ item . dispatchEvent ( new MouseEvent ( 'mousedown' ) ) ;
848
+ item . dispatchEvent ( new MouseEvent ( 'mouseup' ) ) ;
849
+ setTimeout ( resolve , 20 ) ;
850
+ } ) ;
851
+ }
852
+
853
+ function assertVisible ( gd , expectation ) {
854
+ var actual = gd . _fullData . map ( function ( trace ) { return trace . visible ; } ) ;
855
+ expect ( actual ) . toEqual ( expectation ) ;
856
+ }
857
+
858
+ it ( 'should ignore carpet traces when toggling' , function ( done ) {
859
+ var _mock = Lib . extendDeep ( { } , require ( '@mocks/cheater.json' ) ) ;
860
+ var gd = createGraphDiv ( ) ;
861
+
862
+ Plotly . plot ( gd , _mock ) . then ( function ( ) {
863
+ assertVisible ( gd , [ true , true , true , true ] ) ;
864
+ } )
865
+ . then ( _click )
866
+ . then ( function ( ) {
867
+ assertVisible ( gd , [ true , 'legendonly' , true , true ] ) ;
868
+ } )
869
+ . then ( _click )
870
+ . then ( function ( ) {
871
+ assertVisible ( gd , [ true , true , true , true ] ) ;
872
+ } )
873
+ . then ( _dblclick )
874
+ . then ( function ( ) {
875
+ assertVisible ( gd , [ true , true , 'legendonly' , 'legendonly' ] ) ;
876
+ } )
877
+ . then ( _dblclick )
878
+ . then ( function ( ) {
879
+ assertVisible ( gd , [ true , true , true , true ] ) ;
880
+ } )
881
+ . catch ( fail )
882
+ . then ( done ) ;
883
+ } ) ;
884
+ } ) ;
816
885
} ) ;
0 commit comments