Skip to content

Commit e7169c7

Browse files
authored
Merge pull request #24 from oslabs-beta/amy/visualizeAxTree
Amy/visualize ax tree
2 parents ea17dd4 + 654d98f commit e7169c7

File tree

2 files changed

+14
-206
lines changed

2 files changed

+14
-206
lines changed

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

Lines changed: 14 additions & 184 deletions
Original file line numberDiff line numberDiff line change
@@ -14,135 +14,6 @@ import AxLegend from './axLegend';
1414
import { renderAxLegend } from '../../../slices/AxSlices/axLegendSlice';
1515
import type { RootState } from '../../../store';
1616

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-
14617
const defaultMargin = {
14718
top: 30,
14819
left: 30,
@@ -166,8 +37,6 @@ export type LinkTypesProps = {
16637
export default function AxTree(props) {
16738
const { currLocation, axSnapshots, width, height } = props;
16839

169-
170-
17140
let margin = defaultMargin;
17241
let totalWidth = width;
17342
let totalHeight = height;
@@ -184,8 +53,6 @@ export default function AxTree(props) {
18453
hideTooltip, // function to close a tooltip
18554
} = useTooltip(); // returns an object with several properties that you can use to manage the tooltip state of your component
18655

187-
// let nameVal = JSON.stringify(tooltipData)
188-
// console.log('nameVal', nameVal);
18956
const {
19057
containerRef, // Access to the container's bounding box. This will be empty on first render.
19158
TooltipInPortal, // TooltipWithBounds in a Portal, outside of your component DOM tree
@@ -208,14 +75,6 @@ export default function AxTree(props) {
20875
pointerEvents: 'all !important',
20976
};
21077

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-
21978
const [layout, setLayout] = useState('cartesian');
22079
const [orientation, setOrientation] = useState('horizontal');
22180
const [linkType, setLinkType] = useState('diagonal');
@@ -253,38 +112,22 @@ export default function AxTree(props) {
253112
// root node of currAxSnapshot
254113
const rootAxNode = JSON.parse(JSON.stringify(currAxSnapshot[0]));
255114

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
257116
const nodeAxArr = [];
258117

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
281119
const organizeAxTree = (currNode, currAxSnapshot) => {
120+
// checks if current ax node has children nodes through childId
282121
if (currNode.childIds && currNode.childIds.length > 0) {
122+
// if yes, add children property to current ax node
283123
currNode.children = [];
284124
for (let j = 0; j < currAxSnapshot.length; j++) {
125+
// locate ax node associated with childId
285126
for (const childEle of currNode.childIds) {
286127
if (childEle === currAxSnapshot[j].nodeId) {
128+
// store ax node in children array
287129
currNode.children.push(currAxSnapshot[j]);
130+
// recursively call organizeAxTree with child ax node passed in to check for further nested children nodes
288131
organizeAxTree(currAxSnapshot[j], currAxSnapshot);
289132
}
290133
}
@@ -294,27 +137,26 @@ export default function AxTree(props) {
294137

295138
organizeAxTree(rootAxNode, currAxSnapshot);
296139

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
299141
const populateNodeAxArr = (currNode) => {
300142
nodeAxArr.splice(0, nodeAxArr.length);
301143
nodeAxArr.push(currNode);
302144
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
304146
const cur = nodeAxArr[i];
305147
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...
307149
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
310152
}
311153
}
312154
}
313155
};
314156

315157
populateNodeAxArr(rootAxNode);
316158

317-
// ax Legend
159+
// Conditionally render ax legend component (RTK)
318160
const { axLegendButtonClicked } = useSelector((state: RootState) => state.axLegend);
319161
const dispatch = useDispatch();
320162

@@ -337,7 +179,6 @@ export default function AxTree(props) {
337179
</button>
338180
</div>
339181

340-
{/* svg references purple background */}
341182
<svg ref={containerRef} width={totalWidth + 0.2*totalWidth} height={totalHeight}>
342183
<LinearGradient id='root-gradient' from='#488689' to='#3c6e71' />
343184
<LinearGradient id='parent-gradient' from='#488689' to='#3c6e71' />
@@ -370,9 +211,8 @@ export default function AxTree(props) {
370211
// code relating to each node in tree
371212
{tree.descendants().map((node, key) => {
372213
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.
374215
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)
376216
if (nodeLength <= 5) return nodeLength + 60;
377217
if (nodeLength <= 10) return nodeLength + 130;
378218
return nodeLength + 160;
@@ -501,13 +341,6 @@ export default function AxTree(props) {
501341
y={-height / 2}
502342
x={-width / 2}
503343
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-
// }
511344
strokeWidth={1.5}
512345
strokeOpacity='1'
513346
rx={node.children ? 4 : 10}
@@ -563,7 +396,6 @@ export default function AxTree(props) {
563396
fontFamily='Roboto'
564397
textAnchor='middle'
565398
style={{ pointerEvents: 'none' }}
566-
//fill={node.depth === 0 ? '#161521' : node.children ? 'white' : '#161521'}
567399
>
568400
{node.data.name.value}
569401
</text>
@@ -601,13 +433,11 @@ export default function AxTree(props) {
601433
</div>
602434
<div>
603435
<ToolTipDataDisplay containerName='Ax Node Info' dataObj={tooltipData} />
604-
{/* <ToolTipDataDisplay containerName='State'dataObj={tooltipData}/> */}
605436
</div>
606437
</div>
607438
</TooltipInPortal>
608439
)}
609440

610-
{/* ax Legend */}
611441
<div>
612442
{ axLegendButtonClicked ?
613443
<AxLegend /> : ''

src/app/styles/layout/_stateContainer.scss

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@
22
font-size: 10px;
33
overflow: auto;
44
background-color: $state-background;
5-
// margin-left: 5px;
65
}
76

87
.toggleAC {
9-
// color: #00dffc;
10-
//color: $blue-brand;
118
background: #ff0001;
129
height: 50%;
1310
text-decoration: none;
@@ -19,16 +16,6 @@
1916
box-shadow: none;
2017
}
2118

22-
// .state-container .navbar {
23-
// //background-color: $state-background;
24-
// //color: #ff0000;
25-
// display: flex;
26-
// flex-direction: row;
27-
// justify-content: flex-start;
28-
// align-items: center;
29-
// height: 30px;
30-
// }
31-
3219
.state-container .main-navbar {
3320
background-color: $state-background;
3421
color: #ff0000;
@@ -59,15 +46,6 @@
5946
height: 35px;
6047
}
6148

62-
// .navbar {
63-
// color: #ff0000;
64-
// // prevent navbar from scrolling with state/tree display
65-
// position: sticky;
66-
// left: 0;
67-
// top: 0;
68-
// @extend %disable-highlight;
69-
// }
70-
7149
.no-data-message {
7250
color: #ff0001;
7351
font: normal 13px $text-font-stack;

0 commit comments

Comments
 (0)