Skip to content

Commit 654d98f

Browse files
committed
update and improve comments for organizeAxTree and populateAxTree functions
1 parent 6b930ef commit 654d98f

File tree

1 file changed

+11
-6
lines changed
  • src/app/components/StateRoute/AxMap

1 file changed

+11
-6
lines changed

src/app/components/StateRoute/AxMap/Ax.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,22 @@ export default function AxTree(props) {
112112
// root node of currAxSnapshot
113113
const rootAxNode = JSON.parse(JSON.stringify(currAxSnapshot[0]));
114114

115-
// 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
116116
const nodeAxArr = [];
117117

118118
// populates ax nodes with children property; visx recognizes 'children' in order to properly render a nested tree
119119
const organizeAxTree = (currNode, currAxSnapshot) => {
120+
// checks if current ax node has children nodes through childId
120121
if (currNode.childIds && currNode.childIds.length > 0) {
122+
// if yes, add children property to current ax node
121123
currNode.children = [];
122124
for (let j = 0; j < currAxSnapshot.length; j++) {
125+
// locate ax node associated with childId
123126
for (const childEle of currNode.childIds) {
124127
if (childEle === currAxSnapshot[j].nodeId) {
128+
// store ax node in children array
125129
currNode.children.push(currAxSnapshot[j]);
130+
// recursively call organizeAxTree with child ax node passed in to check for further nested children nodes
126131
organizeAxTree(currAxSnapshot[j], currAxSnapshot);
127132
}
128133
}
@@ -132,18 +137,18 @@ export default function AxTree(props) {
132137

133138
organizeAxTree(rootAxNode, currAxSnapshot);
134139

135-
// stores each individual ax node with populated children property
140+
// stores each individual ax node with populated children property in array
136141
const populateNodeAxArr = (currNode) => {
137142
nodeAxArr.splice(0, nodeAxArr.length);
138143
nodeAxArr.push(currNode);
139144
for (let i = 0; i < nodeAxArr.length; i += 1) {
140-
// iterate through the nodeList that contains our snapshot
145+
// iterate through the nodeAxArr that contains the root ax node
141146
const cur = nodeAxArr[i];
142147
if (cur.children && cur.children.length > 0) {
143-
// if the currently itereated snapshot has non-zero children...
148+
// if the current ax node evaluated has non-zero children...
144149
for (const child of cur.children) {
145-
// iterate through each child in the children array
146-
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
147152
}
148153
}
149154
}

0 commit comments

Comments
 (0)