Skip to content

Commit 7ffd1c5

Browse files
added more pseudocode to ComponentMap
1 parent bc4c1dc commit 7ffd1c5

File tree

1 file changed

+30
-21
lines changed

1 file changed

+30
-21
lines changed

src/app/components/StateRoute/ComponentMap/ComponentMap.tsx

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,13 @@ const defaultMargin: DefaultMargin = {
2929
bottom: 70,
3030
};
3131

32-
3332
export default function ComponentMap({
3433
// imported props to be used to display the dendrogram
3534
width: totalWidth,
3635
height: totalHeight,
3736
margin = defaultMargin,
3837
currentSnapshot, // from 'tabs[currentTab].stateSnapshot object in 'MainContainer'
3938
}: LinkTypesProps): JSX.Element {
40-
4139
const [layout, setLayout] = useState('cartesian'); // We create a local state "layout" and set it to a string 'cartesian'
4240
const [orientation, setOrientation] = useState('vertical'); // We create a local state "orientation" and set it to a string 'vertical'.
4341
const [linkType, setLinkType] = useState('diagonal'); // We create a local state "linkType" and set it to a string 'diagonal'.
@@ -86,9 +84,15 @@ export default function ComponentMap({
8684
}
8785
}
8886

89-
// Tooltip stuff:
90-
const { tooltipData, tooltipLeft, tooltipTop, tooltipOpen, showTooltip, hideTooltip } =
91-
useTooltip();
87+
// Tooltip stuff that was destructured from the returned object from 'useTooltip()'
88+
const {
89+
tooltipData, // value/data that tooltip may need to render
90+
tooltipLeft, // number used for tooltip positioning
91+
tooltipTop, // number used for tooltip positioning
92+
tooltipOpen, // boolean whether the tooltip state is open or closed
93+
showTooltip, // function to set tooltip state
94+
hideTooltip // function to close a tooltip
95+
} = useTooltip(); // returns an object with several properties that you can use to manage the tooltip state of your component
9296

9397
const { containerRef, TooltipInPortal } = useTooltipInPortal({
9498
detectBounds: true,
@@ -122,8 +126,7 @@ export default function ComponentMap({
122126
return `${renderTime} ms `;
123127
};
124128

125-
// places all nodes into a flat array
126-
const nodeList: [] = [];
129+
const nodeList: [] = []; // create a nodeList array to store our nodes as a flat array
127130

128131
const collectNodes: void = (node) => {
129132
nodeList.splice(0, nodeList.length);
@@ -137,31 +140,34 @@ export default function ComponentMap({
137140
}
138141
}
139142
};
143+
140144
collectNodes(currentSnapshot);
141145
// @ts
142146
// find the node that has been selected and use it as the root
143147
let startNode = null;
144148
let rootNode;
145-
const findSelectedNode = () => {
149+
150+
const findSelectedNode = () => { // iterates through each node of nodeList and sets the rootNode and startNode to a node with the name root
146151
for (const node of nodeList) {
147152
if (node.name === 'root') rootNode = node;
148-
if (node.name === selectedNode) startNode = node;
153+
if (node.name === selectedNode) startNode = node; // selectedNode label initialized as 'root'
149154
}
150155
if (startNode === null) startNode = rootNode;
151156
};
157+
152158
findSelectedNode();
153159

154160
// controls for the map
155161
const LinkComponent: React.ComponentType<unknown> = getLinkComponent({ layout, linkType, orientation });
156162
return totalWidth < 10 ? null : (
157163
<div>
158164
<LinkControls
159-
layout={layout}
160-
orientation={orientation}
161-
linkType={linkType}
162-
stepPercent={stepPercent}
165+
layout={layout}
166+
orientation={orientation}
167+
linkType={linkType}
168+
stepPercent={stepPercent}
163169
snapShots={currentSnapshot}
164-
selectedNode={selectedNode}
170+
selectedNode={selectedNode}
165171
setLayout={setLayout}
166172
setOrientation={setOrientation}
167173
setLinkType={setLinkType}
@@ -200,25 +206,28 @@ export default function ComponentMap({
200206
))}
201207

202208
{tree.descendants().map((node, key) => {
203-
const widthFunc:number = (name) => {
204-
// is this the name of the component - so if it's longer it will make the box wider?
209+
const widthFunc:number = (name) => { // function that takes in a node's name and returns a number that is related to the length of the name.
205210
const nodeLength = name.length;
206-
if (nodeLength < 5) return nodeLength + 80; // change from 40 to 80, to see what's affected
207-
if (nodeLength < 10) return nodeLength + 120; // change from 60 to 120 to see what's affected
208-
return nodeLength + 140; // change from 70 to 140 to see what happens
211+
if (nodeLength <= 5) return nodeLength + 80; // returns a number between 80-85
212+
if (nodeLength <= 10) return nodeLength + 120; // returns a number between 125-130
213+
return nodeLength + 140; // returns a number greater than 150
209214
};
210-
const width:number = widthFunc(node.data.name);
211-
const height:number = 25;
212215

216+
const width:number = widthFunc(node.data.name); // the width is determined by the length of the node.name
217+
const height:number = 25;
213218
let top: number;
214219
let left: number;
220+
221+
215222
if (layout === 'polar') {
216223
const [radialX, radialY] = pointRadial(node.x, node.y);
217224
top = radialY;
218225
left = radialX;
226+
219227
} else if (orientation === 'vertical') {
220228
top = node.y;
221229
left = node.x;
230+
222231
} else {
223232
top = node.x;
224233
left = node.y;

0 commit comments

Comments
 (0)