Position groups to overlap each other, then expand or collapse them. If there is an overlap of the expanded group with any top-level nodes, it shifts them either rightwards or downwards or both, depending on the relative locations of the nodes.

Note: this does not move a group if the group itself would have to move to avoid overlap with a node that is leftward and upward of it.