score:2

Accepted answer

You don't need the zoom behavior to explicitly zoom to a path, e.g.:

var bounds = path.bounds(d),
        dx = bounds[1][0] - bounds[0][0],
        dy = bounds[1][1] - bounds[0][1],
        x = (bounds[0][0] + bounds[1][0]) / 2,
        y = (bounds[0][1] + bounds[1][1]) / 2,
        scale = .9 / Math.max(dx / width, dy / height),
        translate = [
            width / 2 - scale * x, 
            height / 2 - scale * y];

svg.transition()
    .duration(750)
    .attr("transform", "translate(" + 
        translate + ")scale(" + 
        scale + ")");

Related Query