Try setting Node.avoidable to false on your bar template(s).
You can define a “VBar” node template that is just like your “HBar” node template.
The following templates also include custom link validation predicates that prevent an HBar from being connected with a VBar, and only allow links in a certain direction. You might want to implement different validation criteria.
myDiagram.nodeTemplateMap.add("HBar",
$(go.Node, "Spot",
new go.Binding("location", "location", go.Point.parse).makeTwoWay(go.Point.stringify),
{
avoidable: false,
locationSpot: go.Spot.Center, locationObjectName: "SHAPE",
linkValidation: (fromNode, fromPort, toNode, toPort, link) => {
if ((fromNode.category === "HBar" || fromNode.category === "VBar") &&
(toNode.category === "HBar" || toNode.category === "VBar")) return false;
if (fromNode.category === "HBar" && toNode.location.y < fromNode.location.y) return false;
if (toNode.category === "HBar" && fromNode.location.y > fromNode.location.y) return false;
return true;
},
// special resizing: just at the ends
resizable: true, resizeObjectName: "SHAPE",
resizeAdornmentTemplate:
$(go.Adornment, "Spot",
$(go.Placeholder),
$(go.Shape, // left resize handle
{
alignment: go.Spot.Left, cursor: "col-resize",
desiredSize: new go.Size(6, 6), fill: "lightblue", stroke: "dodgerblue"
}),
$(go.Shape, // right resize handle
{
alignment: go.Spot.Right, cursor: "col-resize",
desiredSize: new go.Size(6, 6), fill: "lightblue", stroke: "dodgerblue"
}))
},
$(go.Shape, "Rectangle",
{
name: "SHAPE",
fill: "black", strokeWidth: 0,
width: 100, height: 2,
minSize: new go.Size(50, 2),
maxSize: new go.Size(Infinity, 2)
},
new go.Binding("width").makeTwoWay(),
new go.Binding("fill"),
{ portId: "", fromLinkable: true, toLinkable: true }),
$(go.TextBlock,
{ alignment: go.Spot.Right, alignmentFocus: go.Spot.Left, editable: true },
new go.Binding("text").makeTwoWay())
));
myDiagram.nodeTemplateMap.add("VBar",
$(go.Node, "Spot",
new go.Binding("location", "location", go.Point.parse).makeTwoWay(go.Point.stringify),
{
avoidable: false,
locationSpot: go.Spot.Center, locationObjectName: "SHAPE",
linkValidation: (fromNode, fromPort, toNode, toPort, link) => {
if ((fromNode.category === "HBar" || fromNode.category === "VBar") &&
(toNode.category === "HBar" || toNode.category === "VBar")) return false;
if (fromNode.category === "VBar" && toNode.location.x < fromNode.location.x) return false;
if (toNode.category === "VBar" && fromNode.location.x > fromNode.location.x) return false;
return true;
},
// special resizing: just at the ends
resizable: true, resizeObjectName: "SHAPE",
resizeAdornmentTemplate:
$(go.Adornment, "Spot",
$(go.Placeholder),
$(go.Shape, // top resize handle
{
alignment: go.Spot.Top, cursor: "row-resize",
desiredSize: new go.Size(6, 6), fill: "lightblue", stroke: "dodgerblue"
}),
$(go.Shape, // bottom resize handle
{
alignment: go.Spot.Bottom, cursor: "row-resize",
desiredSize: new go.Size(6, 6), fill: "lightblue", stroke: "dodgerblue"
}))
},
$(go.Shape, "Rectangle",
{
name: "SHAPE",
fill: "black", strokeWidth: 0,
width: 2, height: 100,
minSize: new go.Size(2, 50),
maxSize: new go.Size(2, Infinity)
},
new go.Binding("height").makeTwoWay(),
new go.Binding("fill"),
{ portId: "", fromLinkable: true, toLinkable: true }),
$(go.TextBlock,
{ alignment: go.Spot.Bottom, alignmentFocus: go.Spot.Top, editable: true, angle: 270 },
new go.Binding("text").makeTwoWay())
));