1- import { ESourceType , TId , TSearchParams , TVec } from 'Types' ;
1+ import * as d3 from 'd3' ;
2+ import {
3+ EActionType ,
4+ EIndexType ,
5+ ESourceType ,
6+ EViewType ,
7+ TId ,
8+ TSearchParams ,
9+ TVec ,
10+ } from 'Types' ;
11+ import { TAcitonData } from 'Types/visData' ;
12+ import { finishLoading , renderLoading , initLoadingStyle } from 'Utils/loading' ;
213import { FederIndex , FederLayout , FederView } from '.' ;
314
4- export default class Feder {
15+ export class Feder {
516 domSelector : string ;
617 initFederPromise : Promise < void > ;
718 federIndex : FederIndex ;
819 viewParams : any ;
920 federLayout : FederLayout ;
21+ indexType : EIndexType ;
22+ viewType : EViewType ;
23+ searchParams : TSearchParams ;
1024 constructor ( {
1125 source,
1226 filePath,
@@ -16,23 +30,90 @@ export default class Feder {
1630 filePath : string ;
1731 source : ESourceType ;
1832 domSelector ?: string ;
33+ viewType ?: EViewType ;
1934 viewParams ?: any ;
2035 } ) {
2136 this . domSelector = domSelector ;
37+ const { viewType = EViewType . default } = viewParams ;
38+ this . viewType = viewType ;
2239 this . viewParams = viewParams ;
40+ this . searchParams = { } ;
2341
2442 this . initFederPromise = new Promise ( async ( resolve ) => {
2543 const arrayBuffer = await fetch ( filePath ) . then ( ( res ) =>
2644 res . arrayBuffer ( )
2745 ) ;
2846 this . federIndex = new FederIndex ( source , arrayBuffer ) ;
47+ this . indexType = await this . federIndex . getIndexType ( ) ;
2948 this . federLayout = new FederLayout ( this . federIndex ) ;
3049 resolve ( ) ;
3150 } ) ;
51+
52+ initLoadingStyle ( ) ;
53+ }
54+ initDom ( ) {
55+ const { width = 800 , height = 480 } = this . viewParams ;
56+ const node = d3
57+ . create ( 'div' )
58+ . style ( 'position' , 'relative' )
59+ . style ( 'width' , width + 'px' )
60+ . style ( 'height' , height + 'px' )
61+ . node ( ) ;
62+ renderLoading ( node , width , height ) ;
63+ return node ;
64+ }
65+ overview ( ) {
66+ const node = this . initDom ( ) ;
67+
68+ this . executeAction ( node , EActionType . overview ) ;
69+
70+ return node ;
71+ }
72+ search ( target : TVec = null , targetMedia : string = null ) {
73+ const node = this . initDom ( ) ;
74+
75+ this . executeAction ( node , EActionType . search , {
76+ target,
77+ targetMedia,
78+ searchParams : this . searchParams ,
79+ } ) ;
80+
81+ return node ;
82+ }
83+
84+ executeAction (
85+ node : HTMLElement ,
86+ actionType : EActionType ,
87+ actionData : TAcitonData = null
88+ ) {
89+ new Promise < void > ( async ( resolve ) => {
90+ await this . initFederPromise ;
91+ const visData = await this . federLayout . getVisData ( {
92+ actionType,
93+ actionData,
94+ viewType : this . viewType ,
95+ layoutParams : this . viewParams ,
96+ } ) ;
97+ const federView = new FederView ( visData , this . viewParams ) ;
98+ ( node as any ) . federView = federView ;
99+ finishLoading ( node ) ;
100+ node . appendChild ( federView . node ) ;
101+ federView . render ( ) ;
102+
103+ resolve ( ) ;
104+ } ) ;
105+
106+ if ( this . domSelector ) {
107+ const container = d3 . select ( this . domSelector ) ;
108+ // container.selectAll('*').remove();
109+ ( container . node ( ) as HTMLElement ) . appendChild ( node ) ;
110+ }
32111 }
33- overview ( ) { }
34- search ( target : TVec = null , targetContent : string = null ) { }
35112 searchById ( id : TId ) { }
36113 searchByRandTestVec ( ) { }
37- setSearchParams ( params : TSearchParams ) { }
114+ setSearchParams ( params : TSearchParams ) {
115+ this . searchParams = params ;
116+ }
38117}
118+
119+ export default Feder ;
0 commit comments