@@ -135,6 +135,13 @@ const ForceGraph: React.FC<ForceGraphProps> = ({
135
135
event . subject . fx = null ;
136
136
event . subject . fy = null ;
137
137
}
138
+
139
+ const zoom = d3 . zoom ( ) . on ( "zoom" , handleZoom ) ;
140
+ function handleZoom ( e : any ) {
141
+ svg . select ( "g.chart" ) . attr ( "transform" , e . transform ) ;
142
+ }
143
+ // @ts -expect-error this works fine
144
+ svg . call ( zoom ) ;
138
145
} ) ;
139
146
140
147
function radius ( num : number ) {
@@ -164,33 +171,39 @@ const ForceGraph: React.FC<ForceGraphProps> = ({
164
171
viewBox = { `${ - width / 2 } ${ - height / 2 } ${ width } , ${ height } ` }
165
172
style = { { height : "auto" , maxWidth : "100%" } }
166
173
>
167
- < g className = "links" stroke = "#999" strokeOpacity = { 0.6 } >
168
- { links . map ( ( link , i ) => (
169
- < line key = { i } strokeWidth = { Math . sqrt ( link . value ) } />
170
- ) ) }
171
- </ g >
172
- < g className = "nodes" stroke = "#fff" strokeWidth = { 1.5 } >
173
- { nodes . map ( ( node , i ) => (
174
- < >
175
- < circle
176
- key = { i }
177
- r = { radius ( node . radius ) }
178
- fill = { color ( node . group ) }
179
- data-nodeid = { node . id }
180
- />
181
- < text
182
- textAnchor = "middle"
183
- alignmentBaseline = "middle"
184
- style = { { userSelect : "none" , cursor : "default" , pointerEvents : "none" } }
185
- fontFamily = "Inter, Helvetica, Arial, sans-serif"
186
- fontSize = { 10 }
187
- strokeWidth = { 0 }
188
- fill = "#fff"
189
- >
190
- { node . text }
191
- </ text >
192
- </ >
193
- ) ) }
174
+ < g className = "chart" >
175
+ < g className = "links" stroke = "#999" strokeOpacity = { 0.6 } >
176
+ { links . map ( ( link , i ) => (
177
+ < line key = { i } strokeWidth = { Math . sqrt ( link . value ) } />
178
+ ) ) }
179
+ </ g >
180
+ < g className = "nodes" stroke = "#fff" strokeWidth = { 1.5 } >
181
+ { nodes . map ( ( node , i ) => (
182
+ < >
183
+ < circle
184
+ key = { i }
185
+ r = { radius ( node . radius ) }
186
+ fill = { color ( node . group ) }
187
+ data-nodeid = { node . id }
188
+ />
189
+ < text
190
+ textAnchor = "middle"
191
+ alignmentBaseline = "middle"
192
+ style = { {
193
+ userSelect : "none" ,
194
+ cursor : "default" ,
195
+ pointerEvents : "none" ,
196
+ } }
197
+ fontFamily = "Inter, Helvetica, Arial, sans-serif"
198
+ fontSize = { 10 }
199
+ strokeWidth = { 0 }
200
+ fill = "#fff"
201
+ >
202
+ { node . text }
203
+ </ text >
204
+ </ >
205
+ ) ) }
206
+ </ g >
194
207
</ g >
195
208
</ svg >
196
209
) ;
0 commit comments