Is there a way to find the sibling of a node programmatically?

The issue I’m facing is that when a node is deleted, the diagram stays still and if we delete all the nodes in viewport then the nodes outside the viewport remains hidden.

Currently I’m selecting the parent of the deleting node and keeping t at the center of diagram but I want to implement this approach using the sibling Node.

Is there any other standard way of GoJS keeping viewport with atleast some part of diagram when the nodes are deleted.

Thank You

The area covered by the nodes, in document coordinates, is given by the Diagram.documentBounds. Normally, the viewport always shows some area in the document bounds, although of course it cannot guarantee that it will show the area that you care about unless you scroll there.

Normally, deleting (or adding) a node will invalidate the layout, resulting in a new layout that typically will cause the nodes to move closer to each other. But perhaps you have disabled that layout invalidation?

If your graph is tree-structured, then given a Node n, the parent node is n.findTreeParentNode() – call that p. If that is non-null you can call p.findTreeChildrenNodes() to get the collection of immediate children of the parent. That will include n, of course.

Hi Walter

Of course, finding sibling using the parent is not an issue but I want to find the immediate sibling to the deleted node, so I could select and center it.

“Normally, deleting (or adding) a node will invalidate the layout, resulting in a new layout that typically will cause the nodes to move closer to each other. But perhaps you have disabled that layout invalidation?”
About which layout exactly are you talking about? I might be missing it. Kindly mention the name of that layout.

Thanks

I suppose you could iterate over those siblings to find the one that you want.

Diagram.layout
http://gojs.net/latest/intro/layouts.html#LayoutInvalidation