@@ -727,3 +727,166 @@ describe('restyle applied on transforms:', function() {
727727 } ) ;
728728
729729} ) ;
730+
731+ describe ( 'supplyDefaults with groupby + filter' , function ( ) {
732+ function calcDatatoTrace ( calcTrace ) {
733+ return calcTrace [ 0 ] . trace ;
734+ }
735+
736+ function _transform ( data , layout ) {
737+ var gd = {
738+ data : data ,
739+ layout : layout || { }
740+ } ;
741+
742+ Plots . supplyDefaults ( gd ) ;
743+ Plots . doCalcdata ( gd ) ;
744+
745+ return gd . calcdata . map ( calcDatatoTrace ) ;
746+ }
747+
748+ it ( 'filter + groupby with blank target' , function ( ) {
749+ var out = _transform ( [ {
750+ x : [ 1 , 2 , 3 , 4 , 5 , 6 , 7 ] ,
751+ y : [ 4 , 6 , 5 , 7 , 6 , 8 , 9 ] ,
752+ transforms : [ {
753+ type : 'filter' ,
754+ operation : '<' ,
755+ value : 6.5
756+ } , {
757+ type : 'groupby' ,
758+ groups : [ 1 , 1 , 1 , 2 , 2 , 2 , 2 ]
759+ } ]
760+ } ] ) ;
761+
762+ expect ( out [ 0 ] . x ) . toEqual ( [ 1 , 2 , 3 ] ) ;
763+ expect ( out [ 0 ] . y ) . toEqual ( [ 4 , 6 , 5 ] ) ;
764+
765+ expect ( out [ 1 ] . x ) . toEqual ( [ 4 , 5 , 6 ] ) ;
766+ expect ( out [ 1 ] . y ) . toEqual ( [ 7 , 6 , 8 ] ) ;
767+ } ) ;
768+
769+ it ( 'fiter + groupby' , function ( ) {
770+ var out = _transform ( [ {
771+ x : [ 5 , 4 , 3 ] ,
772+ y : [ 6 , 5 , 4 ] ,
773+ } , {
774+ x : [ 1 , 2 , 3 , 4 , 5 , 6 , 7 ] ,
775+ y : [ 4 , 6 , 5 , 7 , 8 , 9 , 10 ] ,
776+ transforms : [ {
777+ type : 'filter' ,
778+ target : [ 1 , 2 , 3 , 4 , 5 , 6 , 7 ] ,
779+ operation : '<' ,
780+ value : 6.5
781+ } , {
782+ type : 'groupby' ,
783+ groups : [ 1 , 1 , 1 , 2 , 2 , 2 , 2 ]
784+ } ]
785+ } ] ) ;
786+
787+ expect ( out [ 0 ] . x ) . toEqual ( [ 5 , 4 , 3 ] ) ;
788+ expect ( out [ 0 ] . y ) . toEqual ( [ 6 , 5 , 4 ] ) ;
789+
790+ expect ( out [ 1 ] . x ) . toEqual ( [ 1 , 2 , 3 ] ) ;
791+ expect ( out [ 1 ] . y ) . toEqual ( [ 4 , 6 , 5 ] ) ;
792+
793+ expect ( out [ 2 ] . x ) . toEqual ( [ 4 , 5 , 6 ] ) ;
794+ expect ( out [ 2 ] . y ) . toEqual ( [ 7 , 8 , 9 ] ) ;
795+ } ) ;
796+
797+ it ( 'groupby + filter' , function ( ) {
798+ var out = _transform ( [ {
799+ x : [ 1 , 2 , 3 , 4 , 5 , 6 , 7 ] ,
800+ y : [ 4 , 6 , 5 , 7 , 6 , 8 , 9 ] ,
801+ transforms : [ {
802+ type : 'groupby' ,
803+ groups : [ 1 , 1 , 1 , 2 , 2 , 2 , 2 ]
804+ } , {
805+ type : 'filter' ,
806+ target : [ 1 , 2 , 3 , 4 , 5 , 6 , 7 ] ,
807+ operation : '<' ,
808+ value : 6.5
809+ } ]
810+ } ] ) ;
811+
812+ expect ( out [ 0 ] . x ) . toEqual ( [ 1 , 2 , 3 ] ) ;
813+ expect ( out [ 0 ] . y ) . toEqual ( [ 4 , 6 , 5 ] ) ;
814+
815+ expect ( out [ 1 ] . x ) . toEqual ( [ 4 , 5 , 6 ] ) ;
816+ expect ( out [ 1 ] . y ) . toEqual ( [ 7 , 6 , 8 ] ) ;
817+ } ) ;
818+
819+ it ( 'groupby + groupby' , function ( ) {
820+ var out = _transform ( [ {
821+ x : [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ] ,
822+ y : [ 4 , 6 , 5 , 7 , 6 , 8 , 9 , 10 ] ,
823+ transforms : [ {
824+ type : 'groupby' ,
825+ groups : [ 1 , 1 , 1 , 1 , 2 , 2 , 2 , 2 ]
826+ } , {
827+ type : 'groupby' ,
828+ groups : [ 3 , 4 , 3 , 4 , 3 , 4 , 3 , 5 ] ,
829+ } ]
830+ } ] ) ;
831+ // | | | | | | | |
832+ // v v v v v v v v
833+ // Trace number: 0 1 0 1 2 3 2 4
834+
835+ expect ( out . length ) . toEqual ( 5 ) ;
836+ expect ( out [ 0 ] . x ) . toEqual ( [ 1 , 3 ] ) ;
837+ expect ( out [ 1 ] . x ) . toEqual ( [ 2 , 4 ] ) ;
838+ expect ( out [ 2 ] . x ) . toEqual ( [ 5 , 7 ] ) ;
839+ expect ( out [ 3 ] . x ) . toEqual ( [ 6 ] ) ;
840+ expect ( out [ 4 ] . x ) . toEqual ( [ 8 ] ) ;
841+ } ) ;
842+
843+ it ( 'groupby + groupby + filter' , function ( ) {
844+ var out = _transform ( [ {
845+ x : [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ] ,
846+ y : [ 4 , 6 , 5 , 7 , 6 , 8 , 9 , 10 ] ,
847+ transforms : [ {
848+ type : 'groupby' ,
849+ groups : [ 1 , 1 , 1 , 1 , 2 , 2 , 2 , 2 ]
850+ } , {
851+ type : 'groupby' ,
852+ groups : [ 3 , 4 , 3 , 4 , 3 , 4 , 3 , 5 ] ,
853+ } , {
854+ type : 'filter' ,
855+ target : [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ] ,
856+ operation : '<' ,
857+ value : 4.5
858+ } ]
859+ } ] ) ;
860+ // | | | | | | | |
861+ // v v v v v v v v
862+ // Trace number: 0 1 0 1 2 3 2 4
863+
864+ expect ( out . length ) . toEqual ( 5 ) ;
865+ expect ( out [ 0 ] . x ) . toEqual ( [ 1 , 3 ] ) ;
866+ expect ( out [ 1 ] . x ) . toEqual ( [ 2 , 4 ] ) ;
867+ expect ( out [ 2 ] . x ) . toEqual ( [ ] ) ;
868+ expect ( out [ 3 ] . x ) . toEqual ( [ ] ) ;
869+ expect ( out [ 4 ] . x ) . toEqual ( [ ] ) ;
870+ } ) ;
871+
872+ it ( 'fiter + filter' , function ( ) {
873+ var out = _transform ( [ {
874+ x : [ 1 , 2 , 3 , 4 , 5 , 6 , 7 ] ,
875+ y : [ 4 , 6 , 5 , 7 , 8 , 9 , 10 ] ,
876+ transforms : [ {
877+ type : 'filter' ,
878+ target : [ 1 , 2 , 3 , 4 , 5 , 6 , 7 ] ,
879+ operation : '<' ,
880+ value : 6.5
881+ } , {
882+ type : 'filter' ,
883+ target : [ 1 , 2 , 3 , 4 , 5 , 6 , 7 ] ,
884+ operation : '>' ,
885+ value : 1.5
886+ } ]
887+ } ] ) ;
888+
889+ expect ( out [ 0 ] . x ) . toEqual ( [ 2 , 3 , 4 , 5 , 6 ] ) ;
890+ expect ( out [ 0 ] . y ) . toEqual ( [ 6 , 5 , 7 , 8 , 9 ] ) ;
891+ } ) ;
892+ } ) ;
0 commit comments