vasturiano/force-graph

No way to get node x and y position

Closed this issue · 1 comments

Use Case
I would like to provide a search bar for a component to search the list of nodes in the force graph and then get the x and y position of the node. Currently node.x and node.y can't be obtained given a node id.

Describe the solution you'd like
A utility function that takes a node filter function and then return the x and y coordinates

Describe alternatives you've considered
I tried using forceRef.current.getGraphBbox((node: any) => node.id === 1) but the resulting x and y didn't match any node's.

@al3x-huang these attributes are in your graph data directly. Assuming you have access to the data that you passed to the force graph, you can extract these attributes from the node you need:

const { x, y } = graphData.nodes.find(node => node.id === 1);