@@ -195,45 +195,99 @@ export default function AxTree(props) {
195
195
const LinkComponent = getLinkComponent ( { layout, linkType, orientation } ) ;
196
196
197
197
const currAxSnapshot = JSON . parse ( JSON . stringify ( axSnapshots [ currLocation . index ] ) ) ;
198
+ console . log ( 'currAxSnapshot: ' , currAxSnapshot ) ;
198
199
199
200
// root node of currAxSnapshot
200
201
const rootAxNode = JSON . parse ( JSON . stringify ( currAxSnapshot [ 0 ] ) ) ;
201
202
202
203
// // array that holds the ax tree as a nested object and the root node initially
203
204
const nodeAxArr = [ ] ;
204
205
206
+ // code handling the initial root case / if there is only 1 child
207
+ // condition checking if the last node added has childIds length > 0
208
+
209
+ // function to handle nesting past the root node
205
210
// const organizeAxTree = (currNode, currAxSnapshot) => {
206
211
// for (let i = 0; i < currNode.length; i++) {
207
- // if (currNode.childIds.length > 0) {
208
- // currNode.children = [];
212
+ // if (currNode[i] .childIds.length > 0) {
213
+ // currNode[i] .children = [];
209
214
210
215
// for (let j = 0; j < currAxSnapshot.length; j++) {
211
216
212
- // if (currNode.childIds.includes(currAxSnapshot[j].nodeId)) {
213
- // currNode.children.push(currAxSnapshot[j]);
217
+ // if (currNode[i] .childIds.includes(currAxSnapshot[j].nodeId)) {
218
+ // currNode[i] .children.push(currAxSnapshot[j]);
214
219
215
- // organizeAxTree(currNode.children, currAxSnapshot);
220
+ // organizeAxTree(currNode[i] .children, currAxSnapshot);
216
221
// }
217
222
// }
218
223
// }
219
224
// }
220
225
// }
221
-
222
226
// organizeAxTree(nodeAxArr, currAxSnapshot);
223
227
228
+ // const organizeAxTree = (currNodeArr, currAxSnapshot, i = 0) => {
229
+ // console.log('currNode: ', currNodeArr);
230
+ // // handles each child node within the children property
231
+ // while (currNodeArr[i]) {
232
+ // if (currNodeArr[i].childIds) {
233
+ // currNodeArr[i].children = [];
234
+ // // iterate through every snapshot in currAxSnapshot
235
+ // for (let j = 0; j < currAxSnapshot.length; j++) {
236
+ // // includes does not have good time complexity, can convert to nested for or for of loop
237
+ // for (const childEle of currNodeArr[i].childIds) {
238
+ // if (childEle === currAxSnapshot[j].nodeId) {
239
+ // currNodeArr[i].children.push(currAxSnapshot[j]);
240
+ // }
241
+ // }
242
+ // }
243
+ // }
244
+ // i++;
245
+ // }
246
+ // i = 0;
247
+ // organizeAxTree(currNodeArr[i].children, currAxSnapshot);
248
+ // }
249
+
250
+ // if (currNode.childIds) {
251
+ // currNode.children = [];
252
+ // // checks if there is more than 1 child
253
+ // if (currNode.childIds.length > 1) {
254
+ // for (let m = 0; m < currNode.childIds.length; m++) {
255
+ // for (let j = 0; j < currAxSnapshot.length; j++) {
256
+ // if (currNode.childIds.includes(currAxSnapshot[j].nodeId)) {
257
+ // currNode.children.push(currAxSnapshot[j]);
258
+ // }
259
+ // }
260
+ // }
261
+ // } else if (currNode.childIds.length === 1) {
262
+ // for (let j = 0; j < currAxSnapshot.length; j++) {
263
+ // if (currNode.childIds.includes(currAxSnapshot[j].nodeId)) {
264
+ // currNode.children.push(currAxSnapshot[j]);
265
+ // }
266
+ // }
267
+ // organizeAxTree(currNode.children[0], currAxSnapshot);
268
+ // }
269
+ // organizeAxTree(currNode.children, currAxSnapshot);
270
+ // }
271
+
272
+ // organizeAxTree([rootAxNode], currAxSnapshot);
224
273
const organizeAxTree = ( currNode , currAxSnapshot ) => {
225
274
if ( currNode . childIds && currNode . childIds . length > 0 ) {
226
275
currNode . children = [ ] ;
227
276
for ( let j = 0 ; j < currAxSnapshot . length ; j ++ ) {
228
- if ( currNode . childIds . includes ( currAxSnapshot [ j ] . nodeId ) ) {
229
- currNode . children . push ( currAxSnapshot [ j ] ) ;
230
- organizeAxTree ( currAxSnapshot [ j ] , currAxSnapshot ) ;
277
+ for ( const childEle of currNode . childIds ) {
278
+ if ( childEle === currAxSnapshot [ j ] . nodeId ) {
279
+ currNode . children . push ( currAxSnapshot [ j ] ) ;
280
+ organizeAxTree ( currAxSnapshot [ j ] , currAxSnapshot ) ;
281
+ }
231
282
}
283
+
232
284
}
233
285
}
234
286
}
235
287
236
288
organizeAxTree ( rootAxNode , currAxSnapshot ) ;
289
+
290
+ console . log ( 'rootAxNode: ' , rootAxNode ) ;
237
291
238
292
// store each individual node, now with children property in nodeAxArr
239
293
// need to consider order, iterate through the children property first?
@@ -255,7 +309,6 @@ export default function AxTree(props) {
255
309
256
310
populateNodeAxArr ( rootAxNode ) ;
257
311
console . log ( 'nodeAxArr: ' , nodeAxArr ) ;
258
- console . log ( 'rootAxNode: ' , rootAxNode ) ;
259
312
260
313
return totalWidth < 10 ? null : (
261
314
< div >
@@ -282,7 +335,7 @@ export default function AxTree(props) {
282
335
/>
283
336
< Group transform = { `scale(${ aspect } )` } top = { margin . top } left = { margin . left } >
284
337
< Tree
285
- root = { hierarchy ( nodeAxArr [ 1 ] , ( d ) => ( d . isExpanded ? null : d . children ) ) }
338
+ root = { hierarchy ( nodeAxArr [ 0 ] , ( d ) => ( d . isExpanded ? null : d . children ) ) }
286
339
size = { [ sizeWidth / aspect , sizeHeight / aspect ] }
287
340
separation = { ( a , b ) => ( a . parent === b . parent ? 0.5 : 0.5 ) / a . depth }
288
341
>
@@ -306,7 +359,7 @@ export default function AxTree(props) {
306
359
//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)
307
360
if ( nodeLength <= 5 ) return nodeLength + 50 ;
308
361
if ( nodeLength <= 10 ) return nodeLength + 120 ;
309
- return nodeLength + 140 ;
362
+ return nodeLength + 180 ;
310
363
} ;
311
364
312
365
const width : number = widthFunc ( node . data . name . value ) ; // the width is determined by the length of the node.name
0 commit comments