How to get level of node in a nested group

i have a diagram that has multiple nested groups in it i want to bind each nested group with different color so i need to get the level of each group to bind it to colors how to get that level?

Implement a Node.containingGroupChanged event handler to call Part | GoJS API and look up a color in an Array and set whatever properties you like.

i did what u said but for all the groups and nodes it returns me 0 for findsublevel

new go.Binding("fill", "key" ,(h,obj)=>
     // alert(h)
      var node=this.diagram.findNodeForKey(h);
      var lvl =node.findSubGraphLevel();
      return this.color[lvl];
      // var node = obj;
      // alert(node.findSubGraphLevel());


That’s strange, are you sure this Binding was placed on your groupTemplate?

I just tried fineSubGraphLevel() with some groups in this sample: Grouping. It works fine, so there must be something else in your code effecting this

Probably because the binding is being evaluated too early, so that the node isn’t yet in the group that it should belong to. That’s why I suggested implementing a Part.containingGroupChanged event handler instead of using a Binding.