New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't access node position in nodeThreeObject #500
Comments
@daniel301r the force directed engine only runs its computation (which sets the nodes' coordinates) after the objects are generated. Therefore, the first time the What you can do is set an async call for the next available frame, and likely you'll have the initial nodes positions by then. Something like: nodeThreeObject={(node) => {
setTimeout(() => console.log(node));
...
}} |
Thanks so much @vasturiano for your quick response. I am actually trying to get the position of the nodes after the engine has run. Is there a way to do this? For context, I have a main graph and the users are able to click on a node which will then generate a completely new graph. Depending on which node they click on in the main graph, I would like to be able to focus on different node in the new graph so knowing the final position of the nodes on the new graph would be very helpful. |
In that case, why not extract the nodes' coordinates at the time of the click (within |
I can't use the coordinates of the node that was clicked on because when the user clicks on a node, it generates a new graph so the previous graph's node positions are not relevant. Is there a way to get the position of the nodes on a graph after the engine has run? |
You can get the position of the nodes at any time by looking for the |
Thanks for the quick response again. I'm not setting the position of the nodes manually when I create the nodes data structure. Is there a way to access the positions that have been assigned by the engine after it has run? Or am I missing something? |
The engine assigns those attributes on the data object for you automatically. In fact, that is the sole way it maintains state of the nodes positions. |
When I console.log the position of the node in the nodeThreeObject function, they are printed out and I can see them. However, when I try to access them they are returned as undefined. Is it possible to access the position of the nodes before/after they are rendered?
nodeThreeObject={(node) => {
console.log(node) // I can see x,y,z position in node object
console.log(node.x) // undefined
}}
The text was updated successfully, but these errors were encountered: