Skip to content
Mike Bostock edited this page Jul 8, 2013 · 8 revisions

WikiAPI ReferenceBehaviorsZoom Behavior

Pan+Zoom Zoomable Area Geometric Zooming d3.geo.tile Raster & Vector Zoom Zoomable Geography

This behavior automatically creates event listeners to handle zooming and panning gestures on a container element. Both mouse and touch events are supported.

# d3.behavior.zoom()

Constructs a new zoom behavior.

# zoom.x([x])

Specifies an x-scale whose domain should be automatically adjusted when zooming. If not specified, returns the current x-scale, which defaults to null. If the scale's domain or range is modified programmatically, this function should be called again.

# zoom.y([y])

Specifies an y-scale whose domain should be automatically adjusted when zooming. If not specified, returns the current y-scale, which defaults to null. If the scale's domain or range is modified programmatically, this function should be called again.

# zoom.scaleExtent([extent])

Specifies the zoom scale's allowed range as a two-element array, [minimum, maximum]. If not specified, returns the current scale extent, which defaults to [0, Infinity].

# zoom.scale([scale])

Specifies the current zoom scale. If not specified, returns the current zoom scale, which defaults to 1.

# zoom.translate([translate])

Specifies the current zoom translation vector. If not specified, returns the current translation vector, which defaults to [0, 0].

# zoom.on(type, listener)

Registers the specified listener to receive events of the specified type from the zoom behavior. Currently, only the "zoom" event is supported. When fired, the d3.event object will contain the following properties:

  • "scale": a number; the current scale.
  • "translate": a two-element array representing the current translation vector.

Clone this wiki locally