', VP_FE_TABLE, 'vp_rendered_html', 'vp-scrollbar');
if (isHtml) {
tag.appendFormatLine('
', renderedText);
// More button
- tag.appendFormatLine('
More...
', VP_FE_TABLE_MORE, 'vp-button');
} else {
tag.appendFormatLine('
', renderedText);
}
@@ -1050,7 +1183,7 @@ define([
}
}
if (type === 'column') {
- content.appendLine('
| ');
content.appendFormatLine('
-
+
+
+
-
+
+
+
@@ -1270,7 +1407,7 @@ define([
var content = new com_String();
content.appendFormatLine('', 'vp-inner-popup-shift-page');
content.appendLine(' ');
- content.appendLine('');
+ content.appendLine('');
content.appendLine('');
content.appendFormatLine(' | ', 'Periods');
content.appendFormatLine(' | '
@@ -1302,33 +1439,26 @@ define([
/**
*
- * @param {int} type FRAME_AXIS
+ * @param {int} method index / values
* @returns
*/
- renderSortPage(type=FRAME_AXIS.COLUMN) {
+ renderSortPage(method='values') {
var content = new com_String();
content.appendFormatLine('', 'vp-inner-popup-sort-page');
content.appendLine(' ');
- // sort by
+ // axis
let sortByStr = 'column';
- let sortByList = [];
- if (type === FRAME_AXIS.ROW) {
+ if (method === 'index') {
+ content.appendFormatLine(' ', 'Axis');
+ content.appendFormatLine(' ');
sortByStr = 'level';
- sortByList = Array.from({ length:this.state.indexLevel },(v,k)=>{ return {label: k, code: k} });
- } else {
- sortByList = this.state.selected;
}
+ // sort by
content.appendFormatLine(' ', 'Sort by', sortByStr);
- // movable list
- content.appendLine('');
+ content.appendLine(this.templateForSortByBox(method));
// ascending
content.appendFormatLine(' ', 'Ascending');
@@ -1343,23 +1473,71 @@ define([
return content.toString();
}
+ templateForSortByBox(method='index', axis=FRAME_AXIS.ROW) {
+ var content = new com_String();
+ let sortByList = [];
+ if (method === 'values') {
+ // sort_values
+ sortByList = this.state.selected;
+ } else {
+ // sort_index
+ if (axis === FRAME_AXIS.ROW) {
+ sortByList = Array.from({ length:this.state.indexLevel },(v,k)=>{ return {label: k, code: k} });
+ } else {
+ sortByList = Array.from({ length:this.state.columnLevel },(v,k)=>{ return {label: k, code: k} });
+ }
+ }
+
+ // movable list
+ content.appendLine('');
+ return content.toString();
+ }
+
renderReplacePage() {
var content = new com_String();
content.appendFormatLine(' ', 'vp-inner-popup-replacepage');
content.appendLine(' ');
- content.appendLine(' ');
+ content.appendLine('');
content.appendFormatLine('{1} | ', '', 'Column');
var target = this.state.selected.map(col => col.label).join(',');
content.appendFormatLine('', 'vp-inner-popup-input1', target);
content.appendLine(' | ');
+ content.appendLine(' | ');
+ content.appendFormatLine(' | ');
content.appendLine(' ');
content.appendLine(''); // end of vp-inner-popup-header
content.appendLine(' ');
- // replace page
+ // replace page - 1. value
+ content.appendFormatLine('', 'vp-inner-popup-tab value');
+ content.appendFormatLine(' ', 'vp-inner-popup-use-regex', 'Use Regular Expression');
+ content.appendLine(' ');
content.appendFormatLine(' ', 'vp-inner-popup-replace-table');
+ content.appendLine(' ');
+ content.appendLine('');
+ content.appendFormatLine('{0} | {1} | | ', 'Value', 'New value');
+ content.appendLine('');
+ content.appendLine(this.renderReplaceInput(0));
+ content.appendFormatLine(' | ', 'vp-button', 'vp-inner-popup-replace-add', '+ Add value');
+ content.appendLine('');
+ content.appendLine(' ');
+ content.appendLine(' ');
+ content.appendLine(' ');
+ // replace page - 2. condition
+ content.appendFormatLine('', 'vp-inner-popup-tab condition');
// subset
- content.appendLine(' ');
+ content.appendLine('');
content.appendLine(''); // end of vp-inner-popup-addpage
@@ -1383,12 +1558,30 @@ define([
return content.toString();
}
+ renderReplaceInput(index) {
+ var content = new com_String();
+ content.appendLine('');
+ content.appendLine('');
+ content.appendFormatLine('', 'vp-inner-popup-origin' + index, 'Origin');
+ content.appendFormatLine('', 'vp-inner-popup-origin-istext' + index, 'Text');
+ content.appendLine(' | ');
+ content.appendLine('');
+ content.appendFormatLine('', 'vp-inner-popup-replace' + index, 'Replace');
+ content.appendFormatLine('', 'vp-inner-popup-replace-istext' + index, 'Text');
+ content.appendLine(' | ');
+ // LAB: img to url
+ // content.appendFormatLine(' | ', 'vp-inner-popup-delete', 'vp-cursor', com_Const.IMAGE_PATH + 'close_small.svg');
+ content.appendFormatLine(' | ', 'vp-inner-popup-delete', 'vp-cursor', 'vp-icon-close-small');
+ content.appendLine(' ');
+ return content.toString();
+ }
+
renderAsType() {
var astypeList = this.astypeList;
var content = new com_String();
content.appendFormatLine('', 'vp-inner-popup-astype');
- content.appendFormatLine(' ', 'vp-inner-popup-astype-table');
- content.appendLine('');
+ content.appendFormatLine('', 'vp-inner-popup-astype-table');
+ content.appendLine('');
content.appendFormatLine('{0} | {1} | {3} | '
, 'Column', 'Data type', 'vp-orange-text', 'New data type');
content.appendLine('');
@@ -1416,8 +1609,16 @@ define([
var content = new com_String();
content.appendFormatLine('', 'vp-inner-popup-fillna-page');
content.appendLine(' ');
- content.appendLine('');
+ content.appendLine('');
content.appendLine('');
+ content.appendFormatLine(' | ', 'Method');
+ content.appendFormatLine(' | ');
+ content.appendLine(' ');
+ content.appendFormatLine('', 'vp-inner-popup-value-row');
content.appendFormatLine(' | ', 'Fill value');
content.appendLine('');
content.appendFormatLine(''
@@ -1426,15 +1627,7 @@ define([
, 'vp-inner-popup-valueastext', 'Text');
content.appendLine(' | ');
content.appendLine(' ');
- content.appendLine('');
- content.appendFormatLine(' | ', 'Method');
- content.appendFormatLine(' | ');
- content.appendLine(' ');
- content.appendLine('');
+ content.appendFormatLine(' ', 'vp-inner-popup-fill-row');
content.appendFormatLine(' | ', 'Limit');
content.appendLine('');
content.appendFormatLine(''
@@ -1449,11 +1642,72 @@ define([
return content.toString();
}
- openInputPopup(type, width=400, height=400) {
+ renderDropNAPage() {
+ // how / thresh / ignore_index
+ let content = ``;
+
+ // set content
+ $(this.wrapSelector('.vp-inner-popup-body')).html(content);
+ return content.toString();
+ }
+
+ renderDropDupPage() {
+ // keep / ignore_index
+ let content = ``;
+
+ // set content
+ $(this.wrapSelector('.vp-inner-popup-body')).html(content);
+ return content.toString();
+ }
+
+ renderDropOutPage() {
+ var content = new com_String();
+ content.appendFormatLine('', 'vp-inner-popup-dropout-page');
+ content.appendLine('Are you sure to drop outliers from columns below?');
+ content.appendFormatLine(' {0} ', this.state.selected.map(col=>col.code).join(', '))
+ content.appendLine(' ');
+
+ // set content
+ $(this.wrapSelector('.vp-inner-popup-body')).html(content.toString());
+ return content.toString();
+ }
+
+ openInputPopup(type, width=450, height=450) {
var title = '';
var content = '';
let size = { width: width, height: height };
let that = this;
+
+ $(this.wrapSelector('.vp-inner-popup-body')).html('');
switch (parseInt(type)) {
case FRAME_EDIT_TYPE.ADD_COL:
@@ -1582,17 +1836,16 @@ define([
break;
case FRAME_EDIT_TYPE.SORT_INDEX:
title = 'Sort by index';
- content = this.renderSortPage(FRAME_AXIS.ROW);
+ content = this.renderSortPage('index');
break;
case FRAME_EDIT_TYPE.SORT_VALUES:
title = 'Sort by values';
- content = this.renderSortPage(FRAME_AXIS.COLUMN);
+ content = this.renderSortPage('values');
break;
case FRAME_EDIT_TYPE.REPLACE:
title = 'Replace';
// content = this.renderReplacePage();
content = this.renderReplacePage();
- size = { width: 450, height: 300 };
// bind codemirror
this.subsetCm = this.initCodemirror({
@@ -1658,15 +1911,30 @@ define([
// bind event on method
$(this.wrapSelector('.vp-inner-popup-method')).on('change', function() {
let changedVal = $(this).val();
- if (changedVal === '') {
- // disable limit
- $(that.wrapSelector('.vp-inner-popup-limit')).prop('disabled', true);
+ if (changedVal === 'value') {
+ // show value row
+ $(that.wrapSelector('.vp-inner-popup-value-row')).show();
+ $(that.wrapSelector('.vp-inner-popup-fill-row')).hide();
} else {
- // enable limit
- $(that.wrapSelector('.vp-inner-popup-limit')).prop('disabled', false);
+ // show method fill row
+ $(that.wrapSelector('.vp-inner-popup-value-row')).hide();
+ $(that.wrapSelector('.vp-inner-popup-fill-row')).show();
}
});
break;
+ case FRAME_EDIT_TYPE.DROP_NA:
+ title = 'Drop NA';
+ content = this.renderDropNAPage();
+ break;
+ case FRAME_EDIT_TYPE.DROP_DUP:
+ title = 'Drop duplicates';
+ content = this.renderDropDupPage();
+ break;
+ case FRAME_EDIT_TYPE.DROP_OUT:
+ title = 'Drop outlier';
+ size = { width: 400, height: 200 };
+ content = this.renderDropOutPage();
+ break;
default:
type = FRAME_EDIT_TYPE.NONE;
break;
@@ -1674,8 +1942,13 @@ define([
this.state.popup.type = type;
- // set size
- $(this.wrapSelector('.vp-inner-popup-box')).css(size);
+ // set size and position
+ $(this.wrapSelector('.vp-inner-popup-box')).css({
+ width: size.width,
+ height: size.height,
+ left: 'calc(50% - ' + (size.width/2) + 'px)',
+ top: 'calc(50% - ' + (size.height/2) + 'px)',
+ });
// bindEventForAddPage
this.bindEventForPopupPage(type);
@@ -1759,9 +2032,31 @@ define([
$(this.wrapSelector('.vp-inner-popup-input1')).attr({'placeholder': 'Required input'});
$(this.wrapSelector('.vp-inner-popup-input1')).focus();
}
- content['subset'] = this.subsetCm?this.subsetCm.getValue():'';
- content['value'] = $(this.wrapSelector('.vp-inner-popup-input3')).val();
- content['valueastext'] = $(this.wrapSelector('.vp-inner-popup-istext3')).prop('checked');
+ var tab = $(this.wrapSelector('.vp-inner-popup-replacetype')).val();
+ content['replacetype'] = tab;
+ if (tab == 'value') {
+ var useregex = $(this.wrapSelector('.vp-inner-popup-use-regex')).prop('checked');
+ content['useregex'] = useregex;
+ content['list'] = [];
+ for (var i=0; i <= this.state.popup.replace.index; i++) {
+ var origin = $(this.wrapSelector('.vp-inner-popup-origin' + i)).val();
+ var origintext = $(this.wrapSelector('.vp-inner-popup-origin-istext'+i)).prop('checked');
+ var replace = $(this.wrapSelector('.vp-inner-popup-replace' + i)).val();
+ var replacetext = $(this.wrapSelector('.vp-inner-popup-replace-istext'+i)).prop('checked');
+ if (origin && replace) {
+ content['list'].push({
+ origin: origin,
+ origintext: origintext,
+ replace: replace,
+ replacetext: replacetext
+ });
+ }
+ }
+ } else if (tab === 'condition') {
+ content['subset'] = this.subsetCm?this.subsetCm.getValue():'';
+ content['value'] = $(this.wrapSelector('.vp-inner-popup-input3')).val();
+ content['valueastext'] = $(this.wrapSelector('.vp-inner-popup-istext3')).prop('checked');
+ }
break;
case FRAME_EDIT_TYPE.RENAME:
content['list'] = {};
@@ -1781,6 +2076,7 @@ define([
}
break;
case FRAME_EDIT_TYPE.SORT_INDEX:
+ content['axis'] = $(this.wrapSelector('.vp-inner-popup-axis')).val();
case FRAME_EDIT_TYPE.SORT_VALUES:
let values = [];
$(this.wrapSelector('.vp-inner-popup-sortby-item')).each((idx, tag) => {
@@ -1835,11 +2131,20 @@ define([
}
break;
case FRAME_EDIT_TYPE.FILL_NA:
+ content['method'] = $(this.wrapSelector('.vp-inner-popup-method')).val();
content['value'] = $(this.wrapSelector('.vp-inner-popup-value')).val();
content['valueastext'] = $(this.wrapSelector('.vp-inner-popup-valueastext')).prop('checked');
- content['method'] = $(this.wrapSelector('.vp-inner-popup-method')).val();
content['limit'] = $(this.wrapSelector('.vp-inner-popup-limit')).val();
break;
+ case FRAME_EDIT_TYPE.DROP_NA:
+ content['how'] = $(this.wrapSelector('.vp-inner-popup-how')).val();
+ content['thresh'] = $(this.wrapSelector('.vp-inner-popup-thresh')).val();
+ content['ignore_index'] = $(this.wrapSelector('.vp-inner-popup-ignoreindex')).val();
+ break;
+ case FRAME_EDIT_TYPE.DROP_DUP:
+ content['keep'] = $(this.wrapSelector('.vp-inner-popup-how')).val();
+ content['ignore_index'] = $(this.wrapSelector('.vp-inner-popup-ignoreindex')).val();
+ break;
default:
break;
}
@@ -1860,7 +2165,7 @@ define([
renderInfoPage = function(renderedText, isHtml = true) {
var tag = new com_String();
tag.appendFormatLine('', VP_FE_INFO_CONTENT
- , 'rendered_html'); // 'rendered_html' style from jupyter output area
+ , 'vp_rendered_html'); // 'rendered_html' style from jupyter output area
if (isHtml) {
tag.appendLine(renderedText);
} else {
@@ -1900,8 +2205,6 @@ define([
// code.append(".value_counts()");
code.appendFormat('_vp_display_dataframe_info({0})', locObj.toString());
- // CHROME: TODO: 6: use com_Kernel.execute
- // Jupyter.notebook.kernel.execute(
vpKernel.execute(code.toString()).then(function(resultObj) {
let { msg } = resultObj;
if (msg.content.data) {
@@ -1993,16 +2296,34 @@ define([
case FRAME_EDIT_TYPE.DROP_NA:
var locObj = '';
if (axis == FRAME_AXIS.ROW) {
- locObj = com_util.formatString('.loc[[{0}],:]', selectedName);
+ code.appendFormat("{0}.loc[[{1}],:].dropna(axis=0", tempObj, selectedName);
} else {
- locObj = com_util.formatString('.loc[:,[{0}]]', selectedName);
+ code.appendFormat("{0}.loc[:,[{1}]].dropna(axis=1", tempObj, selectedName);
+ }
+ if (content.how && content.how !== '') {
+ code.appendFormat(", how='{0}'", content.how);
}
- code.appendFormat("{0}{1}.dropna(axis={2}, inplace=True)", tempObj, locObj, axis);
+ if (content.thresh && content.thresh !== '') {
+ code.appendFormat(", thresh={0}", content.thresh);
+ }
+ if (content.ignore_index && content.ignore_index !== '') {
+ code.appendFormat(", ignore_index={0}", content.ignore_index);
+ }
+ code.append(", inplace=True)");
break;
case FRAME_EDIT_TYPE.DROP_DUP:
- if (axis == FRAME_AXIS.COLUMN) {
- code.appendFormat("{0}.drop_duplicates(subset=[{1}], inplace=True)", tempObj, selectedName);
+ let dropDupOptions = [];
+ if (selectedName && selectedName !== '') {
+ dropDupOptions.push(com_util.formatString("subset=[{0}]", selectedName));
+ }
+ if (content.keep && content.keep !== '') {
+ dropDupOptions.push(com_util.formatString("keep={0}", content.keep));
}
+ if (content.ignore_index && content.ignore_index !== '') {
+ dropDupOptions.push(com_util.formatString("ignore_index={0}", content.ignore_index));
+ }
+ dropDupOptions.push(com_util.formatString("inplace=True"));
+ code.appendFormat("{0}.drop_duplicates({1})", tempObj, dropDupOptions.join(', '));
break;
case FRAME_EDIT_TYPE.DROP_OUT:
if (axis == FRAME_AXIS.COLUMN) {
@@ -2036,11 +2357,11 @@ define([
case FRAME_EDIT_TYPE.SORT_INDEX:
let selectedStr = '';
if (content.values.length > 1) {
- selectedStr = "[" + content.values.join(',') + "]";
+ selectedStr = content.values.join(',');
}
- code.appendFormat("{0}.sort_index(ascending={1}", tempObj, content.ascending);
+ code.appendFormat("{0}.sort_index(axis={1}, ascending={2}", tempObj, content.axis, content.ascending);
if (selectedStr !== '') {
- code.appendFormat(', level=[{0}])', selectedStr);
+ code.appendFormat(', level=[{0}]', selectedStr);
}
code.append(', inplace=True)');
break;
@@ -2096,8 +2417,33 @@ define([
}
var name = com_util.convertToStr(content.name, content.nameastext);
name = selectedName;
- var value = com_util.convertToStr(content.value, content.valueastext);
- code.appendFormat("{0} = {1}", content.subset, value);
+ var tab = content.replacetype;
+ if (tab === 'value') {
+ var replaceStr = new com_String();
+ var useRegex = content['useregex'];
+ content['list'].forEach((obj, idx) => {
+ if (idx == 0) {
+ replaceStr.appendFormat("{0}: {1}"
+ , com_util.convertToStr(obj.origin, obj.origintext, useRegex)
+ , com_util.convertToStr(obj.replace, obj.replacetext, useRegex));
+ } else {
+ replaceStr.appendFormat(", {0}: {1}"
+ , com_util.convertToStr(obj.origin, obj.origintext, useRegex)
+ , com_util.convertToStr(obj.replace, obj.replacetext, useRegex));
+ }
+ });
+ if (selectedName && selectedName != '') {
+ selectedName = '[[' + selectedName + ']]';
+ }
+ code.appendFormat("{0}[{1}] = {2}{3}.replace({{4}}", tempObj, name, tempObj, selectedName, replaceStr);
+ if (useRegex) {
+ code.append(', regex=True');
+ }
+ code.append(')');
+ } else if (tab === 'condition') {
+ var value = com_util.convertToStr(content.value, content.valueastext);
+ code.appendFormat("{0} = {1}", content.subset, value);
+ }
break;
case FRAME_EDIT_TYPE.AS_TYPE:
var astypeStr = new com_String();
@@ -2144,9 +2490,11 @@ define([
code.append(')');
break;
case FRAME_EDIT_TYPE.FILL_NA:
- code.appendFormat("{0} = {1}.fillna({2}", subsetObjStr, subsetObjStr, com_util.convertToStr(content['value'], content['valueastext']));
- if (content['method'] && content['method'] !== '') {
- code.appendFormat(", method='{0}'", content['method']);
+ code.appendFormat("{0} = {1}.fillna(", subsetObjStr, subsetObjStr);
+ if (content['method'] == 'value') {
+ code.append(com_util.convertToStr(content['value'], content['valueastext']));
+ } else {
+ code.appendFormat("method='{0}'", content['method']);
if (content['limit'] && content['limit'] !== '') {
code.appendFormat(", limit={0}", content['limit']);
}
@@ -2239,9 +2587,9 @@ define([
// add column
// LAB: img to url
// table.appendFormatLine('  | ', VP_FE_ADD_COLUMN, com_Const.IMAGE_PATH + 'plus.svg');
- if (colLevIdx === 0) {
- table.appendFormatLine(' | ', VP_FE_ADD_COLUMN, 'vp-icon-plus');
- }
+ // if (colLevIdx === 0) {
+ // table.appendFormatLine(' | ', VP_FE_ADD_COLUMN, 'vp-icon-plus');
+ // }
table.appendLine(' | ');
}
@@ -2256,8 +2604,8 @@ define([
table.appendFormatLine('{6} | '
, colCode, FRAME_AXIS.COLUMN, col.type, col.label, VP_FE_TABLE_COLUMN, colClass, col.label);
});
- // add column
- table.appendFormatLine(' | ', VP_FE_ADD_COLUMN, 'vp-icon-plus');
+ // // add column
+ // table.appendFormatLine(' | ', VP_FE_ADD_COLUMN, 'vp-icon-plus');
table.appendLine('');
}
@@ -2291,7 +2639,7 @@ define([
table.appendLine('');
// LAB: img to url
// table.appendFormatLine(' | ', VP_FE_ADD_ROW, com_Const.IMAGE_PATH + 'plus.svg');
- table.appendFormatLine(' | ', VP_FE_ADD_ROW, 'vp-icon-plus');
+ // table.appendFormatLine(' | ', VP_FE_ADD_ROW, 'vp-icon-plus');
table.appendLine(' ');
table.appendLine('');
$(that.wrapSelector('.' + VP_FE_TABLE)).replaceWith(function() {
diff --git a/visualpython/js/m_apps/Groupby.js b/visualpython/js/m_apps/Groupby.js
index ddc20307..d1aff5d4 100644
--- a/visualpython/js/m_apps/Groupby.js
+++ b/visualpython/js/m_apps/Groupby.js
@@ -514,7 +514,7 @@ define([
renderDataPage(renderedText, isHtml = true) {
var tag = new com_String();
- tag.appendFormatLine('', 'rendered_html'); // 'rendered_html' style from jupyter output area
+ tag.appendFormatLine(' ', 'vp_rendered_html'); // 'rendered_html' style from jupyter output area
if (isHtml) {
tag.appendLine(renderedText);
} else {
diff --git a/visualpython/js/m_apps/Information.js b/visualpython/js/m_apps/Information.js
index a387e704..28024e95 100644
--- a/visualpython/js/m_apps/Information.js
+++ b/visualpython/js/m_apps/Information.js
@@ -18,8 +18,9 @@ define([
'vp_base/js/com/com_String',
'vp_base/js/com/com_util',
'vp_base/js/com/component/PopupComponent',
- 'vp_base/js/com/component/DataSelector'
-], function(varHtml, varCss, com_String, com_util, PopupComponent, DataSelector) {
+ 'vp_base/js/com/component/DataSelector',
+ 'vp_base/js/com/component/LoadingSpinner'
+], function(varHtml, varCss, com_String, com_util, PopupComponent, DataSelector, LoadingSpinner) {
/**
* Information
@@ -44,6 +45,11 @@ define([
start: -1,
end: -1
},
+ columnLevel: 1,
+ columnList: [],
+ indexLevel: 1,
+ indexList: [],
+ lines: TABLE_LINES,
...this.state
}
@@ -65,7 +71,7 @@ define([
dtype: ['DataFrame', 'Series'],
child: [
{ id: 'null_count', label: 'Null count',
- code: "pd.DataFrame({'Null Count': ${data}.isnull().sum(), 'Non-Null Count': ${data}.notnull().sum()})", dtype: ['DataFrame', 'Series'] },
+ code: "pd.DataFrame({'Null Count': ${data}.isnull().sum(), 'Non-Null Count': ${data}.notnull().sum()})", dtype: ['DataFrame', 'Series'], toframe: true },
// { id: 'duplicates', label: 'Duplicated', code: '${data}.duplicated()', dtype: ['DataFrame', 'Series'] },
{ id: 'duplicates', label: 'Duplicated', code: "_duplicated = ([${data}.duplicated().sum()] + [${data}[col].duplicated().sum() for col in ${data}.columns])\
\n_duplicated_df = pd.DataFrame({\
@@ -87,8 +93,6 @@ define([
{ id: 'count', label: 'count', code: '${data}.count()' },
{ id: 'min', label: 'min', code: '${data}.min()' },
{ id: 'max', label: 'max', code: '${data}.max()' },
- { id: 'argmin', label: 'min', code: '${data}.argmin()' },
- { id: 'argmax', label: 'max', code: '${data}.argmax()' },
{ id: 'quantile', label: 'quantile', code: '${data}.quantile(numeric_only=True)' },
{ id: 'sum', label: 'sum', code: '${data}.sum()' },
{ id: 'mean', label: 'mean', code: '${data}.mean(numeric_only=True)' },
@@ -129,7 +133,9 @@ define([
]
}
- ]
+ ];
+
+ this.loading = false;
}
_unbindEvent() {
@@ -147,24 +153,24 @@ define([
// change data
$(this.wrapSelector('#data')).on('change', function() {
let val = $(this).val();
- if (val === '') {
- that.handleChangeData('');
- }
});
// un-select every selection
- $(document).on('click', this.wrapSelector('.vp-popup-body'), function(evt) {
+ $(document).on('click', this.wrapSelector('.vp-variable-table'), function(evt) {
evt.stopPropagation();
var target = evt.target;
// if(!$(target).is("input") && !$(target).is("label")) {
- if ($('.vp-dropdown-content').find(target).length == 0
- && !$(target).hasClass('vp-dropdown-content') ) {
- $(that.wrapSelector('.vp-variable-preview thead th')).removeClass('selected');
-
- // load menu
- that.renderMenu();
- // load info
- that.loadInfo();
+ if (that.state.selected.length > 0) {
+ if ($('.vp-dropdown-content').find(target).length == 0
+ && !$(target).hasClass('vp-dropdown-content') ) {
+ $(that.wrapSelector('.vp-variable-table thead th')).removeClass('selected');
+ that.state.selected = [];
+
+ // load menu
+ that.renderMenu();
+ // load info
+ that.loadInfo();
+ }
}
});
@@ -193,7 +199,12 @@ define([
});
// add selection
$(that.wrapSelector('.vp-information-menu')).removeClass('selected');
- $(that.wrapSelector('.vp-information-menu[data-menu="statistics"]')).addClass('selected');
+ if (that.state.menuItem.length > 0) {
+ $(that.wrapSelector('.vp-information-menu[data-menu="statistics"]')).addClass('selected');
+ } else {
+ // all selection removed from statistics
+ that.state.menu = '';
+ }
} else {
that.state.menu = menuParent;
that.state.menuItem = [ menuId ];
@@ -209,6 +220,165 @@ define([
}
});
+ // column group selection
+ // select column group
+ $(document).on('click', this.wrapSelector('.' + VP_FE_TABLE + ' .' + VP_FE_TABLE_COLUMN_GROUP), function(evt) {
+ evt.stopPropagation();
+
+ let hasSelected = $(this).hasClass('selected');
+ let colLabel = $(this).data('label');
+ let firstIdx = $(that.wrapSelector(`.${VP_FE_TABLE} th[data-parent="${colLabel}"]:first`)).index();
+ let lastIdx = $(that.wrapSelector(`.${VP_FE_TABLE} th[data-parent="${colLabel}"]:last`)).index();
+ if (firstIdx === lastIdx) {
+ lastIdx = -1;
+ }
+
+ $(that.wrapSelector('.' + VP_FE_TABLE + ' .' + VP_FE_TABLE_ROW)).removeClass('selected');
+
+ if (vpEvent.keyManager.keyCheck.ctrlKey) {
+ if (!hasSelected) {
+ that.state.selection = { start: firstIdx, end: -1 };
+ $(this).addClass('selected');
+ $(that.wrapSelector(`.${VP_FE_TABLE} th[data-parent="${colLabel}"]`)).addClass('selected');
+ } else {
+ $(this).removeClass('selected');
+ $(that.wrapSelector(`.${VP_FE_TABLE} th[data-parent="${colLabel}"]`)).removeClass('selected');
+ }
+ } else if (vpEvent.keyManager.keyCheck.shiftKey) {
+ var startIdx = that.state.selection.start;
+
+ if (startIdx == -1) {
+ // no selection
+ that.state.selection = { start: firstIdx, end: -1 };
+ } else if (startIdx > firstIdx) {
+ // add selection from idx to startIdx
+ var tags = $(that.wrapSelector('.' + VP_FE_TABLE_COLUMN));
+ let parentSet = new Set();
+ for (var i = firstIdx - 1; i <= startIdx; i++) {
+ $(tags[i]).addClass('selected');
+ parentSet.add($(tags[i]).data('parent'));
+ }
+ parentSet.forEach(parentKey => {
+ let length = $(that.wrapSelector(`.${VP_FE_TABLE} th[data-parent="${parentKey}"]`)).length;
+ let selectedLength = $(that.wrapSelector(`.${VP_FE_TABLE} th.selected[data-parent="${parentKey}"]`)).length;
+ if (length === selectedLength) {
+ $(that.wrapSelector(`.${VP_FE_TABLE} th[data-label="${parentKey}"]`)).addClass('selected');
+ } else {
+ $(that.wrapSelector(`.${VP_FE_TABLE} th[data-label="${parentKey}"]`)).removeClass('selected');
+ }
+ });
+ that.state.selection = { start: startIdx, end: firstIdx };
+ } else if (startIdx <= firstIdx) {
+ // add selection from startIdx to idx
+ var tags = $(that.wrapSelector('.' + VP_FE_TABLE_COLUMN));
+ let parentSet = new Set();
+ for (var i = startIdx; i < lastIdx; i++) {
+ $(tags[i]).addClass('selected');
+ parentSet.add($(tags[i]).data('parent'));
+ }
+ parentSet.forEach(parentKey => {
+ let length = $(that.wrapSelector(`.${VP_FE_TABLE} th[data-parent="${parentKey}"]`)).length;
+ let selectedLength = $(that.wrapSelector(`.${VP_FE_TABLE} th.selected[data-parent="${parentKey}"]`)).length;
+ if (length === selectedLength) {
+ $(that.wrapSelector(`.${VP_FE_TABLE} th[data-label="${parentKey}"]`)).addClass('selected');
+ } else {
+ $(that.wrapSelector(`.${VP_FE_TABLE} th[data-label="${parentKey}"]`)).removeClass('selected');
+ }
+ });
+ that.state.selection = { start: startIdx, end: lastIdx };
+ }
+ } else {
+ $(that.wrapSelector('.' + VP_FE_TABLE + ' .' + VP_FE_TABLE_COLUMN)).removeClass('selected');
+ $(that.wrapSelector('.' + VP_FE_TABLE + ' .' + VP_FE_TABLE_COLUMN_GROUP)).removeClass('selected');
+
+ $(this).addClass('selected');
+ $(that.wrapSelector(`.${VP_FE_TABLE} th[data-parent="${colLabel}"]`)).addClass('selected');
+ that.state.selection = { start: firstIdx, end: lastIdx };
+ }
+ var selected = [];
+ $(that.wrapSelector(`.${VP_FE_TABLE} th:not(.${VP_FE_TABLE_COLUMN_GROUP}).selected`)).each((idx, tag) => {
+ var label = $(tag).text();
+ var code = $(tag).data('code');
+ var type = $(tag).data('type');
+ selected.push({ label: label, code: code, type: type });
+ });
+ that.state.selected = selected;
+
+ // load info
+ that.renderMenu();
+ that.loadInfo();
+ });
+
+ // column selection
+ // select column
+ $(document).on('click', this.wrapSelector('.' + VP_FE_TABLE + ' .' + VP_FE_TABLE_COLUMN), function(evt) {
+ evt.stopPropagation();
+
+ var idx = $(that.wrapSelector('.' + VP_FE_TABLE_COLUMN)).index(this); // 1 ~ n
+ var hasSelected = $(this).hasClass('selected');
+
+ $(that.wrapSelector('.' + VP_FE_TABLE + ' .' + VP_FE_TABLE_ROW)).removeClass('selected');
+
+ if (vpEvent.keyManager.keyCheck.ctrlKey) {
+ if (!hasSelected) {
+ that.state.selection = { start: idx, end: -1 };
+ $(this).addClass('selected');
+ } else {
+ $(this).removeClass('selected');
+ }
+
+ } else if (vpEvent.keyManager.keyCheck.shiftKey) {
+ var startIdx = that.state.selection.start;
+
+ if (startIdx == -1) {
+ // no selection
+ that.state.selection = { start: idx, end: -1 };
+ } else if (startIdx > idx) {
+ // add selection from idx to startIdx
+ var tags = $(that.wrapSelector('.' + VP_FE_TABLE_COLUMN));
+ for (var i = idx; i <= startIdx; i++) {
+ $(tags[i]).addClass('selected');
+ }
+ that.state.selection = { start: startIdx, end: idx };
+ } else if (startIdx <= idx) {
+ // add selection from startIdx to idx
+ var tags = $(that.wrapSelector('.' + VP_FE_TABLE_COLUMN));
+ for (var i = startIdx; i <= idx; i++) {
+ $(tags[i]).addClass('selected');
+ }
+ that.state.selection = { start: startIdx, end: idx };
+ }
+ } else {
+ $(that.wrapSelector('.' + VP_FE_TABLE + ' .' + VP_FE_TABLE_COLUMN)).removeClass('selected');
+ $(that.wrapSelector('.' + VP_FE_TABLE + ' .' + VP_FE_TABLE_COLUMN_GROUP)).removeClass('selected');
+
+ $(this).addClass('selected');
+ that.state.selection = { start: idx, end: -1 };
+ }
+ // select its group
+ $(that.wrapSelector(`.${VP_FE_TABLE} th[data-label="${$(this).data('parent')}"]`)).addClass('selected');
+
+ var selected = [];
+ $(that.wrapSelector(`.${VP_FE_TABLE} th:not(.${VP_FE_TABLE_COLUMN_GROUP}).selected`)).each((idx, tag) => {
+ var label = $(tag).text();
+ var code = $(tag).data('code');
+ var type = $(tag).data('type');
+ selected.push({ label: label, code: code, type: type });
+ });
+ that.state.selected = selected;
+
+ // load info
+ that.renderMenu();
+ that.loadInfo();
+ });
+
+ // click more button for more rows
+ $(document).on('click', this.wrapSelector('.' + VP_FE_TABLE_MORE), function() {
+ that.state.lines += TABLE_LINES;
+ that.loadCode(that.state.data, true);
+ });
+
+
// click run button
$(this.wrapSelector('.vp-information-run-button')).click(function(event) {
// get code
@@ -232,7 +402,7 @@ define([
this.state.selected = [];
this.state.selection = { start: -1, end: -1 };
this.renderMenu();
- this.loadPreview(data);
+ this.loadCode(data);
this.loadInfo(data, this.state.menu);
}
@@ -305,6 +475,13 @@ define([
let { id, label, dtype } = itemObj;
let enabled = dtype.includes(currentDtype);
let selected = that.state.menuItem.includes(id);
+ if (enabled === false && selected === true) {
+ // if disabled menu is selected, remove selection
+ $menu.find('.vp-information-menu').removeClass('selected');
+ selected = false;
+ that.state.menu = '';
+ that.state.menuItem = [];
+ }
// disable item depends on dtype
$menu.find('.vp-dropdown-content')
.append($(``));
@@ -314,13 +491,30 @@ define([
});
}
+ renderTable(renderedText, isHtml=true) {
+ var tag = new com_String();
+ // Table
+ tag.appendFormatLine(' ', VP_FE_TABLE, 'vp_rendered_html', 'vp-scrollbar');
+ if (isHtml) {
+ tag.appendFormatLine(' ', renderedText);
+ // More button
+ tag.appendFormatLine(' Show more ', VP_FE_TABLE_MORE, 'vp-button');
+ } else {
+ tag.appendFormatLine(' {0} ', renderedText);
+ }
+ tag.appendLine(' '); // End of Table
+ return tag.toString();
+ }
+
generateCode() {
let { data, dtype, menu, menuItem } = this.state;
var selected = [];
- $(this.wrapSelector('.vp-variable-preview thead th.selected')).each((idx, tag) => {
+ $(this.wrapSelector(`.${VP_FE_TABLE} th:not(.${VP_FE_TABLE_COLUMN_GROUP}).selected`)).each((idx, tag) => {
var label = $(tag).text();
- selected.push("'" + label + "'"); // FIXME: get data columns and use its code
+ var code = $(tag).data('code');
+ var type = $(tag).data('type');
+ selected.push({ label: label, code: code, type: type });
});
this.state.selected = selected;
@@ -331,11 +525,11 @@ define([
if (selected.length > 0) {
if (selected.length == 1) {
// series
- dataVar.appendFormat("[{0}]", selected[0]);
+ dataVar.appendFormat("[{0}]", selected[0].code);
currentDtype = 'Series';
} else {
// dataframe
- dataVar.appendFormat("[[{0}]]", selected.join(','));
+ dataVar.appendFormat("[[{0}]]", selected.map(col=>col.code).join(','));
}
}
}
@@ -358,7 +552,7 @@ define([
if (currentDtype === 'Series') {
// if multiple stats selected, set series data as dataframe
dataVar = new com_String();
- dataVar.appendFormat("{0}[[{1}]]", data, selected.join(','));
+ dataVar.appendFormat("{0}[[{1}]]", data, selected.map(col=>col.code).join(','));
currentDtype = 'DataFrame';
}
codePattern = com_util.formatString("pd.DataFrame({{0}})", statList.join(','));
@@ -375,7 +569,7 @@ define([
let childObj = infoObj.child.find(obj=>obj.id === menuItem[0]);
if (childObj.toframe === true && currentDtype === 'Series') {
dataVar = new com_String();
- dataVar.appendFormat("{0}[[{1}]]", data, selected.join(','));
+ dataVar.appendFormat("{0}[[{1}]]", data, selected.map(col=>col.code).join(','));
currentDtype = 'DataFrame';
}
codePattern = childObj.code;
@@ -389,112 +583,193 @@ define([
let code = codePattern.replaceAll('${data}', dataVar.toString());
return code;
}
- } else if (currentDtype == 'DataFrame') {
- // if dtype is dataframe, show describe + info preview
- let codePattern = "_desc = ${data}.describe().T\
- \n_info = pd.DataFrame({'Non-Null Count': ${data}.notnull().sum(), 'Dtype': ${data}.dtypes})\
- \ndisplay(pd.concat([_info, _desc], axis=1).fillna(''))";
-
- let code = codePattern.replaceAll('${data}', dataVar.toString());
- return code;
- }
+ }
+ // else if (currentDtype == 'DataFrame') {
+ // // if dtype is dataframe, show describe + info preview
+ // let codePattern = "_desc = ${data}.describe().T\
+ // \n_info = pd.DataFrame({'Non-Null Count': ${data}.notnull().sum(), 'Dtype': ${data}.dtypes})\
+ // \ndisplay(pd.concat([_info, _desc], axis=1).fillna(''))";
+
+ // let code = codePattern.replaceAll('${data}', dataVar.toString());
+ // return code;
+ // }
// add ignore options TODO:
// let ignoreCode = `import warnings\
// \nwith warnings.catch_warnings():
// \n warnings.simplefilter("ignore")\n`;
- return dataVar.toString();
+ return `display(${dataVar.toString()})`;
}
- loadPreview(data) {
- let that = this;
- let variablePreviewTag = $(this.wrapSelector('#variablePreview'));
- $(variablePreviewTag).html('');
- // show variable information on clicking variable
- vpKernel.execute(data).then(function(resultObj) {
- let { result, type, msg } = resultObj;
- if (msg.content.data) {
- var textResult = msg.content.data["text/plain"];
- var htmlResult = msg.content.data["text/html"];
- var imgResult = msg.content.data["image/png"];
-
- if (htmlResult != undefined) {
- // 1. HTML tag
- $(variablePreviewTag).append(htmlResult);
- } else if (imgResult != undefined) {
- // 2. Image data (base64)
- var imgTag = '  ';
- $(variablePreviewTag).append(imgTag);
- } else if (textResult != undefined) {
- // 3. Text data
- var preTag = document.createElement('pre');
- $(preTag).text(textResult);
- $(variablePreviewTag).html(preTag);
- } else {
- $(variablePreviewTag).append('(Select data to preview.)');
+ loadCode(codeStr, more=false) {
+ if (this.loading) {
+ return;
+ }
+
+ var that = this;
+ let { data, lines, indexList } = this.state;
+ var prevLines = 0;
+ var scrollPos = -1;
+ if (more) {
+ prevLines = indexList.length;
+ scrollPos = $(this.wrapSelector('.vp-variable-table')).scrollTop();
+ }
+
+ var code = new com_String();
+ code.appendLine(codeStr);
+ code.appendFormat("{0}.iloc[{1}:{2}].to_json(orient='{3}')", data, prevLines, lines, 'split');
+
+ this.loading = true;
+ vpKernel.execute(code.toString()).then(function(resultObj) {
+ let { result } = resultObj;
+ try {
+ if (!result || result.length <= 0) {
+ return;
}
+ result = result.substr(1,result.length - 2).replaceAll('\\\\', '\\');
+ result = result.replaceAll('\'', "\\'"); // TEST: need test
+ // result = result.replaceAll('\\"', "\"");
+ var dataJson = JSON.parse(result);
- // add event listener for columns
- $(that.wrapSelector('.vp-variable-preview thead th')).click(function(evt) {
- evt.stopPropagation();
- let col = $(this).text();
-
- var idx = $(that.wrapSelector('.vp-variable-preview thead th')).index(this); // 1 ~ n
- var hasSelected = $(this).hasClass('selected');
-
- if (vpEvent.keyManager.keyCheck.ctrlKey) {
- if (!hasSelected) {
- that.state.selection = { start: idx, end: -1 };
- $(this).addClass('selected');
- } else {
- $(this).removeClass('selected');
- }
-
- } else if (vpEvent.keyManager.keyCheck.shiftKey) {
- var startIdx = that.state.selection.start;
-
- if (startIdx == -1) {
- // no selection
- that.state.selection = { start: idx, end: -1 };
- } else if (startIdx > idx) {
- // add selection from idx to startIdx
- var tags = $(that.wrapSelector('.vp-variable-preview thead th'));
- for (var i = idx; i <= startIdx; i++) {
- $(tags[i]).addClass('selected');
- }
- that.state.selection = { start: startIdx, end: idx };
- } else if (startIdx <= idx) {
- // add selection from startIdx to idx
- var tags = $(that.wrapSelector('.vp-variable-preview thead th'));
- for (var i = startIdx; i <= idx; i++) {
- $(tags[i]).addClass('selected');
+ vpKernel.getColumnList(data).then(function(colResObj) {
+ try {
+ let columnResult = colResObj.result;
+ var columnInfo = JSON.parse(columnResult);
+ let { name:columnName='', level:columnLevel, list:columnList } = columnInfo;
+ // var columnList = data.columns;
+ var indexList = dataJson.index;
+ var dataList = dataJson.data;
+
+ columnList = columnList.map(col => { return { label: col.label, type: col.dtype, code: col.value } });
+ indexList = indexList.map(idx => { return { label: idx, code: idx } });
+
+ if (!more) {
+ // table
+ var table = new com_String();
+ // table.appendFormatLine(' ', 1, 'dataframe');
+ table.appendLine('');
+ if (columnLevel > 1) {
+ for (let colLevIdx = 0; colLevIdx < columnLevel; colLevIdx++) {
+ table.appendLine(' | ');
+ let colIdx = 0;
+ let colSpan = 1;
+ while (colIdx < columnList.length) {
+ let col = columnList[colIdx];
+ let colCode = col.code.slice(0, colLevIdx + 1).join(',');
+ let nextCol = columnList[colIdx + 1];
+ if (nextCol && nextCol.code.slice(0, colLevIdx + 1).join(',') === colCode) {
+ colSpan++;
+ } else {
+ let colClass = '';
+ let selected = ''; // set class if it's leaf node of columns on multi-level
+ if (that.state.selected.map(col=>col.code[colLevIdx]).includes(colCode)) {
+ selected = 'selected';
+ }
+ if ((columnLevel - 1) === colLevIdx) {
+ colClass = VP_FE_TABLE_COLUMN;
+ } else {
+ colClass = VP_FE_TABLE_COLUMN_GROUP;
+ }
+ table.appendFormatLine('{8} | '
+ , colCode, FRAME_AXIS.COLUMN, col.type, col.label[colLevIdx-1], col.label[colLevIdx], colClass, selected, colSpan, col.label[colLevIdx]);
+ colSpan = 1;
+ }
+ colIdx++;
+ }
+
+ table.appendLine(' ');
+ }
+ } else {
+ table.appendLine(' | ');
+ columnList && columnList.forEach(col => {
+ var colCode = col.code;
+ var colClass = '';
+ if (that.state.selected.map(col=>col.code).includes(colCode)) {
+ colClass = 'selected';
+ }
+ table.appendFormatLine('{6} | '
+ , colCode, FRAME_AXIS.COLUMN, col.type, col.label, VP_FE_TABLE_COLUMN, colClass, col.label);
+ });
+ table.appendLine(' ');
}
- that.state.selection = { start: startIdx, end: idx };
+ table.appendLine('');
+ table.appendLine('');
+
+ dataList && dataList.forEach((row, idx) => {
+ table.appendLine('');
+ var idxName = indexList[idx].label;
+ var idxLabel = com_util.convertToStr(idxName, typeof idxName == 'string');
+ var idxClass = '';
+ table.appendFormatLine('{4} | ', idxLabel, FRAME_AXIS.ROW, VP_FE_TABLE_ROW, idxClass, idxName);
+ row.forEach((cell, colIdx) => {
+ if (cell == null) {
+ cell = 'NaN';
+ }
+ var cellType = columnList[colIdx].type;
+ if (cellType.includes('datetime')) {
+ cell = new Date(parseInt(cell)).toLocaleString();
+ }
+ table.appendFormatLine('{0} | ', cell);
+ });
+ table.appendLine(' ');
+ });
+ // add row
+ table.appendLine('');
+ table.appendLine(' ');
+ table.appendLine('');
+ $(that.wrapSelector('.' + VP_FE_TABLE)).replaceWith(function() {
+ return that.renderTable(table.toString());
+ });
+ } else {
+ var table = new com_String();
+ dataList && dataList.forEach((row, idx) => {
+ table.appendLine('');
+ var idxName = indexList[idx].label;
+ var idxLabel = com_util.convertToStr(idxName, typeof idxName == 'string');
+ var idxClass = '';
+ table.appendFormatLine('{4} | ', idxLabel, FRAME_AXIS.ROW, VP_FE_TABLE_ROW, idxClass, idxName);
+ row.forEach((cell, colIdx) => {
+ if (cell == null) {
+ cell = 'NaN';
+ }
+ var cellType = columnList[colIdx].type;
+ if (cellType.includes('datetime')) {
+ cell = new Date(parseInt(cell)).toLocaleString();
+ }
+ table.appendFormatLine('{0} | ', cell);
+ });
+ table.appendLine(' ');
+ });
+ // insert before last tr tag(add row button)
+ $(table.toString()).insertBefore($(that.wrapSelector('.' + VP_FE_TABLE + ' tbody tr:last')));
}
- } else {
- $(that.wrapSelector('.vp-variable-preview thead th')).removeClass('selected');
- if (!hasSelected) {
- $(this).addClass('selected');
- that.state.selection = { start: idx, end: -1 };
+
+ // save columnList & indexList as state
+ that.state.columnLevel = columnLevel;
+ that.state.columnList = columnList;
+ if (!more) {
+ that.state.indexList = indexList;
} else {
- $(this).removeClass('selected');
+ that.state.indexList = that.state.indexList.concat(indexList);
+ }
+
+ // if scrollPos is saved, go to the position
+ if (scrollPos >= 0) {
+ $(that.wrapSelector('.vp-variable-table')).scrollTop(scrollPos);
}
+
+ that.loading = false;
+ } catch (err1) {
+ vpLog.display(VP_LOG_TYPE.ERROR, err1);
+ that.loading = false;
+ throw err1;
}
-
- // load info
- that.renderMenu();
- that.loadInfo();
});
- } else {
- var errorContent = '';
- if (msg.content.ename) {
- errorContent = com_util.templateForErrorBox(msg.content.ename, msg.content.evalue, msg.content.detail);
- }
- $(variablePreviewTag).html(errorContent);
- vpLog.display(VP_LOG_TYPE.ERROR, msg.content.ename, msg.content.evalue, msg.content);
+ } catch (err) {
+ vpLog.display(VP_LOG_TYPE.ERROR, err);
+ that.loading = false;
}
-
}).catch(function(resultObj) {
let { msg } = resultObj;
var errorContent = '';
@@ -503,9 +778,15 @@ define([
}
$(variablePreviewTag).html(errorContent);
vpLog.display(VP_LOG_TYPE.ERROR, msg.content.ename, msg.content.evalue, msg.content);
+ that.loading = false;
});
+
+ return code.toString();
}
+ /**
+ * Load information preview
+ */
loadInfo() {
let that = this;
let { menu, menuItem } = this.state;
@@ -523,6 +804,12 @@ define([
$infoPreviewTag.html('');
let code = this.generateCode();
+ // use default pandas option
+ // let defaultPOCode = new com_String();
+ // defaultPOCode.appendLine("with pd.option_context('display.min_rows', 10, 'display.max_rows', 60, 'display.max_columns', 0, 'display.max_colwidth', 50, 'display.expand_frame_repr', True, 'display.precision', 6, 'display.chop_threshold', None):");
+ // defaultPOCode.append(' ' + code.replaceAll('\n', '\n '));
+
+ let loadingSpinner = new LoadingSpinner($(this.wrapSelector('#informationPreview')));
// show variable information on clicking variable
vpKernel.execute(code).then(function(resultObj) {
let { result, type, msg } = resultObj;
@@ -551,7 +838,6 @@ define([
$infoPreviewTag.html(errorContent);
vpLog.display(VP_LOG_TYPE.ERROR, msg.content.ename, msg.content.evalue, msg.content);
}
-
}).catch(function(resultObj) {
let { msg } = resultObj;
var errorContent = '';
@@ -560,9 +846,26 @@ define([
}
$infoPreviewTag.html(errorContent);
vpLog.display(VP_LOG_TYPE.ERROR, msg.content.ename, msg.content.evalue, msg.content);
+ }).finally(function() {
+ loadingSpinner.remove();
});
}
}
+ // search rows count at once
+ const TABLE_LINES = 10;
+
+ const VP_FE_TABLE = 'vp-variable-table';
+ const VP_FE_TABLE_COLUMN = 'vp-variable-table-column';
+ const VP_FE_TABLE_COLUMN_GROUP = 'vp-variable-table-column-group';
+ const VP_FE_TABLE_ROW = 'vp-variable-table-row';
+ const VP_FE_TABLE_MORE = 'vp-variable-table-more';
+
+ const FRAME_AXIS = {
+ NONE: -1,
+ ROW: 0,
+ COLUMN: 1
+ }
+
return Information;
});
\ No newline at end of file
diff --git a/visualpython/js/m_apps/Reshape.js b/visualpython/js/m_apps/Reshape.js
index 8628ac46..022739a3 100644
--- a/visualpython/js/m_apps/Reshape.js
+++ b/visualpython/js/m_apps/Reshape.js
@@ -219,7 +219,9 @@ define([
// reset index checkbox event
$(document).on('change', this.wrapSelector('#vp_rsResetIndex'), function() {
- that.state.resetIndex = $(this).prop('checked');
+ let isChecked = $(this).prop('checked');
+ $(that.wrapSelector('#vp_rsWithoutColumn')).prop('disabled', !isChecked);
+ that.state.resetIndex = isChecked;
});
// with/without column select event
@@ -246,7 +248,7 @@ define([
renderDataPage(renderedText, isHtml = true) {
var tag = new com_String();
- tag.appendFormatLine('', 'rendered_html'); // 'rendered_html' style from jupyter output area
+ tag.appendFormatLine(' ', 'vp_rendered_html'); // 'rendered_html' style from jupyter output area
if (isHtml) {
tag.appendLine(renderedText);
} else {
diff --git a/visualpython/js/m_apps/Subset.js b/visualpython/js/m_apps/Subset.js
index e9e2a094..a6272232 100644
--- a/visualpython/js/m_apps/Subset.js
+++ b/visualpython/js/m_apps/Subset.js
@@ -162,7 +162,7 @@ define([
VP_DS_DATA_VIEW_ALL_DIV, VP_DS_DATA_VIEW_ALL, (this.state.viewAll?'checked':''), "view all");
// data view
tag.appendFormatLine(' ', VP_DS_DATA_VIEW_BOX,
- 'rendered_html'); // 'rendered_html' style from jupyter output area
+ 'vp_rendered_html'); // 'rendered_html' style from jupyter output area
return tag.toString();
}
getAllowSubsetTypes() {
diff --git a/visualpython/js/m_stats/EqualVarTest.js b/visualpython/js/m_stats/EqualVarTest.js
new file mode 100644
index 00000000..3fe50bb9
--- /dev/null
+++ b/visualpython/js/m_stats/EqualVarTest.js
@@ -0,0 +1,65 @@
+/*
+ * Project Name : Visual Python
+ * Description : GUI-based Python code generator
+ * File Name : EqualVarTest.js
+ * Author : Black Logic
+ * Note : Equal Variance Test
+ * License : GNU GPLv3 with Visual Python special exception
+ * Date : 2023. 05. 09
+ * Change Date :
+ */
+
+//============================================================================
+// [CLASS] EqualVarTest
+//============================================================================
+define([
+ 'vp_base/js/com/com_util',
+ 'vp_base/js/com/com_Const',
+ 'vp_base/js/com/com_String',
+ 'vp_base/js/com/component/PopupComponent',
+ 'vp_base/js/com/component/DataSelector'
+], function(com_util, com_Const, com_String, PopupComponent, DataSelector) {
+
+ /**
+ * EqualVarTest
+ */
+ class EqualVarTest extends PopupComponent {
+ _init() {
+ super._init();
+ /** Write codes executed before rendering */
+ }
+
+ _bindEvent() {
+ super._bindEvent();
+ /** Implement binding events */
+ var that = this;
+ }
+
+ templateForBody() {
+ /** Implement generating template */
+ return `This is sample.
+ `;
+ }
+
+ render() {
+ super.render();
+
+ let dataSelector = new DataSelector({
+ type: 'data',
+ pageThis: this,
+ id: 'sample',
+ finish: function() {
+ ;
+ }
+ });
+ $(this.wrapSelector('#sample')).replaceWith(dataSelector.toTagString());
+ }
+
+ generateCode() {
+ return "print('sample code')";
+ }
+
+ }
+
+ return EqualVarTest;
+});
\ No newline at end of file
diff --git a/visualpython/js/m_stats/NormTest.js b/visualpython/js/m_stats/NormTest.js
new file mode 100644
index 00000000..ebb9dc74
--- /dev/null
+++ b/visualpython/js/m_stats/NormTest.js
@@ -0,0 +1,65 @@
+/*
+ * Project Name : Visual Python
+ * Description : GUI-based Python code generator
+ * File Name : NormTest.js
+ * Author : Black Logic
+ * Note : Norm test
+ * License : GNU GPLv3 with Visual Python special exception
+ * Date : 2023. 05. 09
+ * Change Date :
+ */
+
+//============================================================================
+// [CLASS] NormTest
+//============================================================================
+define([
+ 'vp_base/js/com/com_util',
+ 'vp_base/js/com/com_Const',
+ 'vp_base/js/com/com_String',
+ 'vp_base/js/com/component/PopupComponent',
+ 'vp_base/js/com/component/DataSelector'
+], function(com_util, com_Const, com_String, PopupComponent, DataSelector) {
+
+ /**
+ * NormTest
+ */
+ class NormTest extends PopupComponent {
+ _init() {
+ super._init();
+ /** Write codes executed before rendering */
+ }
+
+ _bindEvent() {
+ super._bindEvent();
+ /** Implement binding events */
+ var that = this;
+ }
+
+ templateForBody() {
+ /** Implement generating template */
+ return `This is sample.
+ `;
+ }
+
+ render() {
+ super.render();
+
+ let dataSelector = new DataSelector({
+ type: 'data',
+ pageThis: this,
+ id: 'sample',
+ finish: function() {
+ ;
+ }
+ });
+ $(this.wrapSelector('#sample')).replaceWith(dataSelector.toTagString());
+ }
+
+ generateCode() {
+ return "print('sample code')";
+ }
+
+ }
+
+ return NormTest;
+});
\ No newline at end of file
diff --git a/visualpython/js/m_stats/ProbDist.js b/visualpython/js/m_stats/ProbDist.js
new file mode 100644
index 00000000..e89b8c9c
--- /dev/null
+++ b/visualpython/js/m_stats/ProbDist.js
@@ -0,0 +1,65 @@
+/*
+ * Project Name : Visual Python
+ * Description : GUI-based Python code generator
+ * File Name : ProbDist.js
+ * Author : Black Logic
+ * Note : Probability Distribution
+ * License : GNU GPLv3 with Visual Python special exception
+ * Date : 2023. 05. 09
+ * Change Date :
+ */
+
+//============================================================================
+// [CLASS] ProbDist
+//============================================================================
+define([
+ 'vp_base/js/com/com_util',
+ 'vp_base/js/com/com_Const',
+ 'vp_base/js/com/com_String',
+ 'vp_base/js/com/component/PopupComponent',
+ 'vp_base/js/com/component/DataSelector'
+], function(com_util, com_Const, com_String, PopupComponent, DataSelector) {
+
+ /**
+ * ProbDist
+ */
+ class ProbDist extends PopupComponent {
+ _init() {
+ super._init();
+ /** Write codes executed before rendering */
+ }
+
+ _bindEvent() {
+ super._bindEvent();
+ /** Implement binding events */
+ var that = this;
+ }
+
+ templateForBody() {
+ /** Implement generating template */
+ return `This is sample.
+ `;
+ }
+
+ render() {
+ super.render();
+
+ let dataSelector = new DataSelector({
+ type: 'data',
+ pageThis: this,
+ id: 'sample',
+ finish: function() {
+ ;
+ }
+ });
+ $(this.wrapSelector('#sample')).replaceWith(dataSelector.toTagString());
+ }
+
+ generateCode() {
+ return "print('sample code')";
+ }
+
+ }
+
+ return ProbDist;
+});
\ No newline at end of file
diff --git a/visualpython/js/m_stats/StudentstTest.js b/visualpython/js/m_stats/StudentstTest.js
new file mode 100644
index 00000000..da5cdcbc
--- /dev/null
+++ b/visualpython/js/m_stats/StudentstTest.js
@@ -0,0 +1,65 @@
+/*
+ * Project Name : Visual Python
+ * Description : GUI-based Python code generator
+ * File Name : StudentstTest.js
+ * Author : Black Logic
+ * Note : Student's t-test
+ * License : GNU GPLv3 with Visual Python special exception
+ * Date : 2023. 05. 09
+ * Change Date :
+ */
+
+//============================================================================
+// [CLASS] StudentstTest
+//============================================================================
+define([
+ 'vp_base/js/com/com_util',
+ 'vp_base/js/com/com_Const',
+ 'vp_base/js/com/com_String',
+ 'vp_base/js/com/component/PopupComponent',
+ 'vp_base/js/com/component/DataSelector'
+], function(com_util, com_Const, com_String, PopupComponent, DataSelector) {
+
+ /**
+ * StudentstTest
+ */
+ class StudentstTest extends PopupComponent {
+ _init() {
+ super._init();
+ /** Write codes executed before rendering */
+ }
+
+ _bindEvent() {
+ super._bindEvent();
+ /** Implement binding events */
+ var that = this;
+ }
+
+ templateForBody() {
+ /** Implement generating template */
+ return `This is sample.
+ `;
+ }
+
+ render() {
+ super.render();
+
+ let dataSelector = new DataSelector({
+ type: 'data',
+ pageThis: this,
+ id: 'sample',
+ finish: function() {
+ ;
+ }
+ });
+ $(this.wrapSelector('#sample')).replaceWith(dataSelector.toTagString());
+ }
+
+ generateCode() {
+ return "print('sample code')";
+ }
+
+ }
+
+ return StudentstTest;
+});
\ No newline at end of file
diff --git a/visualpython/python/variableCommand.py b/visualpython/python/variableCommand.py
index a6bc7fcd..3195908e 100644
--- a/visualpython/python/variableCommand.py
+++ b/visualpython/python/variableCommand.py
@@ -102,16 +102,16 @@ def _vp_sample(data, sample_cnt):
"""
Sampling data
"""
- dataType = type(data).__name__
+ data_type = type(data).__name__
sample_cnt = len(data) if len(data) < sample_cnt else sample_cnt
- if dataType == 'DataFrame':
+ if data_type == 'DataFrame':
return data.sample(sample_cnt, random_state=0)
- elif dataType == 'Series':
- return data.sample(sample_cnt, random_state=0)
- elif dataType == 'ndarray':
+ elif data_type == 'Series':
+ return data.sample(sample_cnt, random_state=0).reset_index(drop=True)
+ elif data_type == 'ndarray':
return data[_vp_np.random.choice(data.shape[0], sample_cnt, replace=False)]
- elif dataType == 'list':
+ elif data_type == 'list':
return _vp_rd.choices(data, k=sample_cnt)
return data
|
---|