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

Copying the graph data to itself results in orphan nodes #532

Open
Harry-OBrien opened this issue Aug 18, 2024 · 1 comment
Open

Copying the graph data to itself results in orphan nodes #532

Harry-OBrien opened this issue Aug 18, 2024 · 1 comment

Comments

@Harry-OBrien
Copy link

Harry-OBrien commented Aug 18, 2024

Describe the bug
When updating graph data, if we copy the links and only update the nodes, the links no longer connect to the node. The image below changes the node with title 'targeteee' to 'target'.

Screenshot 2024-08-18 at 12 09 21 Screenshot 2024-08-18 at 12 09 29

To Reproduce

const [graphData, setGraphData] = useState({ nodes: [{id:0, title:'a'}, {id:1, title:'b'}], links: [{source: 0, target:1}]});
setGraphData({
  ...graphData,
  nodes: [{id:0, title:'c'}, {id:1, title:'b'}]
});

Expected behavior
A clear and concise description of what you expected to happen.

Node changes, still connected.

Screenshot 2024-08-18 at 12 15 02 Screenshot 2024-08-18 at 12 14 57

If I 'clean' the links first, it works fine:

const updatedNodes = graphData.nodes.map(node =>
  node.id === selectedNode.id ? selectedNode : node
);

const cleanedLinks = graphData.links.map(link => {
    return { source: link.source.id, target: link.target.id };
});

setGraphData({
  links: cleanedLinks,
  nodes: updatedNodes,
});

I suspect it has to do with all of the other information that gets added to the links such as x, y, vx, vy, and information about the source and target nodes.

Screenshots
If applicable, add screenshots to help explain your problem.

See above

Desktop (please complete the following information):

  • OS: [e.g. iOS] MacOs
  • Browser [e.g. chrome, safari] Firefox
  • Version [e.g. 22]

Smartphone (please complete the following information):
N/A

Additional context
Add any other context about the problem here.
Related - not the same problem, but a similar solution.

@anyuruf
Copy link

anyuruf commented Sep 6, 2024

Not sure but think D3 kinda works like that. For every cycle you provide information. I stand to be corrected!

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