@@ -148,8 +148,38 @@ export const GraphCanvas: FC<GraphCanvasProps & { ref?: Ref<GraphCanvasRef> }> =
148148 rendererRef . current ?. centerGraph ( nodeIds , opts ) ,
149149 fitNodesInView : ( nodeIds , opts ) =>
150150 rendererRef . current ?. fitNodesInView ( nodeIds , opts ) ,
151- zoomIn : ( ) => controlsRef . current ?. zoomIn ( ) ,
152- zoomOut : ( ) => controlsRef . current ?. zoomOut ( ) ,
151+ zoomIn : ( ) => {
152+ const controls = controlsRef . current ?. controls ;
153+ if ( ! controls ) return ;
154+
155+ const currentDistance = controls . distance ;
156+ const currentZoom = controls . camera . zoom ;
157+
158+ // Calculate what the new zoom would be has to match CameraControls logic
159+ const newZoom = currentZoom + currentZoom / 2 ;
160+ const newEffectiveDistance = currentDistance / newZoom ;
161+
162+ // Check if zooming in would violate minDistance constraint
163+ if ( ! minDistance || newEffectiveDistance >= minDistance ) {
164+ controlsRef . current ?. zoomIn ( ) ;
165+ }
166+ } ,
167+ zoomOut : ( ) => {
168+ const controls = controlsRef . current ?. controls ;
169+ if ( ! controls ) return ;
170+
171+ const currentDistance = controls . distance ;
172+ const currentZoom = controls . camera . zoom ;
173+
174+ // Calculate what the new zoom would be (matches CameraControls logic)
175+ const newZoom = currentZoom - currentZoom / 2 ;
176+ const newEffectiveDistance = currentDistance / newZoom ;
177+
178+ // Check if zooming out would violate maxDistance constraint
179+ if ( ! maxDistance || newEffectiveDistance <= maxDistance ) {
180+ controlsRef . current ?. zoomOut ( ) ;
181+ }
182+ } ,
153183 dollyIn : distance => controlsRef . current ?. dollyIn ( distance ) ,
154184 dollyOut : distance => controlsRef . current ?. dollyOut ( distance ) ,
155185 panLeft : ( ) => controlsRef . current ?. panLeft ( ) ,
0 commit comments