@@ -51,12 +51,6 @@ class Chart extends Component {
5151 . append ( 'svg' ) // chartContainer is now pointing to svg
5252 . attr ( 'width' , width )
5353 . attr ( 'height' , height ) ;
54-
55- chartContainer . call ( d3 . zoom ( )
56- . on ( "zoom" , function ( ) {
57- chartContainer . attr ( "transform" , d3 . event . transform )
58- } ) )
59- . append ( "g" )
6054
6155 let g = chartContainer . append ( "g" )
6256 // this is changing where the graph is located physically
@@ -70,7 +64,7 @@ class Chart extends Component {
7064
7165 let tree = d3 . tree ( )
7266 // this assigns width of tree to be 2pi
73- . size ( [ 2 * Math . PI , radius / 1.5 ] )
67+ . size ( [ 2 * Math . PI , radius / 1.4 ] )
7468 . separation ( function ( a , b ) { return ( a . parent == b . parent ? 1 : 2 ) / a . depth } ) ;
7569
7670 let d3root = tree ( hierarchy ) ;
@@ -99,7 +93,7 @@ class Chart extends Component {
9993 } ) ;
10094
10195 node . append ( "circle" )
102- . attr ( "r" , 12 )
96+ . attr ( "r" , 10 )
10397
10498 //creating a d3.tip method where the html has a function that returns the data we passed into tip.show from line 120
10599 let tip = d3Tip ( )
@@ -125,6 +119,34 @@ class Chart extends Component {
125119 return d . data . index ;
126120 } ) ;
127121
122+ // allows svg to be dragged around
123+ node . call ( d3 . drag ( )
124+ . on ( "start" , dragstarted )
125+ . on ( "drag" , dragged )
126+ . on ( "end" , dragended ) ) ;
127+
128+ chartContainer . call ( d3 . zoom ( )
129+ . extent ( [ [ 0 , 0 ] , [ width , height ] ] )
130+ . scaleExtent ( [ 1 , 8 ] )
131+ . on ( "zoom" , zoomed ) ) ;
132+
133+ function dragstarted ( ) {
134+ d3 . select ( this ) . raise ( ) ;
135+ g . attr ( "cursor" , "grabbing" ) ;
136+ }
137+
138+ function dragged ( d ) {
139+ d3 . select ( this ) . attr ( "dx" , d . x = d3 . event . x ) . attr ( "dy" , d . y = d3 . event . y ) ;
140+ }
141+
142+ function dragended ( ) {
143+ g . attr ( "cursor" , "grab" ) ;
144+ }
145+
146+ function zoomed ( ) {
147+ g . attr ( "transform" , d3 . event . transform ) ;
148+ }
149+
128150 //applying tooltip on mouseover and removes it when mouse cursor moves away
129151 node
130152 . on ( 'mouseover' , function ( d ) {
0 commit comments