3d-force-graph
3d-force-graph copied to clipboard
Press 2 nodes to create link in browser
I'm curious what are some ways in which I can add a function where if I press a node it becomes 'selected' and when I press another node as my 'target' the two nodes form a link.
How can this be done live in the environment?
At the moment I need to go to the json and update the nodes and links manually -- but it would be so helpful if say, I could load
2 nodes representing different concepts: ex. {"id": "neuron", "group": "nervous system"}, {"id": "plasma", "group": "circulatory system"}
And in the browser click on either of them, click on the other to connect, and have this represented as {"source": "neuron", "target": "plasma"}
Equally as important would be pressing on the link to remove it -- restoring the 2 nodes to their original unconnected state.
Thank you so much for creating this amazing repository -- would appreciate if any of the users could help find a solution to this :)
@atlllas you should be able to do those edit operations easily with array manipulation functions. For instance to add:
const newLinkToAdd = { source: "neuron", target: "plasma" };
const curData = myGraph.graphData();
myGraph.graphData({ nodes: curData.nodes, links: [...curData.links, newLinkToAdd] });
Similarly for removal.
With onNodeClick(fn) you select and store your nodes