Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I dispatch a 'zoom' event after setting scale (d3, zoom.behavior)

How can I trigger the zoom event, once I've set scale manually on the zoom behavior?

var zoom = d3.behavior.zoom()
    .scaleExtent([0.5, 4])
    .on('zoom', onzoom);

// later on
zoom.scale(2);

https://github.com/mbostock/d3/wiki/Zoom-Behavior#wiki-scale

like image 331
Benny Schudel Avatar asked Oct 29 '12 11:10

Benny Schudel


1 Answers

Firstly, you need to attach the zoom behavior to an SVG object. As well, you can call the zoom function on the zoom object.

var zoom = d3.behavior.zoom()
    .scaleExtent([0.5, 4])
    .on('zoom', onzoom);

//svgElement is an actual element such as a rect or text or group
svgElement.call(zoom);

// later on
zoom.scale(2);
zoom.event(svgElement);
like image 135
Brett Avatar answered Sep 22 '22 12:09

Brett