Skip to content Skip to sidebar Skip to footer

How To Pan To A Node Using D3's Force Layout

I would like to focus on a node when it is searched for by name. I am trying to do this using a recenter method.... zoom = d3.behavior.zoom() .scaleExtent([.05, 10])

Solution 1:

Lars was right this is the answer...

zoom.translate([width / 2 - zoom.scale() * node.x, height / 2 - zoom.scale() * node.y])

To break this doesn a bit

width / 2 (go to middle) 
- 
zoom.scale() * node.x (move middle to the scaled x)

Post a Comment for "How To Pan To A Node Using D3's Force Layout"