@@ -84,13 +84,13 @@ class Chart extends Component {
84
84
// };
85
85
const width = 600 ; // - margin.right - margin.left;
86
86
const height = 600 ; // 700 - margin.top - margin.bottom;
87
- const chartContainer = d3
87
+ const svgContainer = d3
88
88
. select ( this . chartRef . current )
89
- . append ( 'svg' ) // chartContainer is now pointing to svg
89
+ . append ( 'svg' ) // svgContainer is now pointing to svg
90
90
. attr ( 'width' , width )
91
91
. attr ( 'height' , height ) ;
92
92
93
- const g = chartContainer
93
+ const g = svgContainer
94
94
. append ( 'g' )
95
95
// this is changing where the graph is located physically
96
96
. attr ( 'transform' , `translate(${ width / 2 + 4 } , ${ height / 2 + 2 } )` ) ;
@@ -159,21 +159,6 @@ class Chart extends Component {
159
159
return colors [ indexColors ] ;
160
160
} )
161
161
. attr ( 'class' , 'node--internal' )
162
- // })
163
- // assigning class to the node based on whether node has children or not
164
- // .attr('class', function (d) {
165
- // return 'node' + (d.children ? ' node--internal' : ' node--leaf');
166
- // })
167
- // .style('fill', function (d) {
168
-
169
- // if (loadTime!== undefined ){
170
-
171
- // if (loadTime > 16){
172
- // return '#ff0000'
173
- // }
174
- // }
175
-
176
- // })
177
162
. attr ( 'transform' , function ( d : { x : number ; y : number } ) {
178
163
return 'translate(' + reinfeldTidierAlgo ( d . x , d . y ) + ')' ;
179
164
} ) ;
@@ -258,17 +243,24 @@ class Chart extends Component {
258
243
. on ( 'end' , dragended )
259
244
) ;
260
245
261
- chartContainer . call (
246
+ // d3 zoom functionality
247
+ let zoom = d3 . zoom ( ) . on ( 'zoom' , zoomed ) ;
248
+ svgContainer . call (
249
+ zoom . transform ,
250
+ // Changes the initial view, (left, top)
251
+ d3 . zoomIdentity . translate ( width / 2 , height / 2 ) . scale ( 1 )
252
+ ) ;
253
+ // allows the canvas to be zoom-able
254
+ svgContainer . call (
262
255
d3
263
256
. zoom ( )
264
- . extent ( [
265
- [ 0 , 0 ] ,
266
- [ width , height ] ,
267
- ] )
268
- . scaleExtent ( [ 0 , 8 ] ) // scaleExtent([minimum scale factor, maximum scale factor])
257
+ . scaleExtent ( [ 0 , 0.9 ] ) // [zoomOut, zoomIn]
269
258
. on ( 'zoom' , zoomed )
270
259
) ;
271
-
260
+ // helper function that allows for zooming
261
+ function zoomed ( d : any ) {
262
+ g . attr ( 'transform' , d3 . event . transform ) ;
263
+ }
272
264
function dragstarted ( ) {
273
265
d3 . select ( this ) . raise ( ) ;
274
266
g . attr ( 'cursor' , 'grabbing' ) ;
@@ -284,10 +276,6 @@ class Chart extends Component {
284
276
g . attr ( 'cursor' , 'grab' ) ;
285
277
}
286
278
287
- function zoomed ( ) {
288
- g . attr ( 'transform' , d3 . event . transform ) ;
289
- }
290
-
291
279
// define the div for the tooltip
292
280
const tooltipDiv = d3
293
281
. select ( 'body' )
0 commit comments