I have created a working zoom behavior in d3 v4 to examine a node graph, but am trying to implement two methods that are invoked by zooming. When the user scrolls up with the mouse wheel to zoom in, I want that to invoke the method undo()
and when the user scrolls down with the mouse wheel to zoom out, I want that to invoke the method coarse()
. I am struggling to figure out how to run two different methods depending on if the user scrolls up or down to zoom. Below is how I wrote my basic zoom behavior. Any help would be great, thanks!
var zoom = d3.zoom()
.scaleExtent([1, 2000])
.on('zoom', zoomFn);
function zoomFn() {
d3.select('#div2').select('svg').select('g')
.attr('transform', 'translate(' + d3.event.transform.x + ',' + d3.event.transform.y + ') scale(' + d3.event.transform.k +')')
}
d3.select('#div2').select('svg').select('rect').call(zoom)