I have created a gist with my problem.
I've started from this example.
So my problem is that I need some zoom in and zoom out buttons in addition to mouse controls.
Mouse controls (zooming with wheel and pan by dragging) are implemented with zoom() behaviour. It works pretty well.
Then I've added two buttons for zoom in and zoom out:
var _zoom = d3.zoom()
.scaleExtent([1 / 2, 8])
.on("zoom", zoomed);
var gui = d3.select("#gui")
gui.append("span")
.classed("zoom in", true)
.text("+")
.on("click", function() { _zoom.scaleBy(container, 2); })
gui.append("span")
.classed("zoom out", true)
.text("-")
.on("click", function(){ _zoom.scaleBy(container, 0.5); })
They are in conflict with the mouse behaviour. To reproduce the bug you have to zoom and drag around (with the mouse controls) and then click on the +
span: the current transformation is overwritten.
How to resolve it?