Skip to content

Commit 62255d4

Browse files
author
minjk-bl
committed
Fixed Load/Save operation for WordCloud
1 parent 5571ddc commit 62255d4

File tree

3 files changed

+48
-14
lines changed

3 files changed

+48
-14
lines changed

html/m_visualize/wordCloud.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
</div>
2525

2626
<label for="wordCount" class="vp-bold">Number of words</label>
27-
<input type="number" id="wordCount" class="vp-input vp-state" min="0" value="200"/>
27+
<input type="number" id="wordCount" class="vp-input vp-state" min="0"/>
2828

2929
</div>
3030
<div class="vp-tab-page vp-grid-box" data-type="wordcloud" style="display: none;">
@@ -40,8 +40,8 @@
4040
<div class="vp-tab-page vp-grid-box" data-type="plot" style="display: none;">
4141
<label for="figWidth" class="vp-bold">Figure size</label>
4242
<div>
43-
<input type="number" id="figWidth" class="vp-input vp-state" min="0" value="8" placeholder="Width"/>
44-
<input type="number" id="figHeight" class="vp-input vp-state" min="0" value="20" placeholder="Height"/>
43+
<input type="number" id="figWidth" class="vp-input vp-state" min="0" placeholder="Width"/>
44+
<input type="number" id="figHeight" class="vp-input vp-state" min="0" placeholder="Height"/>
4545
</div>
4646
</div>
4747
</div>

js/com/component/DataSelector.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ define([
185185
that.state.dataType = ui.item.dtype;
186186
that.state.returnDataType = ui.item.dtype;
187187

188-
// that.prop.pageThis.state[that.prop.id + '_state'] = that.state;
188+
that.prop.pageThis.state[that.prop.id + '_state'] = that.state;
189189

190190
$(this).trigger('change');
191191

js/m_visualize/WordCloud.js

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ define([
3636
data: '',
3737
useFile: false,
3838
encoding: '',
39-
wordCount: 200,
39+
wordCount: '200',
4040
stopWords: '',
4141
fontPath: '',
4242
userOption: '',
@@ -103,6 +103,37 @@ define([
103103
$(page).find('.vp-wc-file-option').hide();
104104
}
105105

106+
let that = this;
107+
//================================================================
108+
// Load state
109+
//================================================================
110+
Object.keys(this.state).forEach(key => {
111+
let tag = $(page).find('#' + key);
112+
let tagName = $(tag).prop('tagName'); // returns with UpperCase
113+
let value = that.state[key];
114+
if (value == undefined) {
115+
return;
116+
}
117+
switch(tagName) {
118+
case 'INPUT':
119+
let inputType = $(tag).prop('type');
120+
if (inputType == 'text' || inputType == 'number' || inputType == 'hidden') {
121+
$(tag).val(value);
122+
break;
123+
}
124+
if (inputType == 'checkbox') {
125+
$(tag).prop('checked', value);
126+
break;
127+
}
128+
break;
129+
case 'TEXTAREA':
130+
case 'SELECT':
131+
default:
132+
$(tag).val(value);
133+
break;
134+
}
135+
});
136+
106137
return page;
107138
}
108139

@@ -120,7 +151,7 @@ define([
120151
'height': '200px'
121152
});
122153

123-
// FIXME: bind dataSelector to #data
154+
// bind dataSelector to #data
124155
let dataSelector = new DataSelector({
125156
type: 'data',
126157
pageThis: this,
@@ -132,8 +163,6 @@ define([
132163
finish: function() {
133164
that.state.useFile = false;
134165
$(that.wrapSelector('.vp-wc-file-option')).hide();
135-
136-
$(that.wrapSelector('#data')).change();
137166
}
138167
});
139168
$(this.wrapSelector('#data')).replaceWith(dataSelector.toTagString());
@@ -239,7 +268,7 @@ define([
239268

240269
generateCode(preview=false) {
241270
let {
242-
data, useFile, encoding, wordCount,
271+
data, data_state, useFile, encoding, wordCount,
243272
stopWords, fontPath, userOption, figWidth, figHeight
244273
} = this.state;
245274
let code = new com_String();
@@ -263,11 +292,16 @@ define([
263292
code.appendLine(" word_cloud_text = fp.read()");
264293
code.appendLine();
265294
dataVariable = 'word_cloud_text';
266-
}
267-
// check data type and convert it to string
268-
let dataType = $(this.wrapSelector('#data')).data('type');
269-
if (dataType == 'DataFrame' || dataType == 'Series') {
270-
dataVariable = data + '.to_string()';
295+
} else {
296+
// check data type and convert it to string
297+
// let dataType = $(this.wrapSelector('#data')).data('type');
298+
let dataType = '';
299+
if (data_state) {
300+
dataType = data_state['returnDataType'];
301+
}
302+
if (dataType == 'DataFrame' || dataType == 'Series') {
303+
dataVariable = data + '.to_string()';
304+
}
271305
}
272306
code.appendFormatLine("counts = Counter({0}.split())", dataVariable);
273307
code.appendFormatLine("tags = counts.most_common({0})", wordCount);

0 commit comments

Comments
 (0)