@@ -33,7 +33,7 @@ function readFromJsonBin(id) {
3333 const objBin = JSON . parse ( req . responseText ) ;
3434 console . log ( req . responseText , objBin ) ;
3535 schematic = objBin . record ;
36- update_smith_chart ( ) ;
36+ updateFromOldState ( ) ;
3737 }
3838 } ;
3939 req . open ( "GET" , `https://api.jsonbin.io/v3/b/${ id } /latest` , true ) ;
@@ -183,42 +183,46 @@ function readFile() {
183183 reader . onload = function ( event ) {
184184
185185 schematic = JSON . parse ( event . target . result ) ;
186- //check for old version of file
187- for ( i = 1 ; i < schematic . length ; i ++ ) {
188- if ( ! ( Array . isArray ( schematic [ i ] . abs ) ) ) {
189- schematic [ i ] . abs = [ schematic [ i ] . abs ] ;
190- }
191- if ( 'abs_bb_i' in schematic [ i ] ) schematic [ i ] . abs . push ( schematic [ i ] . abs_bb_i ) ;
192- if ( ! ( Array . isArray ( schematic [ i ] . unit ) ) ) {
193- schematic [ i ] . unit = [ schematic [ i ] . unit ] ;
194- }
195- }
186+ console . log ( "READING" , schematic ) ;
187+ updateFromOldState ( )
188+ }
189+ reader . readAsText ( file ) ;
190+ }
196191
197- //update freq units
198- var opts = domFreqSel . options ;
199- for ( var opt , j = 0 ; opt = opts [ j ] ; j ++ ) {
200- if ( opt . value == freqUnitToText ( schematic [ 0 ] . freq_unit . multiplier ) ) {
201- domFreqSel . selectedIndex = j ;
202- break ;
203- }
192+ function updateFromOldState ( ) {
193+ //check for old version of file
194+ for ( i = 1 ; i < schematic . length ; i ++ ) {
195+ if ( ! ( Array . isArray ( schematic [ i ] . abs ) ) ) {
196+ schematic [ i ] . abs = [ schematic [ i ] . abs ] ;
204197 }
205- opts = domSpanSel . options ;
206- for ( opt , j = 0 ; opt = opts [ j ] ; j ++ ) {
207- if ( opt . value == freqUnitToText ( schematic [ 0 ] . span_unit . multiplier ) ) {
208- domSpanSel . selectedIndex = j ;
209- break ;
210- }
198+ if ( 'abs_bb_i' in schematic [ i ] ) schematic [ i ] . abs . push ( schematic [ i ] . abs_bb_i ) ;
199+ if ( ! ( Array . isArray ( schematic [ i ] . unit ) ) ) {
200+ schematic [ i ] . unit = [ schematic [ i ] . unit ] ;
211201 }
202+ }
212203
213- domFreq . value = Number ( schematic [ 0 ] . freq ) ;
214- domSpan . value = Number ( schematic [ 0 ] . span ) ;
215- domEr . value = Number ( schematic [ 0 ] . er ) ;
216- zo = Number ( schematic [ 0 ] . zo ) ;
217- domZo . value = zo ;
218- console . log ( "READING" , schematic ) ;
219- updateFromDom ( ) ;
204+ //update freq units
205+ var opts = domFreqSel . options ;
206+ for ( var opt , j = 0 ; opt = opts [ j ] ; j ++ ) {
207+ if ( opt . value == freqUnitToText ( schematic [ 0 ] . freq_unit . multiplier ) ) {
208+ domFreqSel . selectedIndex = j ;
209+ break ;
210+ }
220211 }
221- reader . readAsText ( file ) ;
212+ opts = domSpanSel . options ;
213+ for ( opt , j = 0 ; opt = opts [ j ] ; j ++ ) {
214+ if ( opt . value == freqUnitToText ( schematic [ 0 ] . span_unit . multiplier ) ) {
215+ domSpanSel . selectedIndex = j ;
216+ break ;
217+ }
218+ }
219+
220+ domFreq . value = Number ( schematic [ 0 ] . freq ) ;
221+ domSpan . value = Number ( schematic [ 0 ] . span ) ;
222+ domEr . value = Number ( schematic [ 0 ] . er ) ;
223+ zo = Number ( schematic [ 0 ] . zo ) ;
224+ domZo . value = zo ;
225+ updateFromDom ( ) ;
222226}
223227
224228
0 commit comments