I have a palette constructed from a TreeLayout and I want to use the information from the TreeNetwork to implement my command handler to support keyboard navigation.
The treeLayout.network is null. I tried calling doLayout as it says that it creates it if not there and should populate everything and resolve the roots. After calling it, the network is still null and from debugging it seems that doLayout sets it back to null at the end.
So question is, how can I get a populated TreeNetwork that I can then use to navigate the tree graph of Vertices, looking at roots, children, expanded state that all seems to be there if I can get my hand on this network. Can make it work without that, but will be much more involved.
First, don’t depend on the TreeLayout’s TreeNetwork. That’s just used for layout. Although it’s normally isomorphic with the graph of Nodes and Links of the Diagram, it might not be.
Just use the Nodes and Links in the Diagram to do your navigation. There are a bunch of tree-oriented methods and properties on the Node class that you can use. Look for names that have “tree” in them.
But if you want to have the user navigate a tree using arrow keys, use the DrawCommandHandler extension, and set DrawCommandHandler.arrowKeyBehavior to “tree”.
Thanks, that helped a lot, I didn’t have it since it was added in 2.0.
At the same time noticed that I would get null for
on my root nodes. I have root “folder” nodes and leaf nodes only.
So after a bit of adaptation, all is good with the navigation.
There is also the Diagram.findTreeRoots method. Diagram | GoJS API