简体   繁体   中英

Find/recenter arbitrary node in d3 force-directed layout

I have a force-directed graph with a large number of nodes (thousands) - the volume of data makes any specific node difficult to locate in the graph. I would love to have a way to search for a specific node, and recenter the graph on it.

Is this something I could do by parsing force.nodes() for a specific data value and somehow recentering the graph on that node? Or is it more complicated than that?

Not too troublesome. Once you've identified the special node, re-run the layout with your own tick handler. In that tick handler, set the special node's x and y properties to keep it centered. The layout algorithm will then adjust all the other nodes accordingly.

For a slightly smoother user experience, you could incrementally move the node from it's starting position to the center within the tick handler.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM