1
1
import BaseDB from './db/base.js'
2
2
import { FixData } from './base.js'
3
3
import JSONLoader from './loader/json.js'
4
+ import IOSelector from './util/ioselector.js'
4
5
5
6
const BASE_URL = 'https://dashboard.e-stat.go.jp/api/1.0'
6
7
const ExpiredTime = 1000 * 60 * 60 * 24 * 30
@@ -61,11 +62,8 @@ export default class EStatData extends FixData {
61
62
constructor ( manager ) {
62
63
super ( manager )
63
64
this . _name = 'Nikkei Indexes'
64
- this . _columns = [ ]
65
65
this . _shift = [ ]
66
66
this . _scale = [ ]
67
- this . _object = [ ]
68
- this . _target = - 1
69
67
this . _scaled = true
70
68
this . _lastRequested = 0
71
69
@@ -109,8 +107,16 @@ export default class EStatData extends FixData {
109
107
credit . innerText = resources . credit
110
108
credit . style . fontSize = '80%'
111
109
elm . appendChild ( credit )
112
- this . _selector = document . createElement ( 'div' )
113
- elm . appendChild ( this . _selector )
110
+ this . _selector = new IOSelector ( elm )
111
+ this . _selector . onchange = ( ) => {
112
+ this . _domain = null
113
+ this . _manager . onReady ( ( ) => {
114
+ this . _manager . platform . init ( )
115
+ } )
116
+ }
117
+
118
+ this . _loader = document . createElement ( 'div' )
119
+ elm . appendChild ( this . _loader )
114
120
115
121
const optionalElm = document . createElement ( 'div' )
116
122
const scaledCheckbox = document . createElement ( 'input' )
@@ -136,21 +142,21 @@ export default class EStatData extends FixData {
136
142
}
137
143
138
144
get _requireDateInput ( ) {
139
- return this . _object . length === 0 && this . _datetime && [ '' , 'RG' , 'AD' ] . includes ( this . _manager . task )
145
+ return this . _selector . object . length === 0 && this . _datetime && [ '' , 'RG' , 'AD' ] . includes ( this . _manager . task )
140
146
}
141
147
142
148
get columnNames ( ) {
143
149
if ( this . _requireDateInput ) {
144
150
return [ 'date' ]
145
151
}
146
- return this . _object . map ( i => this . _columns [ i ] )
152
+ return this . _selector . objectNames
147
153
}
148
154
149
155
get originalX ( ) {
150
156
if ( this . _requireDateInput ) {
151
157
return this . _datetime . map ( v => [ v ] )
152
158
}
153
- return this . _x . map ( v => this . _object . map ( i => v [ i ] ) )
159
+ return this . _x . map ( v => this . _selector . object . map ( i => v [ i ] ) )
154
160
}
155
161
156
162
get x ( ) {
@@ -161,22 +167,24 @@ export default class EStatData extends FixData {
161
167
this . _readyScaledData ( )
162
168
return this . _x . map ( v => {
163
169
const c = v . map ( ( a , d ) => ( a - this . _shift [ d ] ) / this . _scale [ d ] )
164
- return this . _object . map ( i => c [ i ] )
170
+ return this . _selector . object . map ( i => c [ i ] )
165
171
} )
166
172
}
167
173
168
174
get originalY ( ) {
169
- if ( this . _target >= 0 ) {
170
- return this . _x . map ( v => v [ this . _target ] )
175
+ const target = this . _selector . target
176
+ if ( target >= 0 ) {
177
+ return this . _x . map ( v => v [ target ] )
171
178
}
172
179
return Array ( this . _x . length ) . fill ( 0 )
173
180
}
174
181
175
182
get y ( ) {
176
183
if ( ! this . _scaled ) return this . originalY
177
184
this . _readyScaledData ( )
178
- if ( this . _target >= 0 ) {
179
- return this . _x . map ( v => ( v [ this . _target ] - this . _shift [ this . _target ] ) / this . _scale [ this . _target ] )
185
+ const target = this . _selector . target
186
+ if ( target >= 0 ) {
187
+ return this . _x . map ( v => ( v [ target ] - this . _shift [ target ] ) / this . _scale [ target ] )
180
188
}
181
189
return Array ( this . _x . length ) . fill ( 0 )
182
190
}
@@ -524,26 +532,23 @@ export default class EStatData extends FixData {
524
532
this . _x = [ ]
525
533
this . _shift = [ ]
526
534
this . _scale = [ ]
527
- this . _columns = [ ]
528
- this . _object = [ ]
529
535
this . _index = null
530
536
this . _datetime = null
531
537
this . _manager . platform ?. init ( )
532
538
533
539
const indicatorCodes = this . indicatorCodes
540
+ this . _selector . columns = [ ]
534
541
if ( indicatorCodes . length === 0 ) {
535
- this . _readySelector ( )
536
542
this . setting . ml . refresh ( )
537
543
return
538
544
}
539
545
540
- const loader = document . createElement ( 'div' )
541
- loader . classList . add ( 'loader' )
542
- this . _selector . replaceChildren ( loader )
546
+ this . _loader . classList . add ( 'loader' )
543
547
544
548
const query = { Cycle : this . cycle , RegionCode : this . region }
545
549
const queryString = JSON . stringify ( query )
546
550
const data = await this . _getData ( indicatorCodes , query )
551
+ this . _loader . classList . remove ( 'loader' )
547
552
if (
548
553
indicatorCodes . length != this . indicatorCodes . length ||
549
554
indicatorCodes . some ( ( c , i ) => c !== this . indicatorCodes [ i ] ) ||
@@ -552,7 +557,6 @@ export default class EStatData extends FixData {
552
557
return
553
558
}
554
559
if ( data . GET_STATS . RESULT . status === '1' ) {
555
- this . _readySelector ( )
556
560
return
557
561
}
558
562
const dataobj = data . GET_STATS . STATISTICAL_DATA . DATA_INF . DATA_OBJ
@@ -597,11 +601,13 @@ export default class EStatData extends FixData {
597
601
}
598
602
}
599
603
600
- this . _columns = columns
604
+ this . _selector . columns = columns
605
+ const object = [ ]
601
606
for ( let i = 0 ; i < columns . length - 1 ; i ++ ) {
602
- this . _object . push ( i )
607
+ object . push ( i )
603
608
}
604
- this . _target = this . _columns . length - 1
609
+ this . _selector . object = object
610
+ this . _selector . target = columns . length - 1
605
611
606
612
const keys = Object . keys ( seldata )
607
613
keys . sort ( )
@@ -621,81 +627,9 @@ export default class EStatData extends FixData {
621
627
{ columnInfos : info }
622
628
)
623
629
this . setArray ( json . data , info )
624
- this . _readySelector ( )
625
630
this . setting . ml . refresh ( )
626
631
this . setting . $forceUpdate ( )
627
632
}
628
-
629
- _readySelector ( ) {
630
- this . _selector . replaceChildren ( )
631
- if ( this . _columns . length > 1 ) {
632
- const islct = document . createElement ( 'select' )
633
- islct . multiple = true
634
- islct . onchange = ( ) => {
635
- this . _object = [ ]
636
- let unslctval = ''
637
- let oreset = false
638
- for ( const opt of islct . options ) {
639
- if ( opt . selected ) {
640
- this . _object . push ( this . _columns . indexOf ( opt . value ) )
641
- if ( opt . value === oslct . value ) {
642
- oreset = true
643
- }
644
- } else if ( ! unslctval ) {
645
- unslctval = opt . value
646
- }
647
- }
648
- if ( oreset ) {
649
- this . _target = this . _columns . indexOf ( unslctval )
650
- oslct . value = unslctval
651
- }
652
- this . _domain = null
653
- this . _manager . onReady ( ( ) => {
654
- this . _manager . platform . init ( )
655
- } )
656
- }
657
- this . _selector . append ( 'Input' , islct )
658
- const oslct = document . createElement ( 'select' )
659
- oslct . onchange = ( ) => {
660
- let hasislct = false
661
- for ( const opt of islct . selectedOptions ) {
662
- if ( opt . value === oslct . value ) {
663
- opt . selected = false
664
- this . _object = this . _object . filter ( i => this . _columns [ i ] !== opt . value )
665
- hasislct = true
666
- break
667
- }
668
- }
669
- if ( hasislct || ( oslct . value === '' && this . _target >= 0 ) ) {
670
- for ( const opt of islct . options ) {
671
- if ( opt . value === this . _columns [ this . _target ] ) {
672
- opt . selected = true
673
- this . _object . push ( this . _target )
674
- }
675
- }
676
- }
677
- this . _target = this . _columns . indexOf ( oslct . value )
678
- this . _domain = null
679
- this . _manager . onReady ( ( ) => {
680
- this . _manager . platform . init ( )
681
- } )
682
- }
683
- this . _selector . append ( 'Output' , oslct )
684
-
685
- oslct . appendChild ( document . createElement ( 'option' ) )
686
- for ( const column of this . _columns ) {
687
- const opt = document . createElement ( 'option' )
688
- opt . value = opt . innerText = column
689
- islct . appendChild ( opt )
690
- oslct . appendChild ( opt . cloneNode ( true ) )
691
- }
692
- islct . size = Math . min ( 4 , islct . options . length )
693
- for ( let i = 0 ; i < this . _columns . length - 1 ; i ++ ) {
694
- islct . options [ i ] . selected = this . _object . includes ( i )
695
- }
696
- oslct . value = this . _columns [ this . _target ]
697
- }
698
- }
699
633
}
700
634
701
635
const DB_NAME = 'dashboard.e-stat.go.jp'
0 commit comments