Maintain an expanded group nodes within the viewport

I have a collapsed group, like in the pic, marked with arrow :

When i expand it, it goes out of the viewport as shown :

Actually, it went here :
I have tried to write some functions that moves elements into the viewport, when a group is expanded but with no luck
How can i force nodes to be within the viewport when a group is expanded ?

Did you want to scroll to where the group is? Call CommandHandler.scrollToPart.

Or is your group template using a Placeholder and the member Nodes happen to be located far away, near the origin? Either make sure the Group.layout respects the original location of the group, or explicitly call Group.move to move the group where you want it.

By the way, if you want to hide the text for a screenshot, you can temporarily change your templates to set the TextBlock.background to be the same color as the TextBlock.stroke, which defaults to “black”.

when should i call the Group.move function ? In the SubgraphExpanderHandler ?
How do i know that the group (X,Y) is out of the viewport bounds ?

Do the collapsed group’s (hidden) member nodes already have real locations? If so, you could call Diagram.computePartsBounds to get an idea of where the Placeholder (minus Placeholder.padding) would be. Then call Diagram.moveParts to shift them where you want them to be. The group will naturally follow due to the placeholder.

Yes, the member nodes already have real locations.
I don’t want to call it anyway, i want only when the expanded group is out of viewport ?
How do i know if the group or the group members are out of viewport bounds ?
Besides, when should i call the computePartsBounds ? after the group is expanded ? In SubgarphExpandHandler ?

Call Rect.containsRect or Rect.intersectsRect to determine the relationship between the Diagram.viewportBounds and some Rect.

I thought you wanted to decide whether to move a group when expanding a group, i.e. in either a Group.subGraphExpandedChanged event handler or in a “SubGraphExpanded” DiagramEvent listener. The former is obviously called for each group, whereas the latter is called only once for the whole diagram.

You can choose to either call Group.move on the group or Diagram.moveParts on the member Parts.

I did manage to determine if an expanded group is outside the viewport.
In such case, i would like to “move” the group back into the viewport.
I tried to group.move(viewport.x+100, viewport.y+100). I guess I’m wrong.
How do i move the group into the viewport area ?

Don’t you get an error calling it that way?
Call this instead: