I am trying to limit pan in d3 zoom but I am not getting correct results. I am using following code to extent both scale
and translate
.
var treeGroup = d3.select('.treeGroup');
var rootSVG = d3.select('.rootSVG')
var zoom = d3.zoom()
.scaleExtent([1.6285, 3])
.translateExtent([[0, 0],[800, 600]])
.on('zoom', function(){
treeGroup.attr('transform', d3.event.transform);
})
rootSVG.call(zoom);
Here is the JSFiddle: https://jsfiddle.net/nohe76yd/45/
scaleExtent
works fine but translateExtent
is giving issues. How do I specify correct value for translateExtent
so that while panning content always stays inside the svg
container?