0

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?

Charles Bandes
  • 795
  • 8
  • 21
  • [This question](http://stackoverflow.com/questions/10887027/how-do-i-set-the-focal-node-in-a-d3-js-force-directed-graph) and [this question](http://stackoverflow.com/questions/21843206/d3-force-layout-fix-root-node-at-the-center) may help. – Lars Kotthoff Apr 29 '15 at 16:50

1 Answers1

0

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.

Stephen Thomas
  • 13,843
  • 2
  • 32
  • 53