@@ -580,3 +580,70 @@ describe('multiple traces with transforms:', function() {
580
580
} ) ;
581
581
} ) ;
582
582
} ) ;
583
+
584
+ describe ( 'restyle applied on transforms:' , function ( ) {
585
+ 'use strict' ;
586
+
587
+ afterEach ( destroyGraphDiv ) ;
588
+
589
+ it ( 'should be able' , function ( done ) {
590
+ var gd = createGraphDiv ( ) ;
591
+
592
+ var data = [ { y : [ 2 , 1 , 2 ] } ] ;
593
+
594
+ var transform0 = {
595
+ type : 'filter' ,
596
+ target : 'y' ,
597
+ operation : '>' ,
598
+ value : 1
599
+ } ;
600
+
601
+ var transform1 = {
602
+ type : 'groupby' ,
603
+ groups : [ 'a' , 'b' , 'b' ]
604
+ } ;
605
+
606
+ Plotly . plot ( gd , data ) . then ( function ( ) {
607
+ expect ( gd . data . transforms ) . toBeUndefined ( ) ;
608
+
609
+ return Plotly . restyle ( gd , 'transforms[0]' , transform0 ) ;
610
+ } )
611
+ . then ( function ( ) {
612
+ var msg = 'to generate blank transform objects' ;
613
+
614
+ expect ( gd . data [ 0 ] . transforms [ 0 ] ) . toBe ( transform0 , msg ) ;
615
+
616
+ // make sure transform actually works
617
+ expect ( gd . _fullData [ 0 ] . y ) . toEqual ( [ 2 , 2 ] , msg ) ;
618
+
619
+ return Plotly . restyle ( gd , 'transforms[1]' , transform1 ) ;
620
+ } )
621
+ . then ( function ( ) {
622
+ var msg = 'to generate blank transform objects (2)' ;
623
+
624
+ expect ( gd . data [ 0 ] . transforms [ 0 ] ) . toBe ( transform0 , msg ) ;
625
+ expect ( gd . data [ 0 ] . transforms [ 1 ] ) . toBe ( transform1 , msg ) ;
626
+ expect ( gd . _fullData [ 0 ] . y ) . toEqual ( [ 2 ] , msg ) ;
627
+
628
+ return Plotly . restyle ( gd , 'transforms[0]' , null ) ;
629
+ } )
630
+ . then ( function ( ) {
631
+ var msg = 'to remove transform objects' ;
632
+
633
+ expect ( gd . data [ 0 ] . transforms [ 0 ] ) . toBe ( transform1 , msg ) ;
634
+ expect ( gd . data [ 0 ] . transforms [ 1 ] ) . toBeUndefined ( msg ) ;
635
+ expect ( gd . _fullData [ 0 ] . y ) . toEqual ( [ 2 ] , msg ) ;
636
+ expect ( gd . _fullData [ 1 ] . y ) . toEqual ( [ 1 , 2 ] , msg ) ;
637
+
638
+ return Plotly . restyle ( gd , 'transforms' , null ) ;
639
+ } )
640
+ . then ( function ( ) {
641
+ var msg = 'to remove all transform objects' ;
642
+
643
+ expect ( gd . data [ 0 ] . transforms ) . toBeUndefined ( msg ) ;
644
+ expect ( gd . _fullData [ 0 ] . y ) . toEqual ( [ 2 , 1 , 2 ] , msg ) ;
645
+ } )
646
+ . then ( done ) ;
647
+ } ) ;
648
+
649
+ } ) ;
0 commit comments