@@ -51,12 +51,6 @@ class Chart extends Component {
51
51
. append ( 'svg' ) // chartContainer is now pointing to svg
52
52
. attr ( 'width' , width )
53
53
. attr ( 'height' , height ) ;
54
-
55
- chartContainer . call ( d3 . zoom ( )
56
- . on ( "zoom" , function ( ) {
57
- chartContainer . attr ( "transform" , d3 . event . transform )
58
- } ) )
59
- . append ( "g" )
60
54
61
55
let g = chartContainer . append ( "g" )
62
56
// this is changing where the graph is located physically
@@ -70,7 +64,7 @@ class Chart extends Component {
70
64
71
65
let tree = d3 . tree ( )
72
66
// this assigns width of tree to be 2pi
73
- . size ( [ 2 * Math . PI , radius / 1.5 ] )
67
+ . size ( [ 2 * Math . PI , radius / 1.4 ] )
74
68
. separation ( function ( a , b ) { return ( a . parent == b . parent ? 1 : 2 ) / a . depth } ) ;
75
69
76
70
let d3root = tree ( hierarchy ) ;
@@ -99,7 +93,7 @@ class Chart extends Component {
99
93
} ) ;
100
94
101
95
node . append ( "circle" )
102
- . attr ( "r" , 12 )
96
+ . attr ( "r" , 10 )
103
97
104
98
//creating a d3.tip method where the html has a function that returns the data we passed into tip.show from line 120
105
99
let tip = d3Tip ( )
@@ -125,6 +119,34 @@ class Chart extends Component {
125
119
return d . data . index ;
126
120
} ) ;
127
121
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
+
128
150
//applying tooltip on mouseover and removes it when mouse cursor moves away
129
151
node
130
152
. on ( 'mouseover' , function ( d ) {
0 commit comments