Constrained Zoom
✓ Published0🌍 Public
Mmbostock
Last edited Nov 15, 2016
Created on Sep 22, 2016
This example demonstrates how to constrain d3-zoom so a rectangular image stays within the viewport during pan and zoom operations, using the `d3.zoom` API and its event handler. The SVG shows a small image element whose bounds are checked against the viewport; the `zoomed` function modifies the transform to prevent the image from moving off-screen. The code calculates the image’s coordinates and uses `scaleExtent` to limit zooming to the viewport size. This implementation relies on the d3.v4 library, rendering via SVG, and handles mouse interactions through the zoom’s event system.
AI-generated descriptionThis example demonstrates how to constrain d3-zoom such that a rectangular area of interest is not allowed to go outside the viewport.
gpl-3.0 Licensed