Skip to content

Commit d660932

Browse files
author
minjk-bl
committed
Groupby - method None added, to frame added
1 parent c8bc0e4 commit d660932

File tree

1 file changed

+37
-16
lines changed

1 file changed

+37
-16
lines changed

src/common/vpGroupby.js

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ define([
102102
]
103103

104104
this.methodList = [
105+
{ label: 'None', value: '' },
105106
{ label: 'count', value: 'count' },
106107
{ label: 'first', value: 'first' },
107108
{ label: 'last', value: 'last' },
@@ -134,13 +135,14 @@ define([
134135
_loadState(state) {
135136
var {
136137
variable, groupby, useGrouper, grouperNumber, grouperPeriod,
137-
display, method, advanced, allocateTo, resetIndex,
138+
display, method, advanced, allocateTo, toFrame, resetIndex,
138139
advPageDom, advColList, advNamingList
139140
} = state;
140141

141142
$(this._wrapSelector('#vp_gbVariable')).val(variable);
142143
$(this._wrapSelector('#vp_gbBy')).val(groupby.map(col=>col.code).join(','));
143144
$(this._wrapSelector('#vp_gbBy')).data('list', groupby);
145+
$(this._wrapSelector('#vp_gbResetIndex')).val(resetIndex?'yes':'no');
144146
if (useGrouper) {
145147
$(this._wrapSelector('#vp_gbByGrouper')).removeAttr('disabled');
146148
$(this._wrapSelector('#vp_gbByGrouper')).prop('checked', useGrouper);
@@ -157,7 +159,7 @@ define([
157159
$(this._wrapSelector('#vp_gbAdvanced')).trigger('change');
158160
}
159161
$(this._wrapSelector('#vp_gbAllocateTo')).val(allocateTo);
160-
$(this._wrapSelector('#vp_gbResetIndex')).val(resetIndex?'yes':'no');
162+
$(this._wrapSelector('#vp_gbToFrame')).val(toFrame);
161163

162164
$(this._wrapSelector('.vp-gb-adv-box')).html(advPageDom);
163165

@@ -358,6 +360,7 @@ define([
358360
page.appendLine('<div>');
359361
page.appendFormatLine('<label for="{0}" class="{1}">{2}</label>', 'vp_gbAllocateTo', 'wp80', 'Allocate to');
360362
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');
361364
page.appendLine('</div>');
362365

363366
page.appendLine('</div>'); // end of df-box
@@ -716,6 +719,12 @@ define([
716719
$(document).on('change', this._wrapSelector('#vp_gbDisplay'), function(event) {
717720
var colList = event.dataList;
718721
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+
}
719728
});
720729

721730
// display select button event
@@ -756,6 +765,11 @@ define([
756765
$(document).on('change', this._wrapSelector('#vp_gbAllocateTo'), function() {
757766
that.state.allocateTo = $(this).val();
758767
});
768+
769+
// to dataframe event
770+
$(document).on('change', this._wrapSelector('#vp_gbToFrame'), function() {
771+
that.state.toFrame = $(this).prop('checked') == true;
772+
});
759773

760774
// reset index checkbox event
761775
$(document).on('change', this._wrapSelector('#vp_gbResetIndex'), function() {
@@ -1009,9 +1023,13 @@ define([
10091023
var code = new sb.StringBuilder();
10101024
var {
10111025
variable, groupby, useGrouper, grouperNumber, grouperPeriod,
1012-
display, method, advanced, allocateTo, resetIndex
1026+
display, method, advanced, allocateTo, toFrame, resetIndex
10131027
} = this.state;
10141028

1029+
if (!variable || variable == '') {
1030+
return '';
1031+
}
1032+
10151033
// mapping colList states
10161034
groupby = groupby.map(col => col.code);
10171035
display = display.map(col => col.code);
@@ -1048,13 +1066,13 @@ define([
10481066
//====================================================================
10491067
var colStr = '';
10501068
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) {
10551070
// over 2 columns
10561071
colStr = '[[' + display.join(',') + ']]';
1057-
}
1072+
} else if (display.length == 1) {
1073+
// for 1 column
1074+
colStr = '[' + display.join('') + ']';
1075+
}
10581076
}
10591077

10601078
//====================================================================
@@ -1172,21 +1190,24 @@ define([
11721190
//================================================================
11731191
// Method code generation
11741192
//================================================================
1175-
methodStr.appendFormat('{0}()', method);
1193+
if (method != '') {
1194+
methodStr.appendFormat('{0}()', method);
1195+
}
11761196
}
11771197

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());
11811205
}
1182-
// display columns
1183-
code.appendFormat('{0}.{1}', colStr, methodStr.toString());
1184-
1206+
11851207
if (allocateTo && allocateTo != '') {
11861208
code.appendLine();
11871209
code.append(allocateTo);
11881210
}
1189-
11901211
return code.toString();
11911212
}
11921213

0 commit comments

Comments
 (0)