d3 / d3-zoom

Pan and zoom SVG, HTML or Canvas using mouse or touch input.
https://d3js.org/d3-zoom
ISC License
505 stars 143 forks source link

Limit zooming on minimum value of axes #145

Closed mmjmanders closed 5 years ago

mmjmanders commented 6 years ago

I'm creating a graph with circles on it, and when clicking a circle the graph zooms to that specific circle centering it. I'm using the scaleExtent and translateExtent to get this done. However I would like to see the zooming be limited to the minimum value of the axes. In this example, when clicking on the blue circle the graph zooms in but as you can see the x-axis in this case now has a minimum value displayed of -5. The graph should be limited to zero in this case instead of centering the circle.

mbostock commented 5 years ago

You can do this, but you’ll need to compute the appropriate transform yourself. We don’t currently enforce constraints on programmatic zooming (so that you have more flexibility).