projectstorm / react-diagrams

a super simple, no-nonsense diagramming library written in react that just works
https://projectstorm.cloud/react-diagrams
MIT License
8.51k stars 1.17k forks source link

Access the Node-Tree / Database? #865

Closed D-Niermann closed 3 years ago

D-Niermann commented 3 years ago

Hello, after I add nodes per drag and drop to the graph and link them, I want to iterate through all nodes. Currently I do it in a very hacky manor by getting the children of the html elements, which also doesnt support all graph structures.

Is there a variable somewhere that stores the nodes and their respective links?

Thanks!

rkesters commented 3 years ago

I assume you have something like,

const model = new DiagramModel();
const engine = createEngine();
engine.setModel(model);

to get the nodes

const nodes = engine.getModel().getNodes();
const links = engine.getModel().getLinks();
D-Niermann commented 3 years ago

Thanks! So I guess I have to iterate all Nodes myself. It's ok, but I thought maybe there is already a structured tree stored internally somewhere.