Instead of using a “Vertical” Panel to hold all of the ports that are on a side of the node, use a “Table” Panel, and make sure that that Panel is stretched vertically, instead of getting its natural height from the collection of elements that it has.
<!DOCTYPE html>
<html>
<head>
<title>Minimal GoJS Sample</title>
<!-- Copyright 1998-2022 by Northwoods Software Corporation. -->
</head>
<body>
<div id="myDiagramDiv" style="border: solid 1px black; width:100%; height:600px"></div>
<script src="https://unpkg.com/gojs"></script>
<script id="code">
const $ = go.GraphObject.make;
const myDiagram =
$(go.Diagram, "myDiagramDiv",
{
layout: $(go.LayeredDigraphLayout),
"undoManager.isEnabled": true
});
function makePort(id, input, row) {
return $(go.Shape,
{
width: 7, height: 7,
row: row,
portId: id,
fromSpot: input ? go.Spot.Default : go.Spot.Right,
toSpot: input ? go.Spot.Left : go.Spot.Default
});
}
myDiagram.nodeTemplate =
$(go.Node, "Spot",
$(go.Panel, "Auto",
{ width: 80, height: 80 },
$(go.Shape,
{ fill: "lightgray" },
new go.Binding("fill", "color")),
$(go.TextBlock,
new go.Binding("text"))
),
$(go.Panel, "Table",
{ stretch: go.GraphObject.Vertical,
alignment: go.Spot.Left, alignmentFocus: go.Spot.Right },
makePort("A", true, 0),
makePort("B", true, 1),
makePort("C", true, 2)
),
$(go.Panel, "Table",
{ stretch: go.GraphObject.Vertical,
alignment: go.Spot.Right, alignmentFocus: go.Spot.Left },
makePort("X", false, 0),
makePort("Y", false, 1)
)
);
myDiagram.linkTemplate =
$(go.Link,
{
curve: go.Link.Bezier,
fromEndSegmentLength: 20, toEndSegmentLength: 20,
relinkableFrom: true, relinkableTo: true,
reshapable: true, resegmentable: true
},
$(go.Shape, { strokeWidth: 1.5 })
);
myDiagram.model = new go.GraphLinksModel(
{
linkFromPortIdProperty: "fpid",
linkToPortIdProperty: "tpid",
nodeDataArray: [
{ key: 1, text: "Alpha", color: "lightblue" },
{ key: 2, text: "Beta", color: "orange" },
{ key: 3, text: "Gamma", color: "lightgreen" },
],
linkDataArray: [
{ from: 1, fpid: "X", to: 2, tpid: "A" },
{ from: 1, fpid: "Y", to: 2, tpid: "B" },
{ from: 3, fpid: "X", to: 2, tpid: "C" }
]
}
);
</script>
</body>
</html>
produces:
