@@ -582,4 +582,114 @@ describe('Test Plots', function() {
582
582
} ) ;
583
583
} ) ;
584
584
585
+ describe ( 'Plots.generalUpdatePerTraceModule' , function ( ) {
586
+
587
+ function _update ( subplotCalcData , traceHashOld ) {
588
+ var subplot = { traceHash : traceHashOld || { } } ;
589
+ var calcDataPerModule = [ ] ;
590
+
591
+ var plot = function ( _ , moduleCalcData ) {
592
+ calcDataPerModule . push ( moduleCalcData ) ;
593
+ } ;
594
+
595
+ subplotCalcData . forEach ( function ( calcTrace ) {
596
+ calcTrace [ 0 ] . trace . _module = { plot : plot } ;
597
+ } ) ;
598
+
599
+ Plots . generalUpdatePerTraceModule ( subplot , subplotCalcData , { } ) ;
600
+
601
+ return {
602
+ traceHash : subplot . traceHash ,
603
+ calcDataPerModule : calcDataPerModule
604
+ } ;
605
+ }
606
+
607
+ it ( 'should update subplot trace hash and call module plot method with correct calcdata traces' , function ( ) {
608
+ var out = _update ( [
609
+ [ { trace : { type : 'A' , visible : false } } ] ,
610
+ [ { trace : { type : 'A' , visible : true } } ] ,
611
+ [ { trace : { type : 'B' , visible : false } } ] ,
612
+ [ { trace : { type : 'C' , visible : true } } ]
613
+ ] ) ;
614
+
615
+ expect ( Object . keys ( out . traceHash ) ) . toEqual ( [ 'A' , 'C' ] ) ;
616
+ expect ( out . traceHash . A . length ) . toEqual ( 1 ) ;
617
+ expect ( out . traceHash . C . length ) . toEqual ( 1 ) ;
618
+
619
+ expect ( out . calcDataPerModule . length ) . toEqual ( 2 ) ;
620
+ expect ( out . calcDataPerModule [ 0 ] . length ) . toEqual ( 1 ) ;
621
+ expect ( out . calcDataPerModule [ 1 ] . length ) . toEqual ( 1 ) ;
622
+
623
+ var out2 = _update ( [
624
+ [ { trace : { type : 'A' , visible : false } } ] ,
625
+ [ { trace : { type : 'A' , visible : false } } ] ,
626
+ [ { trace : { type : 'B' , visible : true } } ] ,
627
+ [ { trace : { type : 'C' , visible : false } } ]
628
+ ] , out . traceHash ) ;
629
+
630
+ expect ( Object . keys ( out2 . traceHash ) ) . toEqual ( [ 'B' , 'A' , 'C' ] ) ;
631
+ expect ( out2 . traceHash . B . length ) . toEqual ( 1 ) ;
632
+ expect ( out2 . traceHash . A . length ) . toEqual ( 1 ) ;
633
+ expect ( out2 . traceHash . A [ 0 ] [ 0 ] . trace . visible ) . toBe ( false ) ;
634
+ expect ( out2 . traceHash . C . length ) . toEqual ( 1 ) ;
635
+ expect ( out2 . traceHash . C [ 0 ] [ 0 ] . trace . visible ) . toBe ( false ) ;
636
+
637
+ expect ( out2 . calcDataPerModule . length ) . toEqual ( 1 ) ;
638
+ expect ( out2 . calcDataPerModule [ 0 ] . length ) . toEqual ( 1 ) ;
639
+
640
+ var out3 = _update ( [
641
+ [ { trace : { type : 'A' , visible : false } } ] ,
642
+ [ { trace : { type : 'A' , visible : false } } ] ,
643
+ [ { trace : { type : 'B' , visible : false } } ] ,
644
+ [ { trace : { type : 'C' , visible : false } } ]
645
+ ] , out2 . traceHash ) ;
646
+
647
+ expect ( Object . keys ( out3 . traceHash ) ) . toEqual ( [ 'B' , 'A' , 'C' ] ) ;
648
+ expect ( out3 . traceHash . B . length ) . toEqual ( 1 ) ;
649
+ expect ( out3 . traceHash . B [ 0 ] [ 0 ] . trace . visible ) . toBe ( false ) ;
650
+ expect ( out3 . traceHash . A . length ) . toEqual ( 1 ) ;
651
+ expect ( out3 . traceHash . A [ 0 ] [ 0 ] . trace . visible ) . toBe ( false ) ;
652
+ expect ( out3 . traceHash . C . length ) . toEqual ( 1 ) ;
653
+ expect ( out3 . traceHash . C [ 0 ] [ 0 ] . trace . visible ) . toBe ( false ) ;
654
+
655
+ expect ( out3 . calcDataPerModule . length ) . toEqual ( 0 ) ;
656
+
657
+ var out4 = _update ( [
658
+ [ { trace : { type : 'A' , visible : true } } ] ,
659
+ [ { trace : { type : 'A' , visible : true } } ] ,
660
+ [ { trace : { type : 'B' , visible : true } } ] ,
661
+ [ { trace : { type : 'C' , visible : true } } ]
662
+ ] , out3 . traceHash ) ;
663
+
664
+ expect ( Object . keys ( out4 . traceHash ) ) . toEqual ( [ 'A' , 'B' , 'C' ] ) ;
665
+ expect ( out4 . traceHash . A . length ) . toEqual ( 2 ) ;
666
+ expect ( out4 . traceHash . B . length ) . toEqual ( 1 ) ;
667
+ expect ( out4 . traceHash . C . length ) . toEqual ( 1 ) ;
668
+
669
+ expect ( out4 . calcDataPerModule . length ) . toEqual ( 3 ) ;
670
+ expect ( out4 . calcDataPerModule [ 0 ] . length ) . toEqual ( 2 ) ;
671
+ expect ( out4 . calcDataPerModule [ 1 ] . length ) . toEqual ( 1 ) ;
672
+ expect ( out4 . calcDataPerModule [ 2 ] . length ) . toEqual ( 1 ) ;
673
+ } ) ;
674
+
675
+ it ( 'should handle cases when module plot is not set (geo case)' , function ( done ) {
676
+ Plotly . plot ( createGraphDiv ( ) , [ {
677
+ type : 'scattergeo' ,
678
+ visible : false ,
679
+ lon : [ 10 , 20 ] ,
680
+ lat : [ 20 , 10 ]
681
+ } , {
682
+ type : 'scattergeo' ,
683
+ lon : [ 10 , 20 ] ,
684
+ lat : [ 20 , 10 ]
685
+ } ] )
686
+ . then ( function ( ) {
687
+ expect ( d3 . selectAll ( 'g.trace.scattergeo' ) . size ( ) ) . toEqual ( 1 ) ;
688
+
689
+ destroyGraphDiv ( ) ;
690
+ done ( ) ;
691
+ } ) ;
692
+ } ) ;
693
+
694
+ } ) ;
585
695
} ) ;
0 commit comments