But the problems here is the scrollToPart is not working as expected.
I have tree layout applied by default on diagram.
Upon debugging it looked like my scrollToPart statement is executing before the tree is completely expanded or collapsed.
I tried TreeCollapsed and TreeExpanded event on diagram but still no luck.
Following is my code in these event
var it = arguments[0].subject.iterator;
while (it.next()) {
var item = it.value;
node = this._diagramInstace.findNodeForKey(item.data.id);
this._diagramInstace.commandHandler.scrollToPart(node.actualBounds);
}
So is there a event which states the expand/ collapse process is completed and I can scrollToPart now.
I just tried this code in a sample that happens to have a tree in it:
function test() {
var nodes = new go.List(myDiagram.nodes).toArray();
var node = nodes[Math.floor(Math.random() * nodes.length)];
if (node) {
myDiagram.select(node);
if (node.isTreeExpanded) {
myDiagram.commandHandler.collapseTree(node);
} else {
myDiagram.commandHandler.expandTree(node);
}
myDiagram.commandHandler.scrollToPart(node);
}
}
Calling test() repeatedly seems to work well. Each time the diagram would be scrolled so that the selected and expanded-or-collapsed node was visible in the viewport.
Precisely which version of GoJS are you using? I’m using 2.1.9, but I have also tried 2.0.21 successfully.