I’m trying to do some viewport manipulation after a SubGraph is expanded, but I’m having a lot of trouble because the redraw hasn’t happened when the SubGraphExpanded event fires. I can move my listener to LayoutChanged or something similar, but then I lose all the information from the DiagramEvent.
Is my only option to save off the subject and then consume it in a LayoutChanged listener I attach/detach in the expanded event?
The “SubGraphExpanded” DiagramEvent is raised towards the end of the CommandHandler.expandSubGraph command, but still before the transaction has been committed. At that time no layouts have been performed, so the Group(s) are unlikely to have their final size and position (actualBounds).
FYI, the Group.subGraphExpandedChanged event is raised even earlier, during the expansion process.
I have a similar case (in a BPMN editor like example): I need to turn off layout.isOngoing after a Lane (in a Pool) is expanded and layout is done. That for initial generated models (that do not have locations and points. ) that depend on auto-layout. I’m not sure if it is according to GoJS best practices or not but I do this on swimLanesGroupTemplate:
subGraphExpandedChanged: function (grp) {
if (grp.diagram === null) return;
if (grp.diagram.undoManager.isUndoingRedoing) return;
const shp = grp.resizeObject;
if (grp.isSubGraphExpanded) {
// Turn off layout.isOngoing if was generated
if (!grp.layout.isValidLayout && grp.layout.isOngoing) {
const listener = function () {
if (grp.layout.isValidLayout) {
grp.layout.isOngoing = false;
grp.diagram.removeDiagramListener('LayoutCompleted', listener);
}
}
grp.diagram.addDiagramListener('LayoutCompleted', listener);
}
}
And it seems to work perfectly - the diagram can be edited freely by the user without Layout intervention. I don’t like timeouts. Ideally if there are some events to be used. What I noticed is that GoJs layouts or parts don’t have independent events, I need to listen on the whole diagram.
When you want to force all of the layouts to be performed, one calls Diagram.layoutDiagram(true). That way you can leave the Group.layout with Layout.isInitial and Layout.isOngoing set to false.