Skip to main content
100%

Zoom + Pan

✓ Published0🌍 Public
Mmbostock
Last edited Apr 9, 2020
Created on Oct 15, 2012

A zoomable and pannable SVG viewport displays a large grid with axes, controlled by the mouse. The example shows how to programmatically reset the zoom state using a button. It uses d3.behavior.zoom with d3.scale.linear domains, and a transition tween with d3.interpolate to animate the domain reset. The axes and grid are rendered as SVG shapes, and zoomed() rebinds the axes to the updated scales during the transition.

AI-generated description

After panning or zooming with the mouse, click the "Reset" button in the top-right corner to transition back to the default viewport. This example demonstrates setting the domain of scales attached to a zoom behavior programmatically. After the domains are set, you must rebind them to the behavior.

See also a simpler version without transitions and a version with buttons that zoom around the center.

gpl-3.0 Licensed

Similar vizzes