Skip to main content
100%

Pan & Zoom with click

✓ Published0🌍 Public
SServuc
Last edited Aug 9, 2016
Created on Aug 9, 2016

This example shows a set of circles arranged in a phyllotaxis pattern within an SVG. Users can pan and zoom the view by clicking and dragging, with zoom controlled by the mouse wheel. The implementation uses the `d3.zoom` behavior applied to an invisible overlay rectangle, which updates the SVG group’s `transform` attribute via `d3.event.transform`. Clicking anywhere displays the client and SVG coordinates, converting screen coordinates to SVG space using the SVG’s `getScreenCTM` method. The data is generated programmatically using a phyllotaxis function, and the visualization is rendered with SVG circles.

AI-generated description

This example demonstrates using d3-zoom to pan and zoom an SVG element by applying an SVG transform using transform.toString. The zoom behavior is applied to an invisible rect overlaying the SVG element; this ensures that it receives input, and that the pointer coordinates are not affected by the zoom behavior’s transform.

forked from <a href='http://bl.ocks.org/mbostock/'>mbostock</a>'s block: <a href='http://bl.ocks.org/mbostock/4e3925cdc804db257a86fdef3a032a45'>Pan & Zoom III</a>

forked from <a href='http://bl.ocks.org/anonymous/'>anonymous</a>'s block: <a href='http://bl.ocks.org/anonymous/9f70fd5e4c562599bfc07a59cf099a7f'>Pan & Zoom with click</a>

gpl-3.0 Licensed

Similar vizzes