@@ -16,6 +16,10 @@ export class TipInfo {
16
16
is_tip : boolean ;
17
17
}
18
18
19
+ class history {
20
+ vertices : Array < Vertex > ;
21
+ }
22
+
19
23
const vertexSize = 20 ;
20
24
21
25
export class VisualizerStore {
@@ -24,7 +28,7 @@ export class VisualizerStore {
24
28
@observable solid_count = 0 ;
25
29
@observable tips_count = 0 ;
26
30
verticesIncomingOrder = [ ] ;
27
- collect : boolean = false ;
31
+ draw : boolean = false ;
28
32
routerStore : RouterStore ;
29
33
30
34
// the currently selected vertex via hover
@@ -45,8 +49,22 @@ export class VisualizerStore {
45
49
46
50
constructor ( routerStore : RouterStore ) {
47
51
this . routerStore = routerStore ;
52
+ this . fetchHistory ( ) ;
48
53
registerHandler ( WSMsgType . Vertex , this . addVertex ) ;
49
- registerHandler ( WSMsgType . TipInfo , this . addTipInfo ) ;
54
+ registerHandler ( WSMsgType . TipInfo , this . addTipInfo ) ;
55
+ }
56
+
57
+ fetchHistory = async ( ) => {
58
+ try {
59
+ let res = await fetch ( `/api/visualizer/history` ) ;
60
+ let history : history = await res . json ( ) ;
61
+ history . vertices . forEach ( v => {
62
+ this . addVertex ( v ) ;
63
+ } ) ;
64
+ } catch ( err ) {
65
+ console . log ( "Fail to fetch history in visualizer" , err ) ;
66
+ }
67
+ return
50
68
}
51
69
52
70
@action
@@ -87,9 +105,7 @@ export class VisualizerStore {
87
105
}
88
106
89
107
@action
90
- addVertex = ( vert : Vertex ) => {
91
- if ( ! this . collect ) return ;
92
-
108
+ addVertex = ( vert : Vertex ) => {
93
109
let existing = this . vertices . get ( vert . id ) ;
94
110
if ( existing ) {
95
111
// can only go from unsolid to solid
@@ -108,35 +124,16 @@ export class VisualizerStore {
108
124
}
109
125
this . verticesIncomingOrder . push ( vert . id ) ;
110
126
this . checkLimit ( ) ;
111
-
112
- if ( vert . strongParentIDs ) {
113
- // clear tip status of strong and weak parents
114
- vert . strongParentIDs . forEach ( ( value , index ) => {
115
- let strongParentVert = this . vertices . get ( value ) ;
116
- if ( strongParentVert ) {
117
- strongParentVert . is_tip = false ;
118
- this . vertices . set ( strongParentVert . id , strongParentVert )
119
- }
120
- } ) ;
121
- }
122
- if ( vert . weakParentIDs ) {
123
- vert . weakParentIDs . forEach ( ( value , index ) => {
124
- let weakParentVert = this . vertices . get ( value ) ;
125
- if ( weakParentVert ) {
126
- weakParentVert . is_tip = false ;
127
- this . vertices . set ( weakParentVert . id , weakParentVert )
128
- }
129
- } ) ;
130
- }
131
127
}
132
128
133
129
this . vertices . set ( vert . id , vert ) ;
134
- this . drawVertex ( vert ) ;
130
+ if ( this . draw ) {
131
+ this . drawVertex ( vert ) ;
132
+ }
135
133
} ;
136
134
137
135
@action
138
136
addTipInfo = ( tipInfo : TipInfo ) => {
139
- if ( ! this . collect ) return ;
140
137
let vert = this . vertices . get ( tipInfo . id ) ;
141
138
if ( ! vert ) {
142
139
// create a new empty one for now
@@ -148,7 +145,9 @@ export class VisualizerStore {
148
145
this . tips_count += tipInfo . is_tip ? 1 : vert . is_tip ? - 1 : 0 ;
149
146
vert . is_tip = tipInfo . is_tip ;
150
147
this . vertices . set ( vert . id , vert ) ;
151
- this . drawVertex ( vert ) ;
148
+ if ( this . draw ) {
149
+ this . drawVertex ( vert ) ;
150
+ }
152
151
} ;
153
152
154
153
@action
@@ -161,7 +160,9 @@ export class VisualizerStore {
161
160
this . clearSelected ( ) ;
162
161
}
163
162
this . vertices . delete ( deleteId ) ;
164
- this . graph . removeNode ( deleteId ) ;
163
+ if ( this . draw ) {
164
+ this . graph . removeNode ( deleteId ) ;
165
+ }
165
166
if ( ! vert ) {
166
167
continue ;
167
168
}
@@ -198,7 +199,9 @@ export class VisualizerStore {
198
199
}
199
200
this . vertices . delete ( approveeId ) ;
200
201
}
201
- this . graph . removeNode ( approveeId ) ;
202
+ if ( this . draw ) {
203
+ this . graph . removeNode ( approveeId ) ;
204
+ }
202
205
}
203
206
204
207
drawVertex = ( vert : Vertex ) => {
@@ -243,7 +246,7 @@ export class VisualizerStore {
243
246
}
244
247
245
248
start = ( ) => {
246
- this . collect = true ;
249
+ this . draw = true ;
247
250
this . graph = Viva . Graph . graph ( ) ;
248
251
249
252
let graphics : any = Viva . Graph . View . webglGraphics ( ) ;
@@ -280,17 +283,18 @@ export class VisualizerStore {
280
283
} ) ;
281
284
this . graphics = graphics ;
282
285
this . renderer . run ( ) ;
286
+
287
+ this . vertices . forEach ( ( vertex ) => {
288
+ this . drawVertex ( vertex )
289
+ } )
283
290
}
284
291
285
292
stop = ( ) => {
286
- this . collect = false ;
293
+ this . draw = false ;
287
294
this . renderer . dispose ( ) ;
288
295
this . graph = null ;
289
296
this . paused = false ;
290
297
this . selected = null ;
291
- this . solid_count = 0 ;
292
- this . tips_count = 0 ;
293
- this . vertices . clear ( ) ;
294
298
}
295
299
296
300
@action
0 commit comments