-
-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathPandasOption.js
More file actions
150 lines (128 loc) · 5.32 KB
/
PandasOption.js
File metadata and controls
150 lines (128 loc) · 5.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
* Project Name : Visual Python
* Description : GUI-based Python code generator
* File Name : PandasOption.js
* Author : Black Logic
* Note : Pandas option
* License : GNU GPLv3 with Visual Python special exception
* Date : 2023. 03. 28
* Change Date :
*/
//============================================================================
// [CLASS] PandasOption
//============================================================================
define([
__VP_TEXT_LOADER__('vp_base/html/m_apps/pandasOption.html'),
'vp_base/js/com/com_util',
'vp_base/js/com/com_Const',
'vp_base/js/com/com_String',
'vp_base/js/com/component/PopupComponent'
], function(poHTML, com_util, com_Const, com_String, PopupComponent) {
/**
* PandasOption
*/
class PandasOption extends PopupComponent {
_init() {
super._init();
/** Write codes executed before rendering */
this.config.sizeLevel = 2;
this.config.dataview = false;
this.config.checkModules = ['pd'];
this.config.docs = 'https://pandas.pydata.org/docs/user_guide/options.html';
this.state = {
filter_warning: '',
min_rows: '',
max_rows: '',
max_columns: '',
max_colwidth: '',
expand_frame_repr: '',
precision: '',
chop_threshold: '',
...this.state
}
}
_bindEvent() {
super._bindEvent();
/** Implement binding events */
var that = this;
// setting popup - set default
$(this.wrapSelector('#resetDisplay')).on('change', function() {
let checked = $(this).prop('checked');
if (checked) {
// disable input
$(that.wrapSelector('.vp-po-option-item')).prop('disabled', true);
} else {
// enable input
$(that.wrapSelector('.vp-po-option-item')).prop('disabled', false);
}
});
// show all rows
$(this.wrapSelector('#showAllRows')).on('change', function() {
let checked = $(this).prop('checked');
if (checked) {
$(that.wrapSelector('#max_rows')).prop('disabled', true);
} else {
$(that.wrapSelector('#max_rows')).prop('disabled', false);
}
});
// show all columns
$(this.wrapSelector('#showAllColumns')).on('change', function() {
let checked = $(this).prop('checked');
if (checked) {
$(that.wrapSelector('#max_columns')).prop('disabled', true);
} else {
$(that.wrapSelector('#max_columns')).prop('disabled', false);
}
});
// setting popup - reset warning
$(this.wrapSelector('#resetWarning')).on('change', function() {
let checked = $(this).prop('checked');
if (checked) {
// disable input
$(that.wrapSelector('.vp-po-warning-item')).prop('disabled', true);
} else {
// enable input
$(that.wrapSelector('.vp-po-warning-item')).prop('disabled', false);
}
});
}
templateForBody() {
let page = $(poHTML);
return page;
}
render() {
super.render();
}
generateCode() {
let that = this;
let code = [];
let resetDisplay = $(this.wrapSelector('#resetDisplay')).prop('checked');
let resetWarning = $(this.wrapSelector('#resetWarning')).prop('checked');
// warning options
if (resetWarning === true) {
code.push("import warnings\nwarnings.resetwarnings()");
} else{
if (that.state['filter_warning'] && that.state['filter_warning'] != '') {
code.push(com_util.formatString("import warnings\nwarnings.simplefilter(action='{0}', category=Warning)", that.state['filter_warning']));
}
}
// display options
if (resetDisplay === true) {
code.push("pd.reset_option('^display')");
} else {
let showAllRows = $(this.wrapSelector('#showAllRows')).prop('checked');
let showAllCols = $(this.wrapSelector('#showAllColumns')).prop('checked');
Object.keys(this.state).forEach((key) => {
if ((showAllRows === true && key === 'max_rows')
|| (showAllCols === true && key === 'max_columns')) {
code.push(com_util.formatString("pd.set_option('display.{0}', {1})", key, 'None'));
} else if (key !== 'filter_warning' && that.state[key] && that.state[key] != '') {
code.push(com_util.formatString("pd.set_option('display.{0}', {1})", key, that.state[key]));
}
});
}
return code.join('\n');
}
}
return PandasOption;
});