So I’m assuming this is an issue with the way I’m collapsing subgraphs, but I can’t see to track down a different way to do this.
I have a diagram with several expandable/collapsible subgraphs. The diagram has a listener to manipulate the viewport to keep the changed objects in a reasonable view:
SubGraphCollapsed: (e: go.DiagramEvent) => {
const nodes = e.subject as go.List<go.Group>;
setTimeout(() => {
const diagram = e.diagram;
if (
diagram.viewportBounds.width > diagram.documentBounds.width &&
diagram.viewportBounds.height > diagram.documentBounds.height
) {
diagram.zoomToRect(diagram.documentBounds);
}
});
},
Then I have buttons that expand/collapse all subGraphs:
const collapseGroup = (group: go.GraphObject) => {
if (!(group instanceof go.Group)) return;
let diagram = group.diagram;
if (diagram === null) return;
let cmd = diagram.commandHandler;
cmd.collapseSubGraph(group);
};
and
const collapseAll = (e: go.InputEvent): void => {
if (!e.diagram) return;
const diagram = e.diagram;
if (diagram instanceof go.Diagram) {
diagram.startTransaction('collapse');
const nodes = new go.List<go.Group>();
diagram.nodes.each((g: go.Node) => {
if (g instanceof go.Group) {
g.collapseSubGraph();
nodes.add(g);
}
});
diagram.redraw();
diagram.raiseDiagramEvent('SubGraphCollapsed', nodes);
diagram.commitTransaction('collapse');
}
};
If I put a breakpoint in the event handler and use the individual collapse, the document bounds are updated fine. If I use the same breakpoint and use the collapseAll, the document bounds aren’t updated, and my ‘zoomToFit’ fails. I have an exact copy of this code, but inverted for expand, and it all works fine (because it’s check doesn’t require document bounds.) I could do something like calculating a bounding rect around all nodes and comparing to the viewport, but I figured I’d check and see if there was something obvious I was missing before that.