@@ -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 ;
@@ -243,16 +112,22 @@ export default function AxTree(props) {
243
112
// root node of currAxSnapshot
244
113
const rootAxNode = JSON . parse ( JSON . stringify ( currAxSnapshot [ 0 ] ) ) ;
245
114
246
- // // 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
247
116
const nodeAxArr = [ ] ;
248
117
118
+ // populates ax nodes with children property; visx recognizes 'children' in order to properly render a nested tree
249
119
const organizeAxTree = ( currNode , currAxSnapshot ) => {
120
+ // checks if current ax node has children nodes through childId
250
121
if ( currNode . childIds && currNode . childIds . length > 0 ) {
122
+ // if yes, add children property to current ax node
251
123
currNode . children = [ ] ;
252
124
for ( let j = 0 ; j < currAxSnapshot . length ; j ++ ) {
125
+ // locate ax node associated with childId
253
126
for ( const childEle of currNode . childIds ) {
254
127
if ( childEle === currAxSnapshot [ j ] . nodeId ) {
128
+ // store ax node in children array
255
129
currNode . children . push ( currAxSnapshot [ j ] ) ;
130
+ // recursively call organizeAxTree with child ax node passed in to check for further nested children nodes
256
131
organizeAxTree ( currAxSnapshot [ j ] , currAxSnapshot ) ;
257
132
}
258
133
}
@@ -262,27 +137,26 @@ export default function AxTree(props) {
262
137
263
138
organizeAxTree ( rootAxNode , currAxSnapshot ) ;
264
139
265
- // store each individual node, now with children property in nodeAxArr
266
- // need to consider order, iterate through the children property first?
140
+ // stores each individual ax node with populated children property in array
267
141
const populateNodeAxArr = ( currNode ) => {
268
142
nodeAxArr . splice ( 0 , nodeAxArr . length ) ;
269
143
nodeAxArr . push ( currNode ) ;
270
144
for ( let i = 0 ; i < nodeAxArr . length ; i += 1 ) {
271
- // iterate through the nodeList that contains our snapshot
145
+ // iterate through the nodeAxArr that contains the root ax node
272
146
const cur = nodeAxArr [ i ] ;
273
147
if ( cur . children && cur . children . length > 0 ) {
274
- // if the currently itereated snapshot has non-zero children...
148
+ // if the current ax node evaluated has non-zero children...
275
149
for ( const child of cur . children ) {
276
- // iterate through each child in the children array
277
- 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
278
152
}
279
153
}
280
154
}
281
155
} ;
282
156
283
157
populateNodeAxArr ( rootAxNode ) ;
284
158
285
- // ax Legend
159
+ // Conditionally render ax legend component (RTK)
286
160
const { axLegendButtonClicked } = useSelector ( ( state : RootState ) => state . axLegend ) ;
287
161
const dispatch = useDispatch ( ) ;
288
162
@@ -305,7 +179,6 @@ export default function AxTree(props) {
305
179
</ button >
306
180
</ div >
307
181
308
- { /* svg references purple background */ }
309
182
< svg ref = { containerRef } width = { totalWidth + 0.2 * totalWidth } height = { totalHeight } >
310
183
< LinearGradient id = 'root-gradient' from = '#488689' to = '#3c6e71' />
311
184
< LinearGradient id = 'parent-gradient' from = '#488689' to = '#3c6e71' />
@@ -338,9 +211,8 @@ export default function AxTree(props) {
338
211
// code relating to each node in tree
339
212
{ tree . descendants ( ) . map ( ( node , key ) => {
340
213
const widthFunc = ( name ) : number => {
341
- //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.
342
215
const nodeLength = name . length ;
343
- //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)
344
216
if ( nodeLength <= 5 ) return nodeLength + 60 ;
345
217
if ( nodeLength <= 10 ) return nodeLength + 130 ;
346
218
return nodeLength + 160 ;
@@ -524,7 +396,6 @@ export default function AxTree(props) {
524
396
fontFamily = 'Roboto'
525
397
textAnchor = 'middle'
526
398
style = { { pointerEvents : 'none' } }
527
- //fill={node.depth === 0 ? '#161521' : node.children ? 'white' : '#161521'}
528
399
>
529
400
{ node . data . name . value }
530
401
</ text >
@@ -568,6 +439,7 @@ export default function AxTree(props) {
568
439
</ div >
569
440
</ TooltipInPortal >
570
441
) }
442
+
571
443
< div >
572
444
{ axLegendButtonClicked ?
573
445
< AxLegend /> : ''
0 commit comments