You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -26,7 +26,7 @@ function History(props: Record<string, unknown>): JSX.Element {
26
26
const{
27
27
width: totalWidth,// from ParentSize provided in StateRoute
28
28
height: totalHeight,// from ParentSize provided in StateRoute
29
-
margin =defaultMargin,
29
+
margin =defaultMargin,//default margin is used when margins aren't passed into props
30
30
hierarchy,// from 'tabs[currentTab]' object in 'MainContainer'
31
31
currLocation,// from 'tabs[currentTab]' object in 'MainContainer'
32
32
snapshots,// from 'tabs[currentTab].snapshotDisplay' object in 'MainContainer'
@@ -146,7 +146,7 @@ function History(props: Record<string, unknown>): JSX.Element {
146
146
147
147
constmakeD3Tree=()=>{
148
148
constsvg=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.
150
150
151
151
consttree=(data)=>{// function that takes in data and turns it into a d3 tree.
152
152
consttreeRoot=d3.hierarchy(data);// 'd3.hierarchy' constructs a root node from the specified hierarchical data.
@@ -156,36 +156,43 @@ function History(props: Record<string, unknown>): JSX.Element {
156
156
constd3root=tree(root);// create a d3. tree from our root
157
157
constcurrNode=labelCurrentNode(d3root);// iterate through our nodes and apply a color property
158
158
159
-
constg=svg
159
+
constg=svg//serves as a container for the nodes and links within the D3 Visualization of the tree
`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.
164
164
);
165
165
166
-
constlink=g
166
+
constlink=g//responsible for rendering the links or connectors between the nodes in the d3 Tree
167
167
.selectAll('.link')// select all elements that contain the string '.link' and return a selection
168
168
.data(d3root.descendants().slice(1))
169
169
.enter()
170
170
.append('path')
171
171
.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)
0 commit comments