Skip to content

UsageGraphError: Graph.addNode: the "Jessica" node already exist in the graph. #9

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

Closed
mooijtech opened this issue Nov 16, 2021 · 3 comments

Comments

@mooijtech
Copy link

mooijtech commented Nov 16, 2021

Hello again,

I'm having trouble getting ForceAtlas2 to work.

The following code works:

import React from "react";
import {useSigma} from "react-sigma-v2";
import {random} from "graphology-layout"

export const NetworkGraph = ({nodes, links}) => {
    const sigma = useSigma();
    const graph = sigma.getGraph();

    graph.addNode("Jessica", { label: "Jessica", x: 0, y: 1, color: "#FF0", size: 10 });
    graph.addNode("Truman", { label: "Truman", x: 1, y: 0, color: "#00F", size: 10 });
    graph.addEdge("Jessica", "Truman", { color: "#CCC", size: 1 });

    random.assign(graph);

    return null;
}

But calling https://graphology.github.io/standard-library/layout-forceatlas2.html after the random assign doesn't:

forceAtlas2.assign(graph);
UsageGraphError: Graph.addNode: the "Jessica" node already exist in the graph.

Do you know what could be the issue?

@mooijtech
Copy link
Author

It seems to work when I do a check for if the graph has the node:

  if (!graph.hasNode("Jessica")) {
        graph.addNode("Jessica", { label: "Jessica", x: 0, y: 1, color: "#FF0", size: 10 });
    }

Not sure why it's not removing the nodes on unmount.

@sim51
Copy link
Owner

sim51 commented Nov 16, 2021

The graph stays the same, event on unmount, it is stored on the SigmaContainer component.

FYI, graphology has some merge functions to add or update nodes/edges.

BTW, I don't know why your component should be remounted, ... generally the properties of the SigmaContainer are pretty much immutable, so the tree should not be re-rendered ...

What are the nodes & links props ?

@mooijtech
Copy link
Author

mooijtech commented Nov 16, 2021

Thanks for the explanation, I appreciate your feedback as always.
I didn't know the state was persisted, I have added a useEffect when adding nodes and this works.

Thanks for this library.

EDIT: The nodes and links props are my actual data but I was using your example as a demo, I will update the code to add nodes from these props.

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