reagraph
reagraph copied to clipboard
Min/MaxDistance not applying to manual zoom control
Describe the bug
When setting minDistance
and maxDistance
on the GraphCanvas
element, these settings have only an impact when zooming in/out with the mouse wheel gesture. Now, if you're using manual controls and call ref.current?.zoomIn()
or ref.current?.zoomOut()
, these settings are ignored and you can zoom in/out beyond these limits.
Steps to Reproduce the Bug or Issue
- Set min/maxDistance on the GraphCanvas like:
maxDistance={10000}
minDistance={1000}
- Add buttons to control the zoom of the graph which call
graphRef.current?.zoomIn()
orgraphRef.current?.zoomOut()
- The view now goes beyond the provided bounds
Expected behavior
When setting min/maxDistance values, these should also apply to programmatically zooming in/out for consistency reasons.
Platform
- Reagraph Version: 4.15.26
- OS: macOS
- Browser: Chrome
Additional context
Looks like that these manual zoom functions are looking for the minZoom
and maxZoom
values of the graphRef.current.getControls()
object. I can manually overwrite these settings to limit the possible zoom but I guess it would be beneficial that the zoom limitations (e.g. setting min/maxDistance) are shared between gesture and 'manual' control. Alternatively, it would be nice to set min/maxZoom on the GraphCanvas as well instead of min/maxDistance to control both zoom limitations.