In GoJS how can I set a node visible when clicking button of it's any preceding node?

48 Views Asked by At

I want to implement a function: when I click button in a node A, all the nodes having link from A will appear. I have tried TreeExpanderButton but the effect is not what I expected.

I'll use an example to show what problem I meet:

myDiagram.nodeTemplate =
    $(go.Node, "Spot",
        $(go.Panel, "Auto",
        $(go.Shape, "Rectangle",
            { fill: "gold" }),
        $(go.TextBlock, "Click small button\nto collapse/expand subtree",
            { margin: 5 },
            new go.Binding("text", "key"))
        ),
        $("TreeExpanderButton",
        { alignment: go.Spot.Bottom, alignmentFocus: go.Spot.Top },
        { visible: true })
    );

    myDiagram.layout = $(go.TreeLayout, { angle: 90 });

    myDiagram.model = new go.GraphLinksModel(
        [ { key: 1 },
          { key: 2 },
          { key: 3 },
        ],
        [ { from: 1, to: 3 },
          { from: 2, to: 3 }] );
    myDiagram.nodes.each(function(n) {
        n.wasTreeExpanded = false; 
        n.isTreeExpanded = false;
    })

Above is the structure of my diagram. When I click the TreeExpanderButton of node 1, the node 3 will appear. But when I click such button of node 2, node 3 will not appear. I guess that's because node 3 is child of node 1 in tree structure, but I want that a node appear when clicking Button of it's any preceding node. How can I achieve this goal?

0

There are 0 best solutions below