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?
Screenshot%20from%202019-06-27%2021-34-25

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();
      alert(lvl);
      return this.color[lvl];
      // var node = obj;
      // alert(node.findSubGraphLevel());
       
    })

Screenshot%20from%202019-06-28%2020-40-11

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.