react-d3-tree icon indicating copy to clipboard operation
react-d3-tree copied to clipboard

How to get the position of a node to translate the camera to it ?

Open Slechani opened this issue 3 years ago • 3 comments

Hi, i currently have an input where the user can select from multiple strings (each string is the name of a node in the graph), I would like for the graph to zoom to the target node each time the user changes the select value.

I was able to do every step up until the translation, I understand that I need to use the translate prop but I don't know how to "find" the node by its name and how to find the position of the node once I found it.

Does someone know how to find the position of a node in the graph ?

Thanks in advance

Slechani avatar Jul 04 '22 14:07 Slechani

It's probably no longer relevant, but whoever comes across the same question, it is totally possible. :)

The trick is:

  1. To provide a custom render function via renderCustomNodeElement.
  2. With that, you get access to CustomNodeElementProps for each node. The property hierarchyPointNode contains the (relative) coordinates of the currently rendered node.
  3. Pass a callback to the render function, and invoke it when a relevant node is rendered. Via the callback itself, you can mutate the state of the component containing the tree and, by that, control translation.

Hope this helps.

kobiakov avatar Apr 03 '23 20:04 kobiakov

Hey @kobiakov, Thank you for this. Any chance you have a specific example of this? I can't seem to get it to work.

austingregory-git avatar Jun 12 '23 04:06 austingregory-git

hey @kobiakov , i'm using "react-d3-tree": "^3.6.1" cant find a property called hierarchyPointNode . I can't seem to get it to work.

Ranjith-3i avatar Oct 27 '23 07:10 Ranjith-3i