How to restrict tree expand and collapse to a specific port?

I have a node with two ports: one to right and one to bottom. At the bottom port I have a TreeExpanderButton. This is expanding and collapsing sub trees coming out of both bottom and Right ports. How do I restrict this functionality to either one?

You’ll probably need to create a custom button that only expands/collapses from the bottom port. The default behavior is to call CommandHandler.collapseTree/CommandHandler.expandTree.

Here’s the implementation of the TreeExpanderButton, which you can probably customize to suit your use case:

go.GraphObject.defineBuilder('TreeExpanderButton', function (args) {
  var button = /** @type {Panel} */ (
    go.GraphObject.make('Button',
      { // set these values for the isTreeExpanded binding conversion
        '_treeExpandedFigure': 'MinusLine',
        '_treeCollapsedFigure': 'PlusLine'
      },
      go.GraphObject.make(go.Shape,  // the icon
        {
          name: 'ButtonIcon',
          figure: 'MinusLine',  // default value for isTreeExpanded is true
          stroke: '#424242',
          strokeWidth: 2,
          desiredSize: new go.Size(8, 8)
        },
        // bind the Shape.figure to the Node.isTreeExpanded value using this converter:
        new go.Binding('figure', 'isTreeExpanded',
          function (exp, shape) {
            var but = shape.panel;
            return exp ? but['_treeExpandedFigure'] : but['_treeCollapsedFigure'];
          }
        ).ofObject()
      ),
      // assume initially not visible because there are no links coming out
      { visible: false },
      // bind the button visibility to whether it's not a leaf node
      new go.Binding('visible', 'isTreeLeaf',
        function (leaf) { return !leaf; }
      ).ofObject()
    )
  );

  // tree expand/collapse behavior
  button.click = function (e, btn) {
    var node = btn.part;
    if (node instanceof go.Adornment) node = node.adornedPart;
    if (!(node instanceof go.Node)) return;
    var diagram = node.diagram;
    if (diagram === null) return;
    var cmd = diagram.commandHandler;
    if (node.isTreeExpanded) {
      if (!cmd.canCollapseTree(node)) return;
    } else {
      if (!cmd.canExpandTree(node)) return;
    }
    e.handled = true;
    if (node.isTreeExpanded) {
      cmd.collapseTree(node);
    } else {
      cmd.expandTree(node);
    }
  };

  return button;
});

https://gojs.net/latest/samples/decisionTree.html

Thanks Walter. Exactly what I was looking for.