Doing the collapse in an “InitialLayoutCompleted” DiagramEvent listener is OK.
An alternative is to default Node.isTreeExpanded to false and then call Node.expandTree instead on each root.
If diagram.findTreeRoots().count === 0, then either you have no Nodes or there is at least one Link coming into each Node. So the graph is not tree-structured.
If I change InitialLayoutCompleted to LayoutCompleted intial loading is exactly same as second screenshot (which I want). But then can not expand collpased nodes as nothing happens
Looks like nodes and links model is correct. Because If I change InitialLayoutCompleted to LayoutCompleted it works. But then I can not expand collpased nodes as nothing happens
Hmmm, it seems that when the initial layout happens your model is empty. I’m guessing that you are using gojs-angular components, version 2. The way that we designed those components is that each diagram component has a single Diagram with a model whose data is replaced.
Normally an initial layout (or other “initial…” things) only happens when the model is replaced – i.e. when the value of Diagram.model changes. However one can cause the “initial…” stuff to happen without replacing the model by calling Diagram.delayInitialization. The Angular (and React) components do that after a call to clear, because that is the way that the component will know that a model data change should be treated as if it were a first time load, rather than just a modification of the model.
So I’m wondering if you are not calling clear on the diagram component when you want to “load” a “new” model.