Skip to content

Commit f86eb5c

Browse files
committed
began styling history nodes
1 parent 7ca9ec9 commit f86eb5c

File tree

2 files changed

+91
-110
lines changed

2 files changed

+91
-110
lines changed

src/app/components/StateRoute/History.tsx

Lines changed: 20 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -181,45 +181,41 @@ function History(props: Record<string, unknown>): JSX.Element {
181181
`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.
182182
);
183183

184-
const link = g //responsible for rendering the links or connectors between the nodes in the d3 Tree
185-
.selectAll('.link') // select all elements that contain the string '.link' and return a selection
184+
const link = g
185+
.selectAll('.link')
186186
.data(d3root.descendants().slice(1))
187187
.enter()
188188
.append('path')
189-
.attr('class', 'link')
190-
.attr('stroke', '#161617')
191-
.attr('fill', 'none')
189+
.attr('class', (d) => {
190+
return d.data.index === currLocation.index ? 'link current-link' : 'link';
191+
})
192192
.attr(
193-
//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)
194193
'd',
195194
(d) =>
196195
`M${d.x},${d.y}C${d.x},${(d.y + d.parent.y) / 2} ${d.parent.x},${
197196
(d.y + d.parent.y) / 2
198197
} ${d.parent.x},${d.parent.y}`,
199-
)
200-
.attr('class', (d) => {
201-
// Adding a class based on the current node's data
202-
if (d.data.index === currLocation.index) {
203-
return 'link current-link'; // Apply both 'link' and 'current-link' classes
204-
}
205-
return 'link'; // Apply only the 'link' class
206-
});
198+
);
207199

208-
const node = g //responsible for rendering nodes in d3 visualization tree
200+
const node = g
209201
.selectAll('.node')
210202
.data(d3root.descendants())
211203
.enter()
212204
.append('g')
213-
.style('cursor', 'pointer')
214-
.attr('class', `snapshotNode`)
205+
.attr('class', (d) => {
206+
const baseClass = 'node';
207+
const internalClass = d.children ? ' node--internal' : '';
208+
const activeClass = d.data.index === currLocation.index ? ' active' : '';
209+
return baseClass + internalClass + activeClass;
210+
})
211+
.attr('transform', (d) => `translate(${d.x},${d.y})`);
212+
213+
// Add click handler for nodes
214+
node
215215
.on('click', (event, d) => {
216216
dispatch(changeView(d.data.index));
217217
dispatch(changeSlider(d.data.index));
218-
/*
219-
created popup div and appended it to display div(returned in this function)
220218

221-
D3 doesn't utilize z-index for priority, rather decides on placement by order of rendering needed to define the return div with a className to have a target to append to with the correct level of priority
222-
*/
223219
function renderToolTip() {
224220
const [x, y] = d3.pointer(event);
225221
const div = d3
@@ -268,10 +264,6 @@ function History(props: Record<string, unknown>): JSX.Element {
268264
if (event.relatedTarget.id !== `tt-${d.data.index}`) {
269265
d3.selectAll('.tooltip').transition().delay(100).remove();
270266
}
271-
})
272-
273-
.attr('transform', function (d) {
274-
return `translate(${d.x},${d.y})`;
275267
});
276268

277269
const tooltip = d3
@@ -283,25 +275,14 @@ function History(props: Record<string, unknown>): JSX.Element {
283275
d3.selectAll('.tooltip').remove();
284276
});
285277

286-
node
287-
.append('circle')
288-
.attr('fill', (d) => {
289-
if (d.data.index === currLocation.index) {
290-
return '#284b63';
291-
}
292-
return d.color ? d.color : '#555';
293-
})
294-
.attr('r', 18);
278+
node.append('circle').attr('r', 18);
295279

296280
node
297281
.append('text')
298282
.attr('dy', '0.31em')
299283
.attr('text-anchor', 'middle')
300-
.attr('fill', 'white')
301-
.text((d) => `${d.data.name}.${d.data.branch}`)
302-
.clone(true)
303-
.lower()
304-
.attr('stroke', 'white');
284+
.text((d) => `${d.data.name}.${d.data.branch}`);
285+
305286
return svg.node();
306287
};
307288

src/app/styles/components/d3graph.css

Lines changed: 71 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,95 @@
11
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@100;200;300;400;500;600;700;800;900&display=swap');
2-
body {
3-
background-color: black;
2+
/* Base node styling */
3+
.node {
4+
cursor: pointer;
5+
fill-opacity: 1;
6+
transition: all 200ms ease;
47
}
58

6-
.node {
7-
cursor: pointer;
8-
fill-opacity: 0.8;
9+
/* Node circle styling */
10+
.node circle {
11+
fill: #ffffff;
12+
stroke: #e5e7eb;
13+
stroke-width: 2px;
14+
transition: all 200ms ease;
915
}
1016

11-
/* this represents leaf nodes aka nodes with no children */
12-
.node text {
13-
fill: #fae6e4;
14-
background-color: red;
15-
font-size: 10px;
16-
font-family: 'Outfit', sans-serif;
17+
.node:hover circle {
18+
fill: #14b8a6;
19+
stroke: #0d9488;
20+
filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.1));
1721
}
1822

19-
/* modifies text of parent nodes (has children) */
20-
.node--internal text {
21-
fill: white;
22-
font-size: 10px;
23+
/* Node text styling */
24+
.node text {
25+
font-family: 'Outfit', sans-serif;
26+
font-size: 14px;
27+
font-weight: 500;
28+
fill: #374151;
2329
}
24-
.link {
25-
fill: none;
26-
stroke: #161617;
27-
stroke-opacity: 0.4;
28-
stroke-width: 3px;
30+
31+
/* Parent node specific styling */
32+
.node--internal circle {
33+
fill: #ffffff;
34+
stroke: #e5e7eb;
2935
}
3036

31-
div.tooltip {
32-
position: absolute;
33-
padding: 0.5rem 1rem;
34-
color: white;
35-
z-index: 100;
36-
font-size: 14px;
37-
font-family: 'Outfit', sans-serif;
38-
background: rgb(17, 17, 17, 0.9);
39-
box-shadow: rgb(33 33 33 / 20%) 0px 1px 2px;
40-
border-radius: 5px;
41-
max-width: 300px;
37+
.node--internal:hover circle {
38+
fill: #14b8a6;
39+
stroke: #0d9488;
4240
}
4341

44-
.d3-tip {
45-
line-height: 1;
46-
padding: 6px;
47-
background: #679dca;
48-
color: #2b2f39;
49-
border-radius: 4px;
50-
font-size: 13px;
51-
max-width: 400px;
52-
overflow-wrap: break-word;
53-
font-family: 'Overpass Mono', monospace;
42+
.node--internal text {
43+
font-family: 'Outfit', sans-serif;
44+
font-size: 14px;
45+
font-weight: 500;
46+
fill: #374151;
5447
}
5548

56-
/* Creates a small triangle extender for the tooltip */
57-
.d3-tip:after {
58-
box-sizing: border-box;
59-
display: inline;
60-
font-size: 15px;
61-
line-height: 1;
62-
color: #679dca;
63-
content: '\25BC';
64-
position: absolute;
65-
text-align: center;
49+
/* Current/active node styling */
50+
.node.active circle {
51+
fill: #14b8a6;
52+
stroke: #0d9488;
6653
}
6754

68-
/* Style northward tooltips specifically */
69-
.d3-tip.n:after {
70-
margin: -2px 0 0 0;
71-
top: 100%;
72-
left: 0;
55+
/* Link styling */
56+
.link {
57+
fill: none;
58+
stroke: #e5e7eb;
59+
stroke-width: 2px;
60+
transition: stroke 200ms ease;
7361
}
7462

75-
.history-d3-container {
76-
display: flex;
77-
flex-direction: column;
78-
justify-content: space-between;
79-
height: calc(100% - 70px);
63+
.link:hover {
64+
stroke: #d1d5db;
8065
}
8166

82-
.perf-d3-container {
83-
height: calc(100% - 70px);
67+
/* Current path highlight */
68+
.link.current-link {
69+
stroke: #14b8a6;
70+
stroke-opacity: 0.6;
8471
}
8572

86-
.perf-d3-svg {
87-
display: block;
73+
/* Tooltip styling */
74+
div.tooltip {
75+
position: absolute;
76+
padding: 12px 16px;
77+
color: #374151;
78+
z-index: 100;
79+
font-family: 'Outfit', sans-serif;
80+
font-size: 14px;
81+
font-weight: 500;
82+
background: #ffffff;
83+
border: 1px solid #e5e7eb;
84+
box-shadow:
85+
0 4px 6px -1px rgba(0, 0, 0, 0.1),
86+
0 2px 4px -1px rgba(0, 0, 0, 0.06);
87+
border-radius: 8px;
88+
max-width: 300px;
89+
transition: all 200ms ease;
8890
}
8991

90-
.perf-chart-labels {
91-
font: 1.3em sans-serif;
92-
fill: #2a2f3a;
93-
pointer-events: none;
94-
text-anchor: middle;
95-
}
92+
/* Container styling */
93+
.history-d3-container svg {
94+
background-color: #f9fafb;
95+
}

0 commit comments

Comments
 (0)