@@ -20,8 +20,9 @@ define([
20
20
'vp_base/js/com/com_generatorV2' ,
21
21
'vp_base/js/com/component/PopupComponent' ,
22
22
'vp_base/js/com/component/DataSelector' ,
23
+ 'vp_base/js/com/component/SuggestInput' ,
23
24
'vp_base/js/m_apps/Subset'
24
- ] , function ( stHTML , com_util , com_Const , com_String , com_generator , PopupComponent , DataSelector , Subset ) {
25
+ ] , function ( stHTML , com_util , com_Const , com_String , com_generator , PopupComponent , DataSelector , SuggestInput , Subset ) {
25
26
26
27
/**
27
28
* StudentstTest
@@ -46,6 +47,8 @@ define([
46
47
groupingVariable : '' ,
47
48
group1 : '' ,
48
49
group2 : '' ,
50
+ group1_istext : true ,
51
+ group2_istext : true ,
49
52
pairedVariable1 : '' ,
50
53
pairedVariable2 : '' ,
51
54
testValue : '' ,
@@ -126,24 +129,58 @@ define([
126
129
// get result and load column list
127
130
vpKernel . getColumnCategory ( that . state . data , colCode ) . then ( function ( resultObj ) {
128
131
let { result } = resultObj ;
129
- $ ( that . wrapSelector ( '#group1' ) ) . html ( '' ) ;
130
- $ ( that . wrapSelector ( '#group2' ) ) . html ( '' ) ;
132
+ $ ( that . wrapSelector ( '#group1' ) ) . val ( '' ) ;
133
+ $ ( that . wrapSelector ( '#group2' ) ) . val ( '' ) ;
134
+ that . state . group1 = '' ;
135
+ that . state . group2 = '' ;
136
+ that . state . group1_istext = true ;
137
+ that . state . group2_istext = true ;
131
138
try {
132
139
var category = JSON . parse ( result ) ;
133
- if ( category && category . length > 0 && colDtype == 'object' ) {
134
- // if it's categorical column and its dtype is object, check 'Text' as default
135
- category . forEach ( obj => {
136
- let selected1 = obj . value === that . state . group1 ;
137
- let selected2 = obj . value === that . state . group2 ;
138
- $ ( that . wrapSelector ( '#group1' ) ) . append ( `<option value="${ obj . value } " ${ selected1 ?'selected' :'' } >${ obj . label } </option>` ) ;
139
- $ ( that . wrapSelector ( '#group2' ) ) . append ( `<option value="${ obj . value } " ${ selected2 ?'selected' :'' } >${ obj . label } </option>` ) ;
140
- } ) ;
140
+ // if (category && category.length > 0 && colDtype == 'object') {
141
+ // // if it's categorical column and its dtype is object, check 'Text' as default
142
+ // category.forEach(obj => {
143
+ // let selected1 = obj.value === that.state.group1;
144
+ // let selected2 = obj.value === that.state.group2;
145
+ // $(that.wrapSelector('#group1')).append(`<option value="${obj.value}" ${selected1?'selected':''}>${obj.label}</option>`);
146
+ // $(that.wrapSelector('#group2')).append(`<option value="${obj.value}" ${selected2?'selected':''}>${obj.label}</option>`);
147
+ // });
148
+ // }
149
+ var groupSuggest1 = new SuggestInput ( ) ;
150
+ groupSuggest1 . setComponentID ( 'group1' ) ;
151
+ groupSuggest1 . addClass ( 'vp-input vp-state' ) ;
152
+ groupSuggest1 . setSuggestList ( function ( ) { return category ; } ) ;
153
+ groupSuggest1 . setNormalFilter ( true ) ;
154
+ groupSuggest1 . setPlaceholder ( 'Select value' ) ;
155
+ $ ( that . wrapSelector ( '#group1' ) ) . replaceWith ( groupSuggest1 . toTagString ( ) ) ;
156
+ var groupSuggest2 = new SuggestInput ( ) ;
157
+ groupSuggest2 . setComponentID ( 'group2' ) ;
158
+ groupSuggest2 . addClass ( 'vp-input vp-state' ) ;
159
+ groupSuggest2 . setSuggestList ( function ( ) { return category ; } ) ;
160
+ groupSuggest2 . setNormalFilter ( true ) ;
161
+ groupSuggest2 . setPlaceholder ( 'Select value' ) ;
162
+ $ ( that . wrapSelector ( '#group2' ) ) . replaceWith ( groupSuggest2 . toTagString ( ) ) ;
163
+
164
+ if ( category && category . length > 0 ) {
141
165
that . state . group1 = category [ 0 ] . value ;
142
166
that . state . group2 = category [ 0 ] . value ;
143
167
}
168
+
169
+ if ( colDtype == 'object' ) {
170
+ // check as default
171
+ $ ( that . wrapSelector ( '#group1_istext' ) ) . prop ( 'checked' , true ) ;
172
+ $ ( that . wrapSelector ( '#group2_istext' ) ) . prop ( 'checked' , true ) ;
173
+ that . state . group1_istext = true ;
174
+ that . state . group2_istext = true ;
175
+ } else {
176
+ $ ( that . wrapSelector ( '#group1_istext' ) ) . prop ( 'checked' , false ) ;
177
+ $ ( that . wrapSelector ( '#group2_istext' ) ) . prop ( 'checked' , false ) ;
178
+ that . state . group1_istext = false ;
179
+ that . state . group2_istext = false ;
180
+ }
144
181
} catch {
145
- $ ( that . wrapSelector ( '#group1' ) ) . html ( '' ) ;
146
- $ ( that . wrapSelector ( '#group2' ) ) . html ( '' ) ;
182
+ $ ( that . wrapSelector ( '#group1' ) ) . val ( '' ) ;
183
+ $ ( that . wrapSelector ( '#group2' ) ) . val ( '' ) ;
147
184
}
148
185
} ) ;
149
186
} ) ;
@@ -231,7 +268,7 @@ define([
231
268
testType, inputType, data,
232
269
testVariable, testVariable1, testVariable2, groupingVariable,
233
270
pairedVariable1, pairedVariable2,
234
- group1, group2,
271
+ group1, group2, group1_istext , group2_istext ,
235
272
testValue, alterHypo, confInt
236
273
} = this . state ;
237
274
let codeList = [ ] ;
@@ -276,8 +313,8 @@ define([
276
313
code . appendLine ( "# Independent two-sample t-test" ) ;
277
314
// variable declaration
278
315
if ( inputType === 'long-data' ) {
279
- code . appendFormatLine ( "vp_df1 = {0}[({1}[{2}] == ' {3}' )][{4}].dropna().copy()" , data , data , groupingVariable , group1 , testVariable ) ;
280
- code . appendFormatLine ( "vp_df2 = {0}[({1}[{2}] == ' {3}' )][{4}].dropna().copy()" , data , data , groupingVariable , group2 , testVariable ) ;
316
+ code . appendFormatLine ( "vp_df1 = {0}[({1}[{2}] == {3})][{4}].dropna().copy()" , data , data , groupingVariable , com_util . convertToStr ( group1 , group1_istext ) , testVariable ) ;
317
+ code . appendFormatLine ( "vp_df2 = {0}[({1}[{2}] == {3})][{4}].dropna().copy()" , data , data , groupingVariable , com_util . convertToStr ( group2 , group2_istext ) , testVariable ) ;
281
318
} else if ( inputType === 'wide-data' ) {
282
319
code . appendFormatLine ( "vp_df1 = {0}[{1}].dropna().copy()" , data , testVariable1 ) ;
283
320
code . appendFormatLine ( "vp_df2 = {0}[{1}].dropna().copy()" , data , testVariable2 ) ;
0 commit comments