@@ -139,12 +139,16 @@ define([
139139} = state ;
140140
141141$ ( this . _wrapSelector ( '#vp_gbVariable' ) ) . val ( variable ) ;
142- $ ( this . _wrapSelector ( '#vp_gbBy' ) ) . val ( groupby . join ( ',' ) ) ;
142+ $ ( this . _wrapSelector ( '#vp_gbBy' ) ) . val ( groupby . map ( col => col . code ) . join ( ',' ) ) ;
143143$ ( this . _wrapSelector ( '#vp_gbBy' ) ) . data ( 'list' , groupby ) ;
144- $ ( this . _wrapSelector ( '#vp_gbByGrouper' ) ) . prop ( 'checked' , useGrouper ) ;
145- $ ( this . _wrapSelector ( '#vp_gbByGrouperNumber' ) ) . val ( grouperNumber ) ;
146- $ ( this . _wrapSelector ( '#vp_gbByGrouperPeriod' ) ) . val ( grouperPeriod ) ;
147- $ ( this . _wrapSelector ( '#vp_gbDisplay' ) ) . val ( display . join ( ',' ) ) ;
144+ if ( useGrouper ) {
145+ $ ( this . _wrapSelector ( '#vp_gbByGrouper' ) ) . removeAttr ( 'disabled' ) ;
146+ $ ( this . _wrapSelector ( '#vp_gbByGrouper' ) ) . prop ( 'checked' , useGrouper ) ;
147+ $ ( this . _wrapSelector ( '#vp_gbByGrouperNumber' ) ) . val ( grouperNumber ) ;
148+ $ ( this . _wrapSelector ( '#vp_gbByGrouperPeriod' ) ) . val ( grouperPeriod ) ;
149+ $ ( this . _wrapSelector ( '.vp-gb-by-grouper-box' ) ) . show ( ) ;
150+ }
151+ $ ( this . _wrapSelector ( '#vp_gbDisplay' ) ) . val ( display . map ( col => col . code ) . join ( ',' ) ) ;
148152$ ( this . _wrapSelector ( '#vp_gbDisplay' ) ) . data ( 'list' , display ) ;
149153$ ( this . _wrapSelector ( '#vp_gbMethod' ) ) . val ( method ) ;
150154$ ( this . _wrapSelector ( '#vp_gbMethodSelector' ) ) . val ( method ) ;
@@ -303,7 +307,7 @@ define([
303307page . appendFormatLine ( '<label for="{0}" class="{1}">{2}</label>' , 'vp_gbBy' , 'vp-orange-text wp80' , 'Groupby' ) ;
304308page . appendFormatLine ( '<input type="text" id="{0}" placeholder="{1}" disabled/>' , 'vp_gbBy' , 'Groupby coluns' ) ;
305309page . appendFormatLine ( '<button id="{0}" class="{1}">{2}</button>' , 'vp_gbBySelect' , 'vp-button wp50' , 'Edit' ) ;
306- page . appendFormatLine ( '<label ><input type="checkbox"/><span>{1}</span></label>' , 'vp_gbByGrouper' , 'Grouper' ) ;
310+ page . appendFormatLine ( '<label><input type="checkbox" disabled /><span>{1}</span></label>' , 'vp_gbByGrouper' , 'Grouper' ) ;
307311page . appendFormatLine ( '<div class="{0}" style="display:none;">' , 'vp-gb-by-grouper-box' ) ;
308312page . appendFormatLine ( '<input type="number" id="{0}" class="{1}"/>' , 'vp_gbByGrouperNumber' , 'vp-gb-by-number' ) ;
309313page . appendFormatLine ( '<select id="{0}">' , 'vp_gbByGrouperPeriod' ) ;
@@ -531,7 +535,11 @@ define([
531535openInnerPopup ( targetSelector , title = 'Select columns' , includeList = [ ] ) {
532536this . popup . type = 'column' ;
533537this . popup . targetSelector = targetSelector ;
534- this . renderColumnSelector ( this . popup . targetSelector . data ( 'list' ) , includeList ) ;
538+ var previousList = this . popup . targetSelector . data ( 'list' ) ;
539+ if ( previousList ) {
540+ previousList = previousList . map ( col => col . code )
541+ }
542+ this . renderColumnSelector ( previousList , includeList ) ;
535543
536544// set title
537545$ ( this . _wrapSelector ( '.' + APP_POPUP_BOX + ' .' + APP_TITLE ) ) . text ( title ) ;
@@ -664,11 +672,12 @@ define([
664672$ ( document ) . on ( 'change' , this . _wrapSelector ( '#vp_gbBy' ) , function ( event ) {
665673var colList = event . colList ;
666674that . state . groupby = colList ;
667-
668- if ( colList && colList . length == 1 ) {
669- $ ( that . _wrapSelector ( '#vp_gbByGrouper' ) ) . parent ( ) . show ( ) ;
675+
676+ if ( colList && colList . length == 1
677+ && colList [ 0 ] . dtype . includes ( 'datetime' ) ) {
678+ $ ( that . _wrapSelector ( '#vp_gbByGrouper' ) ) . removeAttr ( 'disabled' ) ;
670679} else {
671- $ ( that . _wrapSelector ( '#vp_gbByGrouper' ) ) . parent ( ) . hide ( ) ;
680+ $ ( that . _wrapSelector ( '#vp_gbByGrouper' ) ) . attr ( 'disabled' , true ) ;
672681}
673682} ) ;
674683
@@ -763,20 +772,38 @@ define([
763772var idx = $ ( that . _wrapSelector ( '.vp-gb-adv-col' ) ) . index ( this ) ;
764773
765774// if there's change, reset display namings
766- var previousList = that . state . advColList [ idx ] ;
767- if ( ! previousList || colList . length !== previousList . length
768- || ! colList . slice ( ) . sort ( ) . every ( ( val , idx ) => { return val === previousList . slice ( ) . sort ( ) [ idx ] } ) ) {
769- that . state . advNamingList = [ ]
770- $ ( that . _wrapSelector ( '.vp-gb-adv-naming' ) ) . val ( '' ) ;
771- $ ( that . _wrapSelector ( '.vp-gb-adv-naming' ) ) . data ( 'dict' , { } ) ;
775+ // var previousList = that.state.advColList[idx];
776+ // if (!previousList || colList.length !== previousList.length
777+ // || !colList.map(col=>col.code).slice().sort().every((val, idx) => {
778+ // return val === previousList.map(col=>col.code).slice().sort()[idx]
779+ // })) {
780+ // that.state.advNamingList = []
781+ // $(this).parent().find('.vp-gb-adv-naming').val('');
782+ // $(this).parent().find('.vp-gb-adv-naming').data('dict', {});
783+ // }
784+ var namingDict = that . state . advNamingList [ idx ] ;
785+ if ( namingDict ) {
786+ // namingDict = namingDict.filter(key => colList.map(col=>col.code).includes(key));
787+ Object . keys ( namingDict ) . forEach ( key => {
788+ if ( ! colList . map ( col => col . code ) . includes ( key ) ) {
789+ delete namingDict [ key ] ;
790+ }
791+ } ) ;
792+ that . state . advNamingList [ idx ] = namingDict ;
793+ $ ( this ) . parent ( ) . find ( '.vp-gb-adv-naming' ) . val ( Object . values ( namingDict ) . map ( val => "'" + val + "'" ) . join ( ',' ) ) ;
794+ $ ( this ) . parent ( ) . find ( '.vp-gb-adv-naming' ) . data ( 'dict' , namingDict ) ;
772795}
773796
774797that . state . advColList [ idx ] = colList ;
775798} ) ;
776799
777800// edit target columns
778801$ ( document ) . on ( 'click' , this . _wrapSelector ( '.vp-gb-adv-col-selector' ) , function ( ) {
779- that . openInnerPopup ( $ ( this ) . parent ( ) . find ( '.vp-gb-adv-col' ) , 'Select columns' , that . state . display ) ;
802+ var includeList = that . state . display ;
803+ if ( includeList && includeList . length > 0 ) {
804+ includeList = includeList . map ( col => col . code ) ;
805+ }
806+ that . openInnerPopup ( $ ( this ) . parent ( ) . find ( '.vp-gb-adv-col' ) , 'Select columns' , includeList ) ;
780807} ) ;
781808
782809// select method
@@ -815,6 +842,9 @@ define([
815842$ ( document ) . on ( 'click' , this . _wrapSelector ( '.vp-gb-adv-naming-selector' ) , function ( ) {
816843var parentDiv = $ ( this ) . parent ( ) ;
817844var columns = $ ( parentDiv ) . find ( '.vp-gb-adv-col' ) . data ( 'list' ) ;
845+ if ( columns && columns . length > 0 ) {
846+ columns = columns . map ( col => col . code ) ;
847+ }
818848var method = $ ( parentDiv ) . find ( '.vp-gb-adv-method' ) . val ( ) ;
819849if ( ! method || method == '' || method == "''" ) {
820850// set focus on selecting method tag
@@ -899,7 +929,7 @@ define([
899929if ( that . popup . type == 'column' ) {
900930var colList = that . popup . ColSelector . getColumnList ( ) ;
901931
902- $ ( that . popup . targetSelector ) . val ( colList . join ( ',' ) ) ;
932+ $ ( that . popup . targetSelector ) . val ( colList . map ( col => { return col . code } ) . join ( ',' ) ) ;
903933$ ( that . popup . targetSelector ) . data ( 'list' , colList ) ;
904934$ ( that . popup . targetSelector ) . trigger ( { type :'change' , colList :colList } ) ;
905935that . closeInnerPopup ( ) ;
@@ -911,13 +941,11 @@ define([
911941var key = $ ( tags [ i ] ) . data ( 'code' ) ;
912942var val = $ ( tags [ i ] ) . val ( ) ;
913943if ( val && val != '' ) {
914- dict [ key ] = "'" + val + "'" ;
944+ dict [ key ] = val ;
915945}
916946}
917947
918- console . log ( dict ) ;
919-
920- $ ( that . popup . targetSelector ) . val ( Object . values ( dict ) . join ( ',' ) ) ;
948+ $ ( that . popup . targetSelector ) . val ( Object . values ( dict ) . map ( val => "'" + val + "'" ) . join ( ',' ) ) ;
921949$ ( that . popup . targetSelector ) . data ( 'dict' , dict ) ;
922950$ ( that . popup . targetSelector ) . trigger ( { type :'change' , namingDict :dict } ) ;
923951that . closeInnerPopup ( ) ;
@@ -980,6 +1008,10 @@ define([
9801008 display, method, advanced, allocateTo, resetIndex
9811009} = this . state ;
9821010
1011+ // mapping colList states
1012+ groupby = groupby . map ( col => col . code ) ;
1013+ display = display . map ( col => col . code ) ;
1014+
9831015//====================================================================
9841016// Allocation
9851017//====================================================================
@@ -1000,9 +1032,8 @@ define([
10001032// Grouper
10011033if ( useGrouper ) {
10021034byStr = vpCommon . formatString ( "pd.Grouper(key={0}, freq='{1}')" , byStr , grouperNumber + grouperPeriod ) ;
1003- }
1004-
1005- if ( resetIndex == true ) {
1035+ } else if ( resetIndex == true ) {
1036+ // as_index option cannot use with Grouper -> use .reset_index() at the end
10061037byStr += ', as_index=False' ;
10071038}
10081039// variable & groupby columns & option
@@ -1039,6 +1070,9 @@ define([
10391070}
10401071for ( var i = 0 ; i < advItemTags . length ; i ++ ) {
10411072var advColumns = $ ( advItemTags [ i ] ) . find ( '.vp-gb-adv-col' ) . data ( 'list' ) ;
1073+ if ( advColumns && advColumns . length > 0 ) {
1074+ advColumns = advColumns . map ( col => col . code ) ;
1075+ }
10421076var advMethod = $ ( advItemTags [ i ] ) . find ( '.vp-gb-adv-method' ) . val ( ) ;
10431077var advNaming = $ ( advItemTags [ i ] ) . find ( '.vp-gb-adv-naming' ) . data ( 'dict' ) ;
10441078if ( ! advMethod || advMethod == '' || advMethod == "''" ) {
@@ -1047,6 +1081,9 @@ define([
10471081if ( advColumns && advColumns . length > 0 ) {
10481082advColumns . forEach ( col => {
10491083var naming = advNaming [ col ] ;
1084+ if ( naming && naming != '' ) {
1085+ naming = "'" + naming + "'" ;
1086+ }
10501087if ( Object . keys ( advColumnDict ) . includes ( col ) ) {
10511088advColumnDict [ col ] . push ( { method :advMethod , naming :naming } )
10521089} else {
@@ -1055,7 +1092,11 @@ define([
10551092} ) ;
10561093
10571094} else {
1058- advColumnDict [ 'nothing' ] . push ( { method :advMethod , naming :advNaming [ advMethod ] } ) ;
1095+ var naming = advNaming [ advMethod ] ;
1096+ if ( naming && naming != '' ) {
1097+ naming = "'" + naming + "'" ;
1098+ }
1099+ advColumnDict [ 'nothing' ] . push ( { method :advMethod , naming :naming } ) ;
10591100}
10601101}
10611102
@@ -1065,7 +1106,7 @@ define([
10651106var noColList = advColumnDict [ 'nothing' ] ;
10661107if ( noColList . length == 1 ) {
10671108// 1 method
1068- if ( noColList [ 0 ] . naming && noColList [ 0 ] . naming != undefined ) {
1109+ if ( noColList [ 0 ] . naming && noColList [ 0 ] . naming != '' ) {
10691110methodStr . appendFormat ( "[({0}, {1})]" , noColList [ 0 ] . naming , noColList [ 0 ] . method ) ;
10701111} else {
10711112methodStr . appendFormat ( "{0}" , noColList [ 0 ] . method ) ;
@@ -1074,7 +1115,7 @@ define([
10741115// more than 1 method
10751116var tmpList = [ ] ;
10761117noColList . forEach ( obj => {
1077- if ( obj . naming && obj . naming != undefined ) {
1118+ if ( obj . naming && obj . naming != '' ) {
10781119tmpList . push ( vpCommon . formatString ( "({0}, {1})" , obj . naming , obj . method ) ) ;
10791120} else {
10801121tmpList . push ( obj . method ) ;
@@ -1106,7 +1147,7 @@ define([
11061147var tmpList2 = [ ] ;
11071148var useTuple = false ;
11081149colList . forEach ( obj => {
1109- if ( obj . naming && obj . naming != undefined ) {
1150+ if ( obj . naming && obj . naming != '' ) {
11101151tmpList2 . push ( vpCommon . formatString ( "({0}, {1})" , obj . naming , obj . method ) ) ;
11111152useTuple = true ;
11121153} else {
@@ -1129,6 +1170,11 @@ define([
11291170//================================================================
11301171methodStr . appendFormat ( '{0}()' , method ) ;
11311172}
1173+
1174+ // when using as_index option with Grouper, use .reset_index()
1175+ if ( useGrouper && resetIndex ) {
1176+ methodStr . append ( '.reset_index()' ) ;
1177+ }
11321178// display columns
11331179code . appendFormat ( '{0}.{1}' , colStr , methodStr . toString ( ) ) ;
11341180