I am currently using this function to zoom in on a state:
function clicked(d) {
if (active.node() === this) return reset();
active.classed("active", false);
active = d3.select(this).classed("active", true);
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];
g.transition()
.duration(750)
.style("stroke-width", 1.5 / scale + "px")
.attr("transform", "translate(" + translate + ")scale(" + scale + ")");
}
And I have this on click listener on the path:
.on("click", clicked)
I want to be able to select a d3 element by class name and then zoom on to it. Preferably, I'd like to call which state to zoom in on from a function like this:
function zoomIn(state) {
//zoom into the state
}
How do I go about doing this?