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
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With