Double Tree Collapse / Expand

Hi there again!

Hoping you can offer a pointer. I have a double tree diagram and I’d like to give the user the ability to expand / collapse. In real terms this means collapsing just the inner nodes leaving the root node and outer leaves. The diagram looks like this expanded:

After pressing the collapse button I’d want it to look like this:

The user can do this already by clicking on each of the leaf nodes but that’s a bit time consuming if the diagram is particularly large.

Any pointers on how to achieve do this. The button itself will likely be ouside of the GoJS diagram although I have no objections to it being part of the diagram if it makes it easier?

myDiagram.commit(diag => diag.findTreeRoots().first().collapseTree(2));

Or call Node.expandTree, or call expandTree and then collapseTree to make sure it’s “evenly” expanded.

This worked generally but because we have a slightly different implementation where the extreme right or left nodes are actually the ‘parents’ we had to implement this in another way. In case it helps anyone this method will either colalpse or expand depending on current state:

    $scope.accordianBowTie = function () {
        var root = dblBowTieDiagram.findNodeForKey(0);
        dblBowTieDiagram.nodes.each(function (node) {
            if ( == "FAR_LEFT" || == "FAR_RIGHT") {
                dblBowTieDiagram.commit(function (diag) {
                    if ( === undefined || ! {
                        diag.model.set(, "collapsed", false); // will be negated
                        diag.model.addLinkData({ from: root.key, to: node.key });
                    else if ( {
                        $scope.removeNodeLink(dblBowTieDiagram, node.key);
                    var vis = !;
                    diag.model.set(, "collapsed", vis);
                    $scope.toggleNodeTree(dblBowTieDiagram, node, !vis);