GraphlinksModel collapse expand based on level

Hi team, need advise on how to collapse expand tree based on level. I tried collapseTree and expandTree on nodes, but it is not working properly on graph links model. Thanks!

You need to describe more precisely what behavior you want. It always helps to show your relevant code, a small screenshot showing current behavior, and maybe a sketch of what you want instead.

Pls refer to the attachment.
I have a level dropdown which collapses to the chosen level. The code I have is foreach of
==> level = dropdown value;

diagram.nodes.each(function ® {
r.collapseTree(level);
r.expandTree(level);
}
the above code does not work for some of the graph links model tree.

Just to add to that diagram, please note that I have tree expander at every level.

Do you understand that that graph is not tree-structured?

Could you show a particular case where it doesn’t do what you want, and show what you would want instead?

You might need to set Node.visible on all of the nodes each time, with a true or false value depending on the level that you want to show or not.

How to know in what level the node is, is there any method I can use ?

I understand that graph is not tree structured.

I suppose you could try calling Node.findTreeLevel, but off-hand I don’t remember what it does when the graph is not tree-structured.

All of the properties and methods on the Node and Link classes that have “Tree” in their names assume the graph is tree-structured. That includes the “TreeExpanderButton”, which calls such methods.