@@ -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