Skip to content
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

Find node by ID #470

Open
Bones5 opened this issue Nov 9, 2023 · 4 comments
Open

Find node by ID #470

Bones5 opened this issue Nov 9, 2023 · 4 comments

Comments

@Bones5
Copy link

Bones5 commented Nov 9, 2023

I am trying to select a node from the graph by its ID and centre the camera on that nodes position. Is that currently possible?

I feel like I'm missing something but I can't gain access to the graphData once it has been provided to locate the node.

Would a findNodeByyId utility function be possible?

@vasturiano
Copy link
Owner

@Bones5 if you're passing a graphData structure to this component then you must have access to that object on your side of the app.

Once you have the node object you intend to focus the camera, you can simply use cameraPosition (in 3D mode) to focus on that particular node's coordinates, a bit like in this example:

fgRef.current.cameraPosition(
{ x: node.x * distRatio, y: node.y * distRatio, z: node.z * distRatio }, // new position
node, // lookAt ({ x, y, z })
3000 // ms transition duration
);

@Bones5
Copy link
Author

Bones5 commented Nov 9, 2023

Thanks for the reply.

That is the example I was using, rather than on click though I would like to use an external link/route to navigate to the node.

This means I don't have the position of the node passed from the onClick function, only the ID of the node.

Is there a way to achieve this?

@vasturiano
Copy link
Owner

Yes, you just need to search for the node in your own graphData object that you've passed to this component.

@Bones5
Copy link
Author

Bones5 commented Nov 9, 2023

Ah, I see now, the position is appended to my original object.

Sorry, I knew I was missing something.

Thanks very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants