@@ -14,135 +14,6 @@ import AxLegend from './axLegend';
14
14
import { renderAxLegend } from '../../../slices/AxSlices/axLegendSlice' ;
15
15
import type { RootState } from '../../../store' ;
16
16
17
- //still using below themes?
18
- const theme = {
19
- scheme : 'monokai' ,
20
- author : 'wimer hazenberg (http://www.monokai.nl)' ,
21
- base00 : '#272822' ,
22
- base01 : '#383830' ,
23
- base02 : '#49483e' ,
24
- base03 : '#75715e' ,
25
- base04 : '#a59f85' ,
26
- base05 : '#f8f8f2' ,
27
- base06 : '#f5f4f1' ,
28
- base07 : '#f9f8f5' ,
29
- base08 : '#f92672' ,
30
- base09 : '#fd971f' ,
31
- base0A : '#f4bf75' ,
32
- base0B : '#a6e22e' ,
33
- base0C : '#a1efe4' ,
34
- base0D : '#66d9ef' ,
35
- base0E : '#ae81ff' ,
36
- base0F : '#cc6633' ,
37
- } ;
38
-
39
- interface TreeNode {
40
- name ?: {
41
- sources ?: any [ ] ;
42
- type ?: string ;
43
- value ?: string ;
44
- } ;
45
- isExpanded ?: boolean ;
46
- children ?: TreeNode [ ] ;
47
- backendDOMNodeId ?: number ;
48
- childIds ?: string [ ] ;
49
- ignored ?: boolean ;
50
- nodeId ?: string ;
51
- ignoredReasons ?: any [ ] ;
52
- }
53
-
54
- // example data from visx
55
-
56
- // pulling name property value to name the node, need to adjust data pull from ax tree to reassign name if the node is ignored
57
-
58
- const data : TreeNode = {
59
- name : {
60
- sources : [ { attribute : 'aria-labelledby' , type : 'relatedElement' } ] ,
61
- type : 'computedString' ,
62
- value : 'Reactime MVP' ,
63
- } ,
64
- backendDOMNodeId : 1 ,
65
- childIds : [ '46' ] ,
66
- ignored : false ,
67
- children : [
68
- {
69
- name : {
70
- sources : [ { attribute : 'aria-labelledby' , type : 'relatedElement' } ] ,
71
- type : 'computedString' ,
72
- value : '' ,
73
- } ,
74
- backendDOMNodeId : 7 ,
75
- childIds : [ '47' ] ,
76
- ignored : true ,
77
- } ,
78
- {
79
- name : {
80
- sources : [ { attribute : 'aria-labelledby' , type : 'relatedElement' } ] ,
81
- type : 'computedString' ,
82
- value : 'Tic-Tac-Toe' ,
83
- } ,
84
- backendDOMNodeId : 8 ,
85
- childIds : [ '48' ] ,
86
- ignored : false ,
87
- } ,
88
- ] ,
89
- } ;
90
-
91
- const nodeAxArr = [
92
- {
93
- name : {
94
- sources : [ { attribute : 'aria-labelledby' , type : 'relatedElement' } ] ,
95
- type : 'computedString' ,
96
- value : 'Reactime MVP' ,
97
- } ,
98
- backendDOMNodeId : 1 ,
99
- childIds : [ '46' ] ,
100
- ignored : false ,
101
- children : [
102
- {
103
- name : {
104
- sources : [ { attribute : 'aria-labelledby' , type : 'relatedElement' } ] ,
105
- type : 'computedString' ,
106
- value : '' ,
107
- } ,
108
- backendDOMNodeId : 7 ,
109
- childIds : [ '47' ] ,
110
- ignored : true ,
111
- } ,
112
- {
113
- name : {
114
- sources : [ { attribute : 'aria-labelledby' , type : 'relatedElement' } ] ,
115
- type : 'computedString' ,
116
- value : 'Tic-Tac-Toe' ,
117
- } ,
118
- backendDOMNodeId : 8 ,
119
- childIds : [ '48' ] ,
120
- ignored : false ,
121
- } ,
122
- ] ,
123
- } ,
124
- {
125
- name : {
126
- sources : [ { attribute : 'aria-labelledby' , type : 'relatedElement' } ] ,
127
- type : 'computedString' ,
128
- value : '' ,
129
- } ,
130
- backendDOMNodeId : 7 ,
131
- childIds : [ '47' ] ,
132
- ignored : true ,
133
- } ,
134
- {
135
- name : {
136
- sources : [ { attribute : 'aria-labelledby' , type : 'relatedElement' } ] ,
137
- type : 'computedString' ,
138
- value : 'Tic-Tac-Toe' ,
139
- } ,
140
- backendDOMNodeId : 8 ,
141
- childIds : [ '48' ] ,
142
- ignored : false ,
143
- } ,
144
- ] ;
145
-
146
17
const defaultMargin = {
147
18
top : 30 ,
148
19
left : 30 ,
@@ -166,8 +37,6 @@ export type LinkTypesProps = {
166
37
export default function AxTree ( props ) {
167
38
const { currLocation, axSnapshots, width, height } = props ;
168
39
169
-
170
-
171
40
let margin = defaultMargin ;
172
41
let totalWidth = width ;
173
42
let totalHeight = height ;
@@ -184,8 +53,6 @@ export default function AxTree(props) {
184
53
hideTooltip, // function to close a tooltip
185
54
} = useTooltip ( ) ; // returns an object with several properties that you can use to manage the tooltip state of your component
186
55
187
- // let nameVal = JSON.stringify(tooltipData)
188
- // console.log('nameVal', nameVal);
189
56
const {
190
57
containerRef, // Access to the container's bounding box. This will be empty on first render.
191
58
TooltipInPortal, // TooltipWithBounds in a Portal, outside of your component DOM tree
@@ -208,14 +75,6 @@ export default function AxTree(props) {
208
75
pointerEvents : 'all !important' ,
209
76
} ;
210
77
211
- // const formatRenderTime = (time: number): string => {
212
- // if (!time) return 'No time information';
213
- // const renderTime = time.toFixed(3);
214
- // return `${renderTime} ms `;
215
- // };
216
-
217
-
218
-
219
78
const [ layout , setLayout ] = useState ( 'cartesian' ) ;
220
79
const [ orientation , setOrientation ] = useState ( 'horizontal' ) ;
221
80
const [ linkType , setLinkType ] = useState ( 'diagonal' ) ;
@@ -253,38 +112,22 @@ export default function AxTree(props) {
253
112
// root node of currAxSnapshot
254
113
const rootAxNode = JSON . parse ( JSON . stringify ( currAxSnapshot [ 0 ] ) ) ;
255
114
256
- // // array that holds the ax tree as a nested object and the root node initially
115
+ // array that holds each ax tree node with children property
257
116
const nodeAxArr = [ ] ;
258
117
259
- // currNode.children = [];
260
- // // checks if there is more than 1 child
261
- // if (currNode.childIds.length > 1) {
262
- // for (let m = 0; m < currNode.childIds.length; m++) {
263
- // for (let j = 0; j < currAxSnapshot.length; j++) {
264
- // if (currNode.childIds.includes(currAxSnapshot[j].nodeId)) {
265
- // currNode.children.push(currAxSnapshot[j]);
266
- // }
267
- // }
268
- // }
269
- // } else if (currNode.childIds.length === 1) {
270
- // for (let j = 0; j < currAxSnapshot.length; j++) {
271
- // if (currNode.childIds.includes(currAxSnapshot[j].nodeId)) {
272
- // currNode.children.push(currAxSnapshot[j]);
273
- // }
274
- // }
275
- // organizeAxTree(currNode.children[0], currAxSnapshot);
276
- // }
277
- // organizeAxTree(currNode.children, currAxSnapshot);
278
- // }
279
-
280
- // organizeAxTree([rootAxNode], currAxSnapshot);
118
+ // populates ax nodes with children property; visx recognizes 'children' in order to properly render a nested tree
281
119
const organizeAxTree = ( currNode , currAxSnapshot ) => {
120
+ // checks if current ax node has children nodes through childId
282
121
if ( currNode . childIds && currNode . childIds . length > 0 ) {
122
+ // if yes, add children property to current ax node
283
123
currNode . children = [ ] ;
284
124
for ( let j = 0 ; j < currAxSnapshot . length ; j ++ ) {
125
+ // locate ax node associated with childId
285
126
for ( const childEle of currNode . childIds ) {
286
127
if ( childEle === currAxSnapshot [ j ] . nodeId ) {
128
+ // store ax node in children array
287
129
currNode . children . push ( currAxSnapshot [ j ] ) ;
130
+ // recursively call organizeAxTree with child ax node passed in to check for further nested children nodes
288
131
organizeAxTree ( currAxSnapshot [ j ] , currAxSnapshot ) ;
289
132
}
290
133
}
@@ -294,27 +137,26 @@ export default function AxTree(props) {
294
137
295
138
organizeAxTree ( rootAxNode , currAxSnapshot ) ;
296
139
297
- // store each individual node, now with children property in nodeAxArr
298
- // need to consider order, iterate through the children property first?
140
+ // stores each individual ax node with populated children property in array
299
141
const populateNodeAxArr = ( currNode ) => {
300
142
nodeAxArr . splice ( 0 , nodeAxArr . length ) ;
301
143
nodeAxArr . push ( currNode ) ;
302
144
for ( let i = 0 ; i < nodeAxArr . length ; i += 1 ) {
303
- // iterate through the nodeList that contains our snapshot
145
+ // iterate through the nodeAxArr that contains the root ax node
304
146
const cur = nodeAxArr [ i ] ;
305
147
if ( cur . children && cur . children . length > 0 ) {
306
- // if the currently itereated snapshot has non-zero children...
148
+ // if the current ax node evaluated has non-zero children...
307
149
for ( const child of cur . children ) {
308
- // iterate through each child in the children array
309
- nodeAxArr . push ( child ) ; // add the child to the nodeList
150
+ // iterate through each child ax node in the children array
151
+ nodeAxArr . push ( child ) ; // add the child to the nodeAxArr
310
152
}
311
153
}
312
154
}
313
155
} ;
314
156
315
157
populateNodeAxArr ( rootAxNode ) ;
316
158
317
- // ax Legend
159
+ // Conditionally render ax legend component (RTK)
318
160
const { axLegendButtonClicked } = useSelector ( ( state : RootState ) => state . axLegend ) ;
319
161
const dispatch = useDispatch ( ) ;
320
162
@@ -337,7 +179,6 @@ export default function AxTree(props) {
337
179
</ button >
338
180
</ div >
339
181
340
- { /* svg references purple background */ }
341
182
< svg ref = { containerRef } width = { totalWidth + 0.2 * totalWidth } height = { totalHeight } >
342
183
< LinearGradient id = 'root-gradient' from = '#488689' to = '#3c6e71' />
343
184
< LinearGradient id = 'parent-gradient' from = '#488689' to = '#3c6e71' />
@@ -370,9 +211,8 @@ export default function AxTree(props) {
370
211
// code relating to each node in tree
371
212
{ tree . descendants ( ) . map ( ( node , key ) => {
372
213
const widthFunc = ( name ) : number => {
373
- //returns a number that is related to the length of the name. Used for determining the node width.
214
+ // returns a number that is related to the length of the name. Used for determining the node width.
374
215
const nodeLength = name . length ;
375
- //return nodeLength * 7 + 20; //uncomment this line if we want each node to be directly proportional to the name.length (instead of nodes of similar sizes to snap to the same width)
376
216
if ( nodeLength <= 5 ) return nodeLength + 60 ;
377
217
if ( nodeLength <= 10 ) return nodeLength + 130 ;
378
218
return nodeLength + 160 ;
@@ -501,13 +341,6 @@ export default function AxTree(props) {
501
341
y = { - height / 2 }
502
342
x = { - width / 2 }
503
343
fill = "url('#parent-gradient')"
504
- //color={'#ff0000'}
505
- //fill={node.children ? nodeParentFill : nodeChildFill}
506
- //stroke={
507
- // node.data.isExpanded && node.data.children.length > 0
508
- // ? nodeParentStroke
509
- // : nodeChildStroke
510
- // }
511
344
strokeWidth = { 1.5 }
512
345
strokeOpacity = '1'
513
346
rx = { node . children ? 4 : 10 }
@@ -563,7 +396,6 @@ export default function AxTree(props) {
563
396
fontFamily = 'Roboto'
564
397
textAnchor = 'middle'
565
398
style = { { pointerEvents : 'none' } }
566
- //fill={node.depth === 0 ? '#161521' : node.children ? 'white' : '#161521'}
567
399
>
568
400
{ node . data . name . value }
569
401
</ text >
@@ -601,13 +433,11 @@ export default function AxTree(props) {
601
433
</ div >
602
434
< div >
603
435
< ToolTipDataDisplay containerName = 'Ax Node Info' dataObj = { tooltipData } />
604
- { /* <ToolTipDataDisplay containerName='State'dataObj={tooltipData}/> */ }
605
436
</ div >
606
437
</ div >
607
438
</ TooltipInPortal >
608
439
) }
609
440
610
- { /* ax Legend */ }
611
441
< div >
612
442
{ axLegendButtonClicked ?
613
443
< AxLegend /> : ''
0 commit comments