7
7
import React , { useEffect , useCallback , useState } from 'react' ;
8
8
import * as d3 from 'd3' ;
9
9
10
- const Map = ( props ) => {
10
+ const ComponentMap = ( props ) => {
11
11
//import props
12
12
const { viewIndex, snapshots , x , y, k, setZoomState} = props ;
13
13
let lastSnap : number | null = null ;
@@ -75,7 +75,7 @@ const Map = (props) => {
75
75
76
76
// declare re render funciton to handle collapse and expansion of nodes
77
77
const update = ( source ) => {
78
- const duration = 0 ;
78
+ const duration = 250 ;
79
79
const nodes = root . descendants ( ) . reverse ( ) ;
80
80
const links = root . links ( ) ;
81
81
@@ -236,118 +236,11 @@ const Map = (props) => {
236
236
) ;
237
237
238
238
239
- < < << << < HEAD
240
- // returns a flat array of objects containing all the nodes and their information
241
- let nodes : any = hierarchyNodes . descendants ( ) ;
242
-
243
- // this segment places all the nodes on the canvas
244
- const node : any = g
245
- . append ( 'g' )
246
- . attr ( 'stroke-linejoin' , 'round' ) // no clue what this does
247
- . attr ( 'stroke-width' , 1 )
248
- . selectAll ( 'g' )
249
- . data ( nodes )
250
- . enter ( )
251
- . append ( 'g' )
252
- . attr ( 'transform' , ( d : any ) => `translate(${ d . y } , ${ d . x } )` )
253
- . attr ( 'class' , 'atomNodes' ) ;
254
-
255
- // for each node that got created, append a circle element
256
- node
257
- . append ( 'circle' )
258
- . attr ( 'fill' , ( d : any ) => ( d . children ? '#95B6B7' : '#46edf2' ) )
259
- . attr ( 'r' , 50 ) ;
260
-
261
- // for each node that got created, append a text element that displays the name of the node
262
- node
263
- . append ( 'text' )
264
- . attr ( 'dy' , '.31em' )
265
- . attr ( 'x' , ( d : any ) => ( d . children ? - 50 : 50 ) )
266
- . attr ( 'text-anchor' , ( d : any ) => ( d . children ? 'end' : 'start' ) )
267
- . text ( ( d : any ) => d . data . name )
268
- . style ( 'font-size' , `2rem` )
269
- . style ( 'fill' , 'white' )
270
- . clone ( true )
271
- . lower ( )
272
- . attr ( 'stroke' , '#646464' )
273
- . attr ( 'stroke-width' , 2 ) ;
274
-
275
- // display the data in the node on hover
276
- node . on ( 'mouseover' , function ( d : any , i : number ) : any {
277
- if ( ! d . children ) {
278
- d3 . select ( this )
279
- . append ( 'text' )
280
- . text ( JSON . stringify ( d . data , undefined , 2 ) )
281
- . style ( 'fill' , 'white' )
282
- . attr ( 'x' , - 999 )
283
- . attr ( 'y' , 100 )
284
- . style ( 'font-size' , '3rem' )
285
- . style ( 'text-align' , 'center' )
286
- . attr ( 'stroke' , '#646464' )
287
- . attr ( 'id' , `popup${ i } ` ) ;
288
- }
289
- } ) ;
290
-
291
- // add mouseOut event handler that removes the popup text
292
- node . on ( 'mouseout' , function ( d : any , i : number ) : any {
293
- d3 . select ( `#popup${ i } ` ) . remove ( ) ;
294
- } ) ;
295
-
296
- // allows the canvas to be draggable
297
- node . call (
298
- d3
299
- . drag ( )
300
- . on ( 'start' , dragStarted )
301
- . on ( 'drag' , dragged )
302
- . on ( 'end' , dragEnded )
303
- ) ;
304
-
305
- // allows the canvas to be zoom-able
306
- // d3 zoom functionality
307
- let zoom = d3 . zoom ( ) . on ( 'zoom' , zoomed ) ;
308
- // svgContainer.call(
309
- // zoom.transform,
310
- // // Changes the initial view, (left, top)
311
- // d3.zoomIdentity.translate(150, 250).scale(0.2)
312
- // );
313
- // allows the canvas to be zoom-able
314
- svgContainer . call (
315
- d3
316
- . zoom ( )
317
- . scaleExtent ( [ 0.05 , 0.9 ] ) // [zoomOut, zoomIn]
318
- . on ( 'zoom' , zoomed )
319
- ) ;
320
- // helper function that allows for zooming
321
- function zoomed ( d : any ) {
322
- g . attr ( 'transform' , d3 . event . transform ) ;
323
- }
324
-
325
- // helper functions that help with dragging functionality
326
- function dragStarted ( ) : any {
327
- d3 . select ( this ) . raise ( ) ;
328
- g . attr ( 'cursor' , 'grabbing' ) ;
329
- }
330
-
331
- function dragged ( d : any ) : any {
332
- d3 . select ( this )
333
- . attr ( 'dx' , ( d . x = d3 . event . x ) )
334
- . attr ( 'dy' , ( d . y = d3 . event . y ) ) ;
335
- }
336
-
337
- function dragEnded ( ) : any {
338
- g . attr ( 'cursor' , 'grab' ) ;
339
- }
340
-
341
-
342
-
343
- } ) ;
344
- = === ===
345
239
// call update on node click
346
240
update ( root ) ;
347
241
} ,
348
242
[ data ]
349
243
) ;
350
- > >>> >>> master
351
244
352
245
return (
353
246
< div data-testid = "canvas" >
@@ -358,4 +251,4 @@ const Map = (props) => {
358
251
) ;
359
252
} ;
360
253
361
- export default Map ;
254
+ export default ComponentMap ;
0 commit comments