Skip to content

Commit f8eaed7

Browse files
committed
styled history nodes into rects
1 parent 67d00d9 commit f8eaed7

File tree

2 files changed

+22
-53
lines changed

2 files changed

+22
-53
lines changed

src/app/components/StateRoute/History.tsx

Lines changed: 17 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -40,46 +40,11 @@ function History(props: Record<string, unknown>): JSX.Element {
4040
const dispatch = useDispatch();
4141

4242
const svgRef = React.useRef(null);
43-
const root = JSON.parse(JSON.stringify(hierarchy)); // why do we stringify and then parse our hierarchy back to JSON? (asked 7/31/23)
43+
const root = JSON.parse(JSON.stringify(hierarchy));
4444
// setting the margins for the Map to render in the tab window.
4545
const innerWidth: number = totalWidth - margin.left - margin.right;
4646
const innerHeight: number = totalHeight - margin.top - margin.bottom - 60;
4747

48-
function labelCurrentNode(d3root) {
49-
// iterates through the parents of a node and applies a color property
50-
if (d3root.data.index === currLocation.index) {
51-
// node.data aka d3root.data allows us to access associated node data. So if node.index === currLocation.index...
52-
53-
let currNode = d3root; // make our input the currNode
54-
55-
while (currNode.parent) {
56-
// while there are parent nodes
57-
currNode.color = '#999'; // change or give the node a color property
58-
currNode = currNode.parent; // change currNode to the parent
59-
}
60-
61-
currNode.color = '#999'; // when there are no more parent nodes, change or give the last node a color property
62-
63-
return d3root; // return the modified d3root
64-
}
65-
66-
let found;
67-
68-
if (!d3root.children) {
69-
// if root has no children array
70-
return found; // return undefined
71-
}
72-
73-
d3root.children.forEach((child) => {
74-
// for each child node within the children array
75-
if (!found) {
76-
// if found is undefined
77-
found = labelCurrentNode(child); //
78-
}
79-
});
80-
return found; // return's the found child node
81-
}
82-
8348
function findDiff(index) {
8449
// determines the difference between our current index and the index-1 snapshot and produces an html string
8550
const statelessCleaning = (obj: {
@@ -202,9 +167,6 @@ function History(props: Record<string, unknown>): JSX.Element {
202167

203168
const g = svg.append('g').attr('transform', `translate(${centerOffset},${margin.top})`);
204169

205-
// Label current node
206-
const currNode = labelCurrentNode(d3root);
207-
208170
const link = g
209171
.selectAll('.link')
210172
.data(d3root.descendants().slice(1))
@@ -234,6 +196,22 @@ function History(props: Record<string, unknown>): JSX.Element {
234196
})
235197
.attr('transform', (d) => `translate(${d.x},${d.y})`);
236198

199+
node
200+
.append('rect')
201+
.attr('width', 100) // Width of rectangle
202+
.attr('height', 40) // Height of rectangle
203+
.attr('x', -50) // Center the rectangle horizontally
204+
.attr('y', -20) // Center the rectangle vertically
205+
.attr('rx', 8) // Rounded corners
206+
.attr('ry', 8); // Rounded corners
207+
208+
// Add text with "Snapshot" prefix
209+
node
210+
.append('text')
211+
.attr('dy', '0.31em')
212+
.attr('text-anchor', 'middle')
213+
.text((d) => `Snapshot ${d.data.index + 1}`);
214+
237215
// Add click handler for nodes
238216
node
239217
.on('click', (event, d) => {
@@ -303,14 +281,6 @@ function History(props: Record<string, unknown>): JSX.Element {
303281
d3.selectAll('.tooltip').remove();
304282
});
305283

306-
node.append('circle').attr('r', 20);
307-
308-
node
309-
.append('text')
310-
.attr('dy', '0.31em')
311-
.attr('text-anchor', 'middle')
312-
.text((d) => `${d.data.name}.${d.data.branch}`);
313-
314284
return svg.node();
315285
};
316286

src/app/styles/components/d3graph.css

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
transition: all 200ms ease;
77
}
88

9-
/* Node circle styling */
10-
.node circle {
9+
/* Node rectangle styling */
10+
.node rect {
1111
fill: #ffffff;
1212
stroke: #e5e7eb;
1313
stroke-width: 2px;
1414
transition: all 200ms ease;
1515
}
1616

17-
.node:hover circle {
17+
.node:hover rect {
1818
fill: #14b8a6;
1919
stroke: #0d9488;
2020
filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.1));
@@ -29,16 +29,15 @@
2929
}
3030

3131
/* Parent node specific styling */
32-
.node--internal circle {
32+
.node--internal rect {
3333
fill: #ffffff;
3434
stroke: #e5e7eb;
3535
}
3636

37-
.node--internal:hover circle {
37+
.node--internal:hover rect {
3838
fill: #14b8a6;
3939
stroke: #0d9488;
4040
}
41-
4241
.node--internal text {
4342
font-family: 'Outfit', sans-serif;
4443
font-size: 14px;

0 commit comments

Comments
 (0)