@@ -9,6 +9,13 @@ import {
9
9
EuiIcon ,
10
10
} from '@elastic/eui'
11
11
12
+ import {
13
+ EDGE_COLOR_BODY_DARK ,
14
+ EDGE_COLOR_BODY_LIGHT ,
15
+ NODE_COLOR_BODY_DARK ,
16
+ NODE_COLOR_BODY_LIGHT ,
17
+ } from './constants'
18
+
12
19
import {
13
20
CoreType ,
14
21
ModuleType ,
@@ -31,6 +38,14 @@ function getEdgeSize(c: number) {
31
38
return Math . floor ( Math . log ( c || 1 ) + 1 )
32
39
}
33
40
41
+ function getNodeColor ( isDarkTheme : boolean ) {
42
+ return isDarkTheme ? NODE_COLOR_BODY_DARK : NODE_COLOR_BODY_LIGHT
43
+ }
44
+
45
+ function getEdgeColor ( isDarkTheme : boolean ) {
46
+ return isDarkTheme ? EDGE_COLOR_BODY_DARK : EDGE_COLOR_BODY_LIGHT
47
+ }
48
+
34
49
export default function Explain ( props : IExplain ) : JSX . Element {
35
50
const command = props . command . split ( ' ' ) [ 0 ] . toLowerCase ( )
36
51
@@ -126,7 +141,6 @@ function ExplainDraw({data, type, module, profilingTime}: {data: any, type: Core
126
141
127
142
const [ done , setDone ] = useState ( false )
128
143
const [ collapse , setCollapse ] = useState ( true )
129
- const [ infoWidth , setInfoWidth ] = useState ( document . body . offsetWidth )
130
144
const [ isFullScreen , setIsFullScreen ] = useState ( false )
131
145
const [ core , setCore ] = useState < Graph > ( )
132
146
@@ -152,7 +166,6 @@ function ExplainDraw({data, type, module, profilingTime}: {data: any, type: Core
152
166
core ?. resize ( width , ( b ?. height || 585 ) + 100 )
153
167
}
154
168
}
155
- setInfoWidth ( width )
156
169
}
157
170
158
171
window . addEventListener ( 'resize' , resize )
@@ -185,16 +198,41 @@ function ExplainDraw({data, type, module, profilingTime}: {data: any, type: Core
185
198
ancestors . pairs . forEach ( p => {
186
199
// Highlight ancestor and their ancestor
187
200
document . querySelector ( `#node-${ p [ 0 ] } ` ) ?. setAttribute ( "style" , "outline: 1px solid #85A2FE !important;" )
188
-
189
201
// Get edge size of parent ancestor to apply the right edge stroke
190
- const strokeSize = getEdgeSize ( parseInt ( ( document . querySelector ( `#node-${ p [ 1 ] } ` ) as HTMLElement ) ?. dataset ?. size || '' ) ) + 1
191
- document . querySelector ( `[data-cell-id='${ p [ 0 ] } -${ p [ 1 ] } ']` ) ?. childNodes . forEach ( k =>
192
- ( k as HTMLElement )
193
- . setAttribute (
194
- "style" ,
195
- `stroke: #85A2FE; stroke-linecap: butt; stroke-width: ${ strokeSize } px`
196
- )
197
- )
202
+ const edge = graph . getCellById ( `${ p [ 0 ] } -${ p [ 1 ] } ` )
203
+ const edgeColor = '#85A2FE'
204
+ edge . setAttrs ( {
205
+ line : {
206
+ stroke : edgeColor ,
207
+ strokeWidth : ( edge . getAttrs ( ) as any ) ?. line ?. strokeWidth ,
208
+ targetMarker : {
209
+ name : 'block' ,
210
+ stroke : edgeColor ,
211
+ fill : edgeColor ,
212
+ } ,
213
+ } ,
214
+ } )
215
+ } )
216
+ } )
217
+
218
+ graph . on ( "node:mouseleave" , x => {
219
+ const { id} = x . node . getData ( )
220
+ const ancestors = GetAncestors ( data , id , { found : false , pairs : [ ] } )
221
+ ancestors . pairs . forEach ( p => {
222
+ document . querySelector ( `#node-${ p [ 0 ] } ` ) ?. setAttribute ( "style" , "" )
223
+ const edge = graph . getCellById ( `${ p [ 0 ] } -${ p [ 1 ] } ` )
224
+ const edgeColor = getEdgeColor ( isDarkTheme )
225
+ edge . setAttrs ( {
226
+ line : {
227
+ stroke : edgeColor ,
228
+ strokeWidth : ( edge . getAttrs ( ) as any ) ?. line ?. strokeWidth ,
229
+ targetMarker : {
230
+ name : 'block' ,
231
+ fill : edgeColor ,
232
+ stroke : edgeColor ,
233
+ }
234
+ } ,
235
+ } )
198
236
} )
199
237
} )
200
238
@@ -237,15 +275,6 @@ function ExplainDraw({data, type, module, profilingTime}: {data: any, type: Core
237
275
238
276
ele ?. addEventListener ( 'mousedown' , mouseDownHandler )
239
277
240
- graph . on ( "node:mouseleave" , x => {
241
- const { id} = x . node . getData ( )
242
- const ancestors = GetAncestors ( data , id , { found : false , pairs : [ ] } )
243
- ancestors . pairs . forEach ( p => {
244
- document . querySelector ( `#node-${ p [ 0 ] } ` ) ?. setAttribute ( "style" , "" )
245
- document . querySelector ( `[data-cell-id='${ p [ 0 ] } -${ p [ 1 ] } ']` ) ?. childNodes . forEach ( k => ( k as HTMLElement ) . setAttribute ( "style" , "" ) )
246
- } )
247
- } )
248
-
249
278
resize ( )
250
279
251
280
const result = Hierarchy . compactBox ( data , {
@@ -297,6 +326,20 @@ function ExplainDraw({data, type, module, profilingTime}: {data: any, type: Core
297
326
}
298
327
299
328
329
+ const portId = data . id + '-source'
330
+ let targetPort = { }
331
+ const targetItem : any = [ ]
332
+ if ( info . parentId ) {
333
+ targetItem . push ( { id : `${ info . id } -${ info . parentId } -target` , group : `${ info . parentId } -target` } )
334
+ targetPort [ info . parentId + '-target' ] = {
335
+ position : { name : 'bottom' } ,
336
+ attrs : {
337
+ circle : {
338
+ r : 0
339
+ }
340
+ }
341
+ }
342
+ }
300
343
model . nodes ?. push ( {
301
344
id : data . id ,
302
345
x : ( data . x || 0 ) + document . body . clientWidth / 2 ,
@@ -305,20 +348,45 @@ function ExplainDraw({data, type, module, profilingTime}: {data: any, type: Core
305
348
data : info ,
306
349
attrs : {
307
350
body : {
308
- fill : isDarkTheme ? '#5F95FF' : '#8992B3' ,
351
+ fill : getNodeColor ( isDarkTheme ) ,
309
352
stroke : 'transparent' ,
310
353
} ,
311
354
} ,
355
+ ports : {
356
+ groups : {
357
+ [ portId ] : {
358
+ position : { name : 'top' } ,
359
+ attrs : {
360
+ circle : {
361
+ r : 0
362
+ }
363
+ }
364
+ } ,
365
+ ...targetPort ,
366
+ } ,
367
+ items : [
368
+ ...data . children . map ( c => ( {
369
+ id : `${ data . id } -${ c . id } ` , group : portId
370
+ } ) ) ,
371
+ ...targetItem ,
372
+ ] ,
373
+ } ,
312
374
} )
313
375
}
314
376
if ( data . children ) {
315
377
data . children . forEach ( ( item : any ) => {
316
378
const itemRecords = parseInt ( item . data . counter || 0 )
317
-
379
+ const edgeColor = getEdgeColor ( isDarkTheme )
318
380
model . edges ?. push ( {
319
381
id : `${ data . id } -${ item . id } ` ,
320
- source : data . id ,
321
- target : item . id ,
382
+ source : {
383
+ cell : data . id ,
384
+ port : `${ data . id } -${ item . id } ` ,
385
+ } ,
386
+ target : {
387
+ cell : item . id ,
388
+ port : `${ data . id } -${ item . id } `
389
+ } ,
322
390
router : {
323
391
name : 'manhattan' ,
324
392
args : {
@@ -336,9 +404,13 @@ function ExplainDraw({data, type, module, profilingTime}: {data: any, type: Core
336
404
} ,
337
405
attrs : {
338
406
line : {
339
- stroke : isDarkTheme ? '#6B6B6B' : '#8992B3' ,
407
+ stroke : edgeColor ,
340
408
strokeWidth : getEdgeSize ( itemRecords ) ,
341
- targetMarker : null ,
409
+ targetMarker : {
410
+ name : 'block' ,
411
+ fill : edgeColor ,
412
+ stroke : edgeColor ,
413
+ } ,
342
414
} ,
343
415
} ,
344
416
} )
@@ -364,7 +436,14 @@ function ExplainDraw({data, type, module, profilingTime}: {data: any, type: Core
364
436
return (
365
437
< div >
366
438
{ collapse && < div style = { { paddingTop : '50px' } } > </ div > }
367
- < div id = "container-parent" style = { { height : isFullScreen ? ( window . outerHeight - 170 ) + 'px' : collapse ? '500px' : '585px' , width : '100%' , overflow : 'auto' } } >
439
+ < div
440
+ id = "container-parent"
441
+ style = { {
442
+ height : isFullScreen ? ( window . outerHeight - 170 ) + 'px' : collapse ? '500px' : '585px' ,
443
+ width : '100%' ,
444
+ overflow : 'auto' ,
445
+ } }
446
+ >
368
447
< div style = { { margin : 0 , width : '100vw' } } ref = { container } id = "container" />
369
448
{ ! collapse && (
370
449
< div className = "ZoomMenu" >
0 commit comments