How to set node layers based on model

Hi All,

I currently have a model with group names set for all nodes and would like to create the nodes with the layerName set to the node values except for one group where the layerName is ‘Foreground’. This is to prevent nodes from overlapping when they are in different groups when the diagram is first rendered.

In the go.GraphObject.make() call, I tried adding a binding:

new go.Binding("layerName", "groupName", function (groupName) {
          if (groupName === 'xyz') {
            return 'Foreground';
          } else {
            return groupName;
          }
        })

However this does not work and the nodes in different groups continue to overlap. If I replace the layerName with for example width and return different width values, it renders the widths perfectly. This layerName manipulation also works
inside the selection listener to bring groups to the foreground. Any idea what I’m doing wrong here? Is there an alternate or better way to prevent overlapping?

Thanks!

I tried your binding and it seems to work just fine: http://codepen.io/simonsarris/pen/evbNYB?editors=1010

I put groupName: “xyz” on the Gamma node, and now its in the Foreground layer (and in front of Delta, whereas normally it would be behind Delta)

Simon

Thanks Simon, it does appear to be working fine with codepen. I’m on version 1.6.9 though, was there any issue with this version?

Update: I verified that my code has the same issue with the latest version so I’ll have to figure out what the problem is. Thanks!