@@ -40,46 +40,11 @@ function History(props: Record<string, unknown>): JSX.Element {
40
40
const dispatch = useDispatch ( ) ;
41
41
42
42
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 ) ) ;
44
44
// setting the margins for the Map to render in the tab window.
45
45
const innerWidth : number = totalWidth - margin . left - margin . right ;
46
46
const innerHeight : number = totalHeight - margin . top - margin . bottom - 60 ;
47
47
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
-
83
48
function findDiff ( index ) {
84
49
// determines the difference between our current index and the index-1 snapshot and produces an html string
85
50
const statelessCleaning = ( obj : {
@@ -202,9 +167,6 @@ function History(props: Record<string, unknown>): JSX.Element {
202
167
203
168
const g = svg . append ( 'g' ) . attr ( 'transform' , `translate(${ centerOffset } ,${ margin . top } )` ) ;
204
169
205
- // Label current node
206
- const currNode = labelCurrentNode ( d3root ) ;
207
-
208
170
const link = g
209
171
. selectAll ( '.link' )
210
172
. data ( d3root . descendants ( ) . slice ( 1 ) )
@@ -234,6 +196,22 @@ function History(props: Record<string, unknown>): JSX.Element {
234
196
} )
235
197
. attr ( 'transform' , ( d ) => `translate(${ d . x } ,${ d . y } )` ) ;
236
198
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
+
237
215
// Add click handler for nodes
238
216
node
239
217
. on ( 'click' , ( event , d ) => {
@@ -303,14 +281,6 @@ function History(props: Record<string, unknown>): JSX.Element {
303
281
d3 . selectAll ( '.tooltip' ) . remove ( ) ;
304
282
} ) ;
305
283
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
-
314
284
return svg . node ( ) ;
315
285
} ;
316
286
0 commit comments