Skip to content

Commit 4a0c107

Browse files
committed
added more pseudocode to the history file
1 parent d75815d commit 4a0c107

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/app/components/StateRoute/History.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { changeView, changeSlider, setCurrentTabInApp } from '../../slices/mainS
1616
const defaultMargin: DefaultMargin = {
1717
top: 30,
1818
left: 30,
19-
right: 55,
19+
right: 55,
2020
bottom: 70,
2121
};
2222

@@ -146,7 +146,7 @@ function History(props: Record<string, unknown>): JSX.Element {
146146

147147
const makeD3Tree = () => {
148148
const svg = d3.select(svgRef.current); // d3.select Selects the first element/node that matches svgRef.current. If no element/node match returns an empty selection. If multiple elements/nodes match the selector, only the first matching element/node (in document order) will be selected.
149-
svg.selectAll('*').remove(); // Selects all elements. The elements will be selected in document order (top-to-bottom). We then remove the selected elements/nodes from the DOM
149+
svg.selectAll('*').remove(); // Selects all elements. The elements will be selected in document order (top-to-bottom). We then remove the selected elements/nodes from the DOM. This is important as to ensure that the SVG is empty before rendering the D3 based visualization to avoid interference/overlap with any previously rendered content.
150150

151151
const tree = (data) => { // function that takes in data and turns it into a d3 tree.
152152
const treeRoot = d3.hierarchy(data); // 'd3.hierarchy' constructs a root node from the specified hierarchical data.
@@ -156,28 +156,28 @@ function History(props: Record<string, unknown>): JSX.Element {
156156
const d3root = tree(root); // create a d3. tree from our root
157157
const currNode = labelCurrentNode(d3root); // iterate through our nodes and apply a color property
158158

159-
const g = svg
159+
const g = svg //serves as a container for the nodes and links withi nthe D3 Visualization
160160
.append('g') // create an element 'g' on svg
161161
.attr(
162162
'transform',
163-
`translate(${margin.left},${d3root.height === 0 ? totalHeight / 2 : margin.top})`,
163+
`translate(${margin.left},${d3root.height === 0 ? totalHeight / 2 : margin.top})`, //Set the position of the group 'g' by translating it horizontally by 'margin.left' pixels and vertically based on the conditional expression.
164164
);
165165

166-
const link = g
166+
const link = g //responsible for rendering the links or connectors between the nodes in the d3 Tree
167167
.selectAll('.link') // select all elements that contain the string '.link' and return a selection
168168
.data(d3root.descendants().slice(1))
169169
.enter()
170170
.append('path')
171171
.attr('class', 'link')
172-
.attr(
172+
.attr( //defines the path attribute (d) for each link (edge) between nodes, using a Bézier curve (C) to connect the source node's coordinates (d.x, d.y) to the midpoint between the source and target nodes and then to the target node's coordinates (d.parent.x, d.parent.y)
173173
'd',
174-
(d) =>
174+
(d) =>
175175
`M${d.x},${d.y}C${d.x},${(d.y + d.parent.y) / 2} ${d.parent.x},${
176176
(d.y + d.parent.y) / 2
177177
} ${d.parent.x},${d.parent.y}`,
178178
);
179179

180-
const node = g
180+
const node = g
181181
.selectAll('.node')
182182
.data(d3root.descendants())
183183
.enter()

0 commit comments

Comments
 (0)