How can I send a “zoom” event after setting the zoom (d3, zoom.behavior)

How can I fire the zoom event as soon as I draw the scale manually in zoom mode?

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

+7
source share
1 answer

First, you need to bind the scaling behavior to the SVG object. In addition, you can call the zoom function of 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); 
+20
source

All Articles