Skip to content

Commit 970dd04

Browse files
committed
converted root node from a circle to a rectangle shape
1 parent 7c37f56 commit 970dd04

File tree

1 file changed

+16
-29
lines changed
  • src/app/components/StateRoute/AxMap

1 file changed

+16
-29
lines changed

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

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ const data: TreeNode = {
7676
}],
7777
};
7878

79-
const dataArray = [
79+
const nodeAxArr = [
8080
{
8181
name: {
8282
sources: [{attribute: 'aria-labelledby', type: 'relatedElement'}],
@@ -128,8 +128,6 @@ const dataArray = [
128128
}
129129
]
130130

131-
const startNode: TreeNode = dataArray[0];
132-
133131
const defaultMargin = {
134132
top: 30,
135133
left: 30,
@@ -223,22 +221,6 @@ export default function AxTree(props) {
223221

224222
// organizeAxTree(nodeAxArr, currAxSnapshot);
225223

226-
227-
// attempted refactored organizeAxTree
228-
// const organizeAxTree2 = (currNode, currAxSnapshot) => {
229-
// console.log('currNode: ', currNode);
230-
// if (currNode.childIds.length > 0) {
231-
// currNode.children = [];
232-
// for (let j = 0; j < currAxSnapshot.length; j++) {
233-
// if (currNode.childIds.includes(currAxSnapshot[j].nodeId)) {
234-
// currNode.children.push(currAxSnapshot[j]);
235-
// organizeAxTree2(currNode.children, currAxSnapshot);
236-
// }
237-
// }
238-
// }
239-
// }
240-
// organizeAxTree2(rootAxNode, currAxSnapshot);
241-
242224
const organizeAxTree = (currNode, currAxSnapshot) => {
243225
if (currNode.childIds && currNode.childIds.length > 0) {
244226
currNode.children = [];
@@ -252,11 +234,11 @@ export default function AxTree(props) {
252234
}
253235

254236
organizeAxTree(rootAxNode, currAxSnapshot);
255-
console.log('nestedAxTree: ', rootAxNode);
256237

257238
// store each individual node, now with children property in nodeAxArr
258239
// need to consider order, iterate through the children property first?
259240
const populateNodeAxArr = (currNode) => {
241+
nodeAxArr.splice(0, nodeAxArr.length);
260242
nodeAxArr.push(currNode);
261243
for (let i = 0; i < nodeAxArr.length; i += 1) {
262244
// iterate through the nodeList that contains our snapshot
@@ -273,6 +255,7 @@ export default function AxTree(props) {
273255

274256
populateNodeAxArr(rootAxNode);
275257
console.log('nodeAxArr: ', nodeAxArr);
258+
console.log('rootAxNode: ', rootAxNode);
276259

277260
return totalWidth < 10 ? null : (
278261
<div>
@@ -299,7 +282,7 @@ export default function AxTree(props) {
299282
/>
300283
<Group transform={`scale(${aspect})`} top={margin.top} left={margin.left}>
301284
<Tree
302-
root={hierarchy(startNode, (d) => (d.isExpanded ? null : d.children))}
285+
root={hierarchy(nodeAxArr[1], (d) => (d.isExpanded ? null : d.children))}
303286
size={[sizeWidth / aspect, sizeHeight / aspect]}
304287
separation={(a, b) => (a.parent === b.parent ? 0.5 : 0.5) / a.depth}
305288
>
@@ -333,8 +316,6 @@ export default function AxTree(props) {
333316

334317
if (layout === 'polar') {
335318
const [radialX, radialY] = pointRadial(node.x, node.y);
336-
console.log('ax tree, radial x y', radialX, radialY);
337-
console.log('ax tree node.x, node.y:', node.x, node.y);
338319
top = radialY;
339320
left = radialX;
340321
} else if (orientation === 'vertical') {
@@ -346,14 +327,14 @@ export default function AxTree(props) {
346327
}
347328

348329
//setup a nodeCoords Object that will have keys of unique y coordinates and value arrays of all the left and right x coordinates of the nodes on that level
349-
count < dataArray.length
330+
count < nodeAxArr.length
350331
? !nodeCoords[top]
351332
? (nodeCoords[top] = [left - width / 2, left + width / 2])
352333
: nodeCoords[top].push(left - width / 2, left + width / 2)
353334
: null;
354335
count++;
355336

356-
if (count === dataArray.length) {
337+
if (count === nodeAxArr.length) {
357338
//check if there is still a tier of the node tree to collision check
358339
while (Object.values(nodeCoords)[nodeCoordTier]) {
359340
//check if there are atleast two nodes on the current tier
@@ -415,10 +396,16 @@ export default function AxTree(props) {
415396
return (
416397
<Group top={top} left={left} key={key} className='rect'>
417398
{node.depth === 0 && (
418-
<circle
419-
className='compMapRoot'
420-
r={25}
421-
fill="url('#root-gradient')"
399+
<rect
400+
className={node.children ? 'compMapParent' : 'compMapChild'}
401+
height={height}
402+
width={width}
403+
y={-height / 2}
404+
x={-width / 2}
405+
fill="url('#parent-gradient')"
406+
strokeWidth={1.5}
407+
strokeOpacity='1'
408+
rx={node.children ? 4 : 10}
422409
onClick={() => {
423410
node.data.isExpanded = !node.data.isExpanded;
424411
}}

0 commit comments

Comments
 (0)