Hi,
I’m trying to clearly understand the difference between LayoutCompleted and InitialLayoutCompleted events in GoJS. please confirm when exactly each of these events are triggered, and in what scenarios?
From my current understanding: LayoutCompleted is triggered whenever a layout finishes, for example:
after calling addNodeData
InitialLayoutCompleted is triggered only once, after the very first layout of the diagram, typically:
after replaceModel
Are there are other conditions when these will fire?
Layouts are delayed, typically to be performed at the end of a top-level transaction. There is a Layout.isValidLayout boolean property that declares whether or not the layout should be done again “soon”. The Layout.invalidateLayout method sets that property to false and requests that the layout be performed.
When the Diagram updates, it recursively iterates over all of the Groups, nested first, to call Layout.doLayout on any invalid layouts. Finally it performs the Diagram.layout if it needs to be performed. Then there is a “LayoutCompleted” DiagramEvent. Note that this is not a per-Layout event, but one for the Diagram when all invalid layouts have been performed again.
Replacing the Diagram.model or calling Diagram.delayInitialization will cause an “InitialLayoutCompleted” DiagramEvent to be raised just before the standard “LayoutCompleted” DiagramEvent.