Group Expanding always on top

I used the zOrder attribute to put all group items, nodes and links, on top of other groups/nodes when expanding a group.
I maintain a zOrder value which increased globally every time a group is expanded.
Is there any smarter way to tell gojs to open an expanded on top of other group or nodes ?

What’s the problem?

If you’re concerned about number overflow(??) you could only increment the counter and assign zOrder values when there actually are nodes in front of the group. And always undo the counter increment and zOrder assignments when the group is collapsed.

How would i know if there are nodes in front of the group ?

Call Diagram | GoJS API. Something like:

  function look(node) {
    if (!(node instanceof go.Node)) return;

    var nodes = new go.List().addAll(myDiagram.findObjectsIn(node.actualBounds,
      function(obj) { return obj.part; },
      function(n) { return n instanceof go.Node; },

    for (var i = 0; i < nodes.length; i++) {
      var n = nodes.elt(i);
      if (n === node) return;
      if (n.isMemberOf(node)) continue;
      console.log("in front: " +;