@@ -40,16 +40,14 @@ const Map = (props) => {
40
40
41
41
// creating the tree map
42
42
const treeMap : any = d3 . tree ( ) . nodeSize ( [ width , height ] ) ;
43
-
44
43
// creating the nodes of the tree
45
44
const hierarchyNodes : any = d3 . hierarchy ( snapshots [ lastSnap ] ) ;
46
-
47
45
// calling the tree function with nodes created from data
48
46
const finalMap : any = treeMap ( hierarchyNodes ) ;
49
-
50
- // renders a flat array of objects containing all parent-child links
51
47
// renders the paths onto the component
52
48
let paths : any = finalMap . links ( ) ;
49
+ // returns a flat array of objects containing all the nodes and their information
50
+ let nodes : any = hierarchyNodes . descendants ( ) ;
53
51
54
52
// this creates the paths to each node and its contents in the tree
55
53
g . append ( 'g' )
@@ -68,8 +66,7 @@ const Map = (props) => {
68
66
. y ( ( d : any ) => d . x )
69
67
) ;
70
68
71
- // returns a flat array of objects containing all the nodes and their information
72
- let nodes : any = hierarchyNodes . descendants ( ) ;
69
+
73
70
74
71
// this segment places all the nodes on the canvas
75
72
const node : any = g
@@ -124,47 +121,49 @@ const Map = (props) => {
124
121
d3 . select ( `#popup${ i } ` ) . remove ( ) ;
125
122
} ) ;
126
123
127
- // allows the canvas to be draggable
128
- node . call (
129
- d3
130
- . drag ( )
131
- . on ( 'start' , dragStarted )
132
- . on ( 'drag' , dragged )
133
- . on ( 'end' , dragEnded )
134
- ) ;
124
+
125
+
126
+ //______________ZOOM______________\\
127
+
128
+ // Sets starting zoom but breaks keeping currents zoom on state change
129
+
130
+ // let zoom = d3.zoom().on('zoom', zoomed);
131
+ // svgContainer.call(
132
+ // zoom.transform,
133
+ // // Changes the initial view, (left, top)
134
+ // d3.zoomIdentity.translate(150, 250).scale(0.2)
135
+ // );
135
136
136
- // allows the canvas to be zoom-able
137
- // d3 zoom functionality
138
- let zoom = d3 . zoom ( ) . on ( 'zoom' , zoomed ) ;
139
- svgContainer . call (
140
- zoom . transform ,
141
- // Changes the initial view, (left, top)
142
- d3 . zoomIdentity . translate ( 150 , 250 ) . scale ( 0.2 )
143
- ) ;
144
137
// allows the canvas to be zoom-able
145
138
svgContainer . call (
146
139
d3
147
140
. zoom ( )
148
141
. scaleExtent ( [ 0.05 , 0.9 ] ) // [zoomOut, zoomIn]
149
142
. on ( 'zoom' , zoomed )
150
143
) ;
151
- // helper function that allows for zooming
152
144
function zoomed ( d : any ) {
153
145
g . attr ( 'transform' , d3 . event . transform ) ;
154
146
}
155
147
156
- // helper functions that help with dragging functionality
148
+ //_____________DRAG_____________\\
149
+ // allows the canvas to be draggable
150
+ node . call (
151
+ d3
152
+ . drag ( )
153
+ . on ( 'start' , dragStarted )
154
+ . on ( 'drag' , dragged )
155
+ . on ( 'end' , dragEnded )
156
+ ) ;
157
+
157
158
function dragStarted ( ) : any {
158
159
d3 . select ( this ) . raise ( ) ;
159
160
g . attr ( 'cursor' , 'grabbing' ) ;
160
161
}
161
-
162
162
function dragged ( d : any ) : any {
163
163
d3 . select ( this )
164
164
. attr ( 'dx' , ( d . x = d3 . event . x ) )
165
165
. attr ( 'dy' , ( d . y = d3 . event . y ) ) ;
166
166
}
167
-
168
167
function dragEnded ( ) : any {
169
168
g . attr ( 'cursor' , 'grab' ) ;
170
169
}
0 commit comments