sim51 / react-sigma

Sigma React component
https://sim51.github.io/react-sigma/
MIT License
172 stars 27 forks source link

External control : forward Sigma ref #30

Closed sim51 closed 1 year ago

sim51 commented 2 years ago

It can be cool to be able to forward the Sigma ref when using the SigmaContainer. This will allow user to control the graph & Sigma outside SigmaContainer tree.

Example :

export const ExternalView: FC = () => {
  const [sigma, setSigma] = useState<Sigma | null>(null);

  useEffect(() => {
    if (sigma) {
      const graph = sigma.getGraph();
      graph.addNode("A", { x: 0, y: 0, label: "Node A", size: 10 });
      graph.addNode("B", { x: 1, y: 1, label: "Node B", size: 10 });
      graph.addEdgeWithKey("rel1", "A", "B", { label: "REL_1" });
    }
  }, [sigma]);

  return <SigmaContainer ref={setSigma} />;
};
sim51 commented 2 years ago

Should add an example on the website