Reposition nodes when group is expanded/collapsed


I have a diagram with expandable/collapsible groups.
Whenever the size of a group changes (this might be by expanding/collapsing but also by adding/remove nodes to the group) I would like to rearrange nodes outside of the group. The new position of the nodes depends on the change in width/height of the group. (Example: Let’s say the groups width changed from 100 to 250: All nodes not within the group should be pushed 2.5-times (250/100) of their current distance away from the group). Therefore I need the width/height change ratio.

So basically similar to this ticket, but also moving other nodes when the size of the group changes (not only using the expand button). As far as I can see, the subGraphExpandedChanged is only executed if the group is expanded, not if its size has changed.

I was also considering to implement a custom layout, but for the calculation of the new position of the nodes I need to know the ratio by which the groups width/height has changed. As far as I can see I don’t have this infomation when implementing a custom layout?

As far as I see, I can neither use subGraphExpandedChanged (not triggered on size changes) nor a custom layout (not able to know the height/width change ratio of a group).
What would be your suggestion?

The normal layout behavior is that whenever a node (including a group) changes size, the layout responsible for positioning that node is invalidated, causing the layout to be performed again using the node’s new size. Is that behavior not suitable for your app? If not, why not?

We aren’t using a layout, the user can position nodes and groups freely.
Still, we would like to push nodes away (with a self-written algorithm) when a users expands a group or does something which increases the size of the node (e.g. adding nodes). Likewise, we want to pull nodes closer when collapsing a group.

Maybe this will help: Automatically shifting nodes

Yes this seems to be helpful.
I only want to change nodes which are to the right or bottom of the group which has been expanded/collapsed though.
Can I assume that I’ll find all groups whose size have changed by checking the part.actualBounds before (old size) and after (new size) calling part.ensureBounds() ?

I think so – you’ll have to try it.

Unfortunately this doesn’t seem to be the case. actualBounds in the LayoutCompleted event is already the bounds of the updated group, even before calling ensureBounds.

I could temporarily save the last known bounds for each group in the LayoutCompleted handler, but maybe there is a better way…?

You could remember the size of each group in a property that you set in your layout code after any change. That way you will have the previous size the next time your layout code runs.

Okay thanks!

Okay so the requirements have changed a bit… I don’t want to move the other nodes anymore when the size of a group changes (e.g. by adding nodes), only if a group is expanded/collapsed.

As far as I can see, I cannot use "LayoutCompleted" for this, as I don’t know the reason for the layout change (group expanded or node added to group)

So I thought I need to use subGraphExpandedChanged. However with nested groups this function is called for every nested group whose parent group is expanded/collpased. In order to move the right collection of nodes, I need to know which group has been expanded by the user (i.e. I am not interested in the groups which have been expanded because the parent group has been expanded).

Take this for example:

Let’s assume the outmost group (“Top”) is initially collapsed.
Now expanding the outmost group, subGraphExpandedChanged gets called three times.
However, I only want to move node “Supermarkt” and not “Prozess_Montage” because I only want to move the nodes outside of the group which has been expanded.

Any way to know which group has been actually expanded by the user?

It might be easier to implement a “SubGraphExpanded” and a “SubGraphCollapsed” DiagramEvent listener. Those only happen once per diagram per call to CommandHandler.expandSubGraph or CommandHandler.collapseSubGraph. The DiagramEvent.subject is a collection of the Groups that were expanded or collapsed, not including nested groups.

Thank you!