@@ -102,6 +102,7 @@ define([
102
102
]
103
103
104
104
this . methodList = [
105
+ { label : 'None' , value : '' } ,
105
106
{ label : 'count' , value : 'count' } ,
106
107
{ label : 'first' , value : 'first' } ,
107
108
{ label : 'last' , value : 'last' } ,
@@ -134,13 +135,14 @@ define([
134
135
_loadState ( state ) {
135
136
var {
136
137
variable, groupby, useGrouper, grouperNumber, grouperPeriod,
137
- display, method, advanced, allocateTo, resetIndex,
138
+ display, method, advanced, allocateTo, toFrame , resetIndex,
138
139
advPageDom, advColList, advNamingList
139
140
} = state ;
140
141
141
142
$ ( this . _wrapSelector ( '#vp_gbVariable' ) ) . val ( variable ) ;
142
143
$ ( this . _wrapSelector ( '#vp_gbBy' ) ) . val ( groupby . map ( col => col . code ) . join ( ',' ) ) ;
143
144
$ ( this . _wrapSelector ( '#vp_gbBy' ) ) . data ( 'list' , groupby ) ;
145
+ $ ( this . _wrapSelector ( '#vp_gbResetIndex' ) ) . val ( resetIndex ?'yes' :'no' ) ;
144
146
if ( useGrouper ) {
145
147
$ ( this . _wrapSelector ( '#vp_gbByGrouper' ) ) . removeAttr ( 'disabled' ) ;
146
148
$ ( this . _wrapSelector ( '#vp_gbByGrouper' ) ) . prop ( 'checked' , useGrouper ) ;
@@ -157,7 +159,7 @@ define([
157
159
$ ( this . _wrapSelector ( '#vp_gbAdvanced' ) ) . trigger ( 'change' ) ;
158
160
}
159
161
$ ( this . _wrapSelector ( '#vp_gbAllocateTo' ) ) . val ( allocateTo ) ;
160
- $ ( this . _wrapSelector ( '#vp_gbResetIndex ' ) ) . val ( resetIndex ? 'yes' : 'no' ) ;
162
+ $ ( this . _wrapSelector ( '#vp_gbToFrame ' ) ) . val ( toFrame ) ;
161
163
162
164
$ ( this . _wrapSelector ( '.vp-gb-adv-box' ) ) . html ( advPageDom ) ;
163
165
@@ -358,6 +360,7 @@ define([
358
360
page . appendLine ( '<div>' ) ;
359
361
page . appendFormatLine ( '<label for="{0}" class="{1}">{2}</label>' , 'vp_gbAllocateTo' , 'wp80' , 'Allocate to' ) ;
360
362
page . appendFormatLine ( '<input type="text" id="{0}" placeholder="{1}"/>' , 'vp_gbAllocateTo' , 'New variable name' ) ;
363
+ page . appendFormatLine ( '<label style="display:none;"><input type="checkbox" id="{0}"/><span>{1}</span></label>' , 'vp_gbToFrame' , 'To DataFrame' ) ;
361
364
page . appendLine ( '</div>' ) ;
362
365
363
366
page . appendLine ( '</div>' ) ; // end of df-box
@@ -716,6 +719,12 @@ define([
716
719
$ ( document ) . on ( 'change' , this . _wrapSelector ( '#vp_gbDisplay' ) , function ( event ) {
717
720
var colList = event . dataList ;
718
721
that . state . display = colList ;
722
+
723
+ if ( colList && colList . length == 1 ) {
724
+ $ ( that . _wrapSelector ( '#vp_gbToFrame' ) ) . parent ( ) . show ( ) ;
725
+ } else {
726
+ $ ( that . _wrapSelector ( '#vp_gbToFrame' ) ) . parent ( ) . hide ( ) ;
727
+ }
719
728
} ) ;
720
729
721
730
// display select button event
@@ -756,6 +765,11 @@ define([
756
765
$ ( document ) . on ( 'change' , this . _wrapSelector ( '#vp_gbAllocateTo' ) , function ( ) {
757
766
that . state . allocateTo = $ ( this ) . val ( ) ;
758
767
} ) ;
768
+
769
+ // to dataframe event
770
+ $ ( document ) . on ( 'change' , this . _wrapSelector ( '#vp_gbToFrame' ) , function ( ) {
771
+ that . state . toFrame = $ ( this ) . prop ( 'checked' ) == true ;
772
+ } ) ;
759
773
760
774
// reset index checkbox event
761
775
$ ( document ) . on ( 'change' , this . _wrapSelector ( '#vp_gbResetIndex' ) , function ( ) {
@@ -1009,9 +1023,13 @@ define([
1009
1023
var code = new sb . StringBuilder ( ) ;
1010
1024
var {
1011
1025
variable, groupby, useGrouper, grouperNumber, grouperPeriod,
1012
- display, method, advanced, allocateTo, resetIndex
1026
+ display, method, advanced, allocateTo, toFrame , resetIndex
1013
1027
} = this . state ;
1014
1028
1029
+ if ( ! variable || variable == '' ) {
1030
+ return '' ;
1031
+ }
1032
+
1015
1033
// mapping colList states
1016
1034
groupby = groupby . map ( col => col . code ) ;
1017
1035
display = display . map ( col => col . code ) ;
@@ -1048,13 +1066,13 @@ define([
1048
1066
//====================================================================
1049
1067
var colStr = '' ;
1050
1068
if ( display ) {
1051
- if ( display . length == 1 ) {
1052
- // for 1 column
1053
- colStr = '[' + display . join ( '' ) + ']' ;
1054
- } else if ( display . length > 1 ) {
1069
+ if ( toFrame || display . length > 1 ) {
1055
1070
// over 2 columns
1056
1071
colStr = '[[' + display . join ( ',' ) + ']]' ;
1057
- }
1072
+ } else if ( display . length == 1 ) {
1073
+ // for 1 column
1074
+ colStr = '[' + display . join ( '' ) + ']' ;
1075
+ }
1058
1076
}
1059
1077
1060
1078
//====================================================================
@@ -1172,21 +1190,24 @@ define([
1172
1190
//================================================================
1173
1191
// Method code generation
1174
1192
//================================================================
1175
- methodStr . appendFormat ( '{0}()' , method ) ;
1193
+ if ( method != '' ) {
1194
+ methodStr . appendFormat ( '{0}()' , method ) ;
1195
+ }
1176
1196
}
1177
1197
1178
- // when using as_index option with Grouper, use .reset_index()
1179
- if ( useGrouper && resetIndex ) {
1180
- methodStr . append ( '.reset_index()' ) ;
1198
+ if ( method != '' ) {
1199
+ // when using as_index option with Grouper, use .reset_index()
1200
+ if ( useGrouper && resetIndex ) {
1201
+ methodStr . append ( '.reset_index()' ) ;
1202
+ }
1203
+ // display columns
1204
+ code . appendFormat ( '{0}.{1}' , colStr , methodStr . toString ( ) ) ;
1181
1205
}
1182
- // display columns
1183
- code . appendFormat ( '{0}.{1}' , colStr , methodStr . toString ( ) ) ;
1184
-
1206
+
1185
1207
if ( allocateTo && allocateTo != '' ) {
1186
1208
code . appendLine ( ) ;
1187
1209
code . append ( allocateTo ) ;
1188
1210
}
1189
-
1190
1211
return code . toString ( ) ;
1191
1212
}
1192
1213
0 commit comments