8
8
, 'nbextensions/visualpython/src/pandas/common/commonPandas'
9
9
, 'nbextensions/visualpython/src/pandas/common/pandasGenerator'
10
10
] , function ( requirejs , $ , vpCommon , vpConst , sb , vpFuncJS , libPandas , pdGen ) {
11
- // 옵션 속성
11
+ // option property
12
12
const funcOptProp = {
13
13
stepCount : 1
14
14
, funcName : "Variables"
@@ -17,74 +17,73 @@ define([
17
17
}
18
18
19
19
/**
20
- * html load 콜백 . 고유 id 생성하여 부과하며 js 객체 클래스 생성하여 컨테이너로 전달
21
- * @param {function } callback 호출자(컨테이너) 의 콜백함수
20
+ * html load callback . 고유 id 생성하여 부과하며 js 객체 클래스 생성하여 컨테이너로 전달
21
+ * @param {function } callback container's callback
22
22
*/
23
23
var optionLoadCallback = function ( callback , meta ) {
24
- // document.getElementsByTagName("head")[0].appendChild(link);
25
- // 컨테이너에서 전달된 callback 함수가 존재하면 실행.
24
+ // execute callback function if available
26
25
if ( typeof ( callback ) === 'function' ) {
27
26
var uuid = 'u' + vpCommon . getUUID ( ) ;
28
- // 최대 10회 중복되지 않도록 체크
27
+ // maximum 10 duplication allowed
29
28
for ( var idx = 0 ; idx < 10 ; idx ++ ) {
30
- // 이미 사용중인 uuid 인 경우 다시 생성
29
+ // uuid check and re-generate
31
30
if ( $ ( vpConst . VP_CONTAINER_ID ) . find ( "." + uuid ) . length > 0 ) {
32
31
uuid = 'u' + vpCommon . getUUID ( ) ;
33
32
}
34
33
}
35
34
$ ( vpCommon . wrapSelector ( vpCommon . formatString ( "#{0}" , vpConst . OPTION_GREEN_ROOM ) ) ) . find ( vpCommon . formatString ( ".{0}" , vpConst . API_OPTION_PAGE ) ) . addClass ( uuid ) ;
36
35
37
- // 옵션 객체 생성
36
+ // create object
38
37
var varPackage = new VariablePackage ( uuid ) ;
39
38
varPackage . metadata = meta ;
40
39
41
- // 옵션 속성 할당.
40
+ // set option property
42
41
varPackage . setOptionProp ( funcOptProp ) ;
43
- // html 설정.
42
+ // html setting
44
43
varPackage . initHtml ( ) ;
45
- callback ( varPackage ) ; // 공통 객체를 callback 인자로 전달
44
+ callback ( varPackage ) ;
46
45
}
47
46
}
48
47
49
48
/**
50
- * html 로드.
51
- * @param {function } callback 호출자(컨테이너) 의 콜백함수
49
+ * Load html
50
+ * @param {function } callback container's callback
52
51
*/
53
52
var initOption = function ( callback , meta ) {
54
53
vpCommon . loadHtml ( vpCommon . wrapSelector ( vpCommon . formatString ( "#{0}" , vpConst . OPTION_GREEN_ROOM ) ) , "file_io/variables.html" , optionLoadCallback , callback , meta ) ;
55
54
}
56
55
57
56
/**
58
- * 본 옵션 처리 위한 클래스
59
- * @param {String } uuid 고유 id
57
+ * Option package
58
+ * @param {String } uuid unique id
60
59
*/
61
60
var VariablePackage = function ( uuid ) {
62
61
this . uuid = uuid ; // Load html 영역의 uuid.
63
- // pandas 함수
62
+ // pandas function
64
63
this . package = libPandas . _PANDAS_FUNCTION [ funcOptProp . libID ] ;
65
64
}
66
65
67
66
68
67
69
68
/**
70
- * vpFuncJS 에서 상속
69
+ * Extend vpFuncJS
71
70
*/
72
71
VariablePackage . prototype = Object . create ( vpFuncJS . VpFuncJS . prototype ) ;
73
72
74
73
/**
75
- * 유효성 검사
76
- * @returns 유효성 검사 결과. 적합시 true
74
+ * Validation
75
+ * @returns true if it's valid
77
76
*/
78
77
VariablePackage . prototype . optionValidation = function ( ) {
79
78
return true ;
80
79
81
- // 부모 클래스 유효성 검사 호출.
80
+ // parent's validation
82
81
// vpFuncJS.VpFuncJS.prototype.optionValidation.apply(this);
83
82
}
84
83
85
84
86
85
/**
87
- * html 내부 binding 처리
86
+ * html inner binding
88
87
*/
89
88
VariablePackage . prototype . initHtml = function ( ) {
90
89
this . showFunctionTitle ( ) ;
@@ -98,7 +97,7 @@ define([
98
97
}
99
98
100
99
/**
101
- * 선택한 패키지명 입력
100
+ * package title
102
101
*/
103
102
VariablePackage . prototype . showFunctionTitle = function ( ) {
104
103
$ ( this . wrapSelector ( '.vp_functionName' ) ) . text ( funcOptProp . funcName ) ;
@@ -115,43 +114,43 @@ define([
115
114
}
116
115
117
116
/**
118
- * Variables 조회
117
+ * Search variables
119
118
*/
120
119
VariablePackage . prototype . loadVariables = function ( ) {
121
120
var that = this ;
122
121
123
- // 조회가능한 변수 data type 정의 FIXME: 조회 필요한 변수 유형 추가
122
+ // Searchable variable types
124
123
var types = [
125
- // pandas 객체
124
+ // pandas object
126
125
'DataFrame' , 'Series' , 'Index' , 'Period' , 'GroupBy' , 'Timestamp'
127
- // Index 하위 유형
126
+ // Index type object
128
127
, 'RangeIndex' , 'CategoricalIndex' , 'MultiIndex' , 'IntervalIndex' , 'DatetimeIndex' , 'TimedeltaIndex' , 'PeriodIndex' , 'Int64Index' , 'UInt64Index' , 'Float64Index'
129
- // GroupBy 하위 유형
128
+ // GroupBy type object
130
129
, 'DataFrameGroupBy' , 'SeriesGroupBy'
131
- // Plot 관련 유형
130
+ // Plot type
132
131
, 'Figure' , 'AxesSubplot'
133
132
// Numpy
134
133
, 'ndarray'
135
- // Python 변수
134
+ // Python variable
136
135
, 'str' , 'int' , 'float' , 'bool' , 'dict' , 'list' , 'tuple'
137
136
] ;
138
137
139
138
var tagTable = this . wrapSelector ( '#vp_var_variableBox table' ) ;
140
139
141
- // 변수 정보 표시
140
+ // variable list table
142
141
var tagDetailTable = this . wrapSelector ( "#vp_varDetailTable" ) ;
143
142
144
143
// initialize tags
145
144
$ ( tagTable ) . find ( 'tr:not(:first)' ) . remove ( ) ;
146
145
$ ( tagDetailTable ) . html ( '' ) ;
147
146
148
- // HTML 구성
147
+ // HTML rendering
149
148
pdGen . vp_searchVarList ( types , function ( result ) {
150
149
// var jsonVars = result.replace(/'/gi, `"`);
151
150
// var varList = JSON.parse(jsonVars);
152
151
var varList = JSON . parse ( result ) ;
153
152
154
- // table 에 변수목록 추가
153
+ // add variable list in table
155
154
varList . forEach ( varObj => {
156
155
if ( types . includes ( varObj . varType ) && varObj . varName [ 0 ] !== '_' ) {
157
156
var tagTr = document . createElement ( 'tr' ) ;
@@ -167,30 +166,12 @@ define([
167
166
$ ( tagTr ) . append ( tagTdName ) ;
168
167
$ ( tagTr ) . append ( tagTdType ) ;
169
168
170
- $ ( tagTdName ) . attr ( {
171
- 'title' : 'Click to copy'
172
- } ) ;
173
- // 변수이름 클릭 시 클립보드에 복사
174
- $ ( tagTdName ) . click ( function ( ) {
175
- // // 클립보드 복사 시작
176
- var tempElem = document . createElement ( 'input' ) ;
177
- tempElem . value = varObj . varName ;
178
- document . body . appendChild ( tempElem ) ;
179
-
180
- tempElem . select ( ) ;
181
- document . execCommand ( "copy" ) ;
182
- document . body . removeChild ( tempElem ) ;
183
- // 클립보드 복사 완료
184
- vpCommon . renderSuccessMessage ( 'Copied!' ) ;
185
- } ) ;
186
-
187
- // 변수 선택 시 표시
169
+ // variable click
188
170
$ ( tagTr ) . click ( function ( ) {
189
171
$ ( this ) . parent ( ) . find ( 'tr' ) . removeClass ( 'selected' ) ;
190
172
$ ( this ) . addClass ( 'selected' ) ;
191
173
192
- // TEST: 변수 선택 시 변수 정보를 하단에 표시
193
- // vpFuncJS.kernelExecute 에서는 callback에 msg.content["text"]를 전달해주기 때문에 따로 구현함
174
+ // show variable information on clicking variable
194
175
Jupyter . notebook . kernel . execute (
195
176
varObj . varName ,
196
177
{
@@ -202,14 +183,14 @@ define([
202
183
203
184
$ ( tagDetailTable ) . html ( '' ) ;
204
185
if ( htmlResult != undefined ) {
205
- // 1. HTML 태그로 구성되어 반환되는 경우
186
+ // 1. HTML tag
206
187
$ ( tagDetailTable ) . append ( htmlResult ) ;
207
188
} else if ( imgResult != undefined ) {
208
- // 2. 이미지 데이터가 반환되는 경우 (base64)
189
+ // 2. Image data (base64)
209
190
var imgTag = '<img src="data:image/png;base64, ' + imgResult + '">' ;
210
191
$ ( tagDetailTable ) . append ( imgTag ) ;
211
192
} else if ( textResult != undefined ) {
212
- // 3. 텍스트 데이터가 반환되는 경우
193
+ // 3. Text data
213
194
var preTag = document . createElement ( 'pre' ) ;
214
195
$ ( preTag ) . text ( textResult ) ;
215
196
$ ( tagDetailTable ) . html ( preTag ) ;
@@ -221,7 +202,6 @@ define([
221
202
} ,
222
203
{ silent : false }
223
204
) ;
224
- // TEST: END
225
205
} )
226
206
227
207
$ ( tagTable ) . append ( tagTr ) ;
@@ -231,14 +211,14 @@ define([
231
211
} ;
232
212
233
213
/**
234
- * 코드 생성
235
- * @param {boolean } exec 실행여부
214
+ * Generate code
215
+ * @param {boolean } exec do execute
236
216
*/
237
217
VariablePackage . prototype . generateCode = function ( addCell , exec ) {
238
218
239
219
var sbCode = new sb . StringBuilder ( ) ;
240
220
241
- // TODO: 변수 내용 조회
221
+ // show selected variable
242
222
var selectedVariable = $ ( this . wrapSelector ( '#vp_var_variableBox table tr.selected' ) ) ;
243
223
if ( selectedVariable ) {
244
224
var varName = selectedVariable . attr ( 'data-var-name' ) ;
0 commit comments