Here’s the answer for #1. Just call the doesBezierLinkCrossOverAnotherNode
predicate.
I’ll think about #2.
<!DOCTYPE html>
<html>
<head>
<title>Minimal GoJS Sample</title>
<!-- Copyright 1998-2025 by Northwoods Software Corporation. -->
</head>
<body>
<div id="myDiagramDiv" style="border: solid 1px black; width:100%; height:400px"></div>
<button id="myTestButton">Test</button>
<textarea id="mySavedModel" style="width:100%;height:250px"></textarea>
<script src="https://cdn.jsdelivr.net/npm/gojs/release/go-debug.js"></script>
<script id="code">
const myDiagram =
new go.Diagram("myDiagramDiv", {
layout: new go.LayeredDigraphLayout(),
"undoManager.isEnabled": true,
"ModelChanged": e => { // just for demonstration purposes,
if (e.isTransactionFinished) { // show the model data in the page's TextArea
document.getElementById("mySavedModel").textContent = e.model.toJson();
}
}
});
myDiagram.nodeTemplate =
new go.Node("Auto")
.add(
new go.Shape({ fill: "white" })
.bind("fill", "color"),
new go.TextBlock({ margin: 8 })
.bind("text")
);
myDiagram.linkTemplate =
new go.Link({
// routing: go.Link.Orthogonal, corner: 10,
curve: go.Link.Bezier, fromEndSegmentLength: 35, toEndSegmentLength: 35
})
.add(
new go.Shape(),
new go.Shape({ toArrow: "OpenTriangle" })
);
myDiagram.model = new go.GraphLinksModel({
linkKeyProperty: "key",
nodeDataArray: [
{ key: 1, text: "Alpha", color: "lightblue" },
{ key: 3, text: "Gamma", color: "lightgreen" },
{ key: 4, text: "Delta", color: "pink" },
{ key: 2, text: "Beta", color: "orange" },
],
linkDataArray: [
{ key: "1-2", from: 1, to: 2 },
{ key: "1-3", from: 1, to: 3 },
{ key: "1-4", from: 1, to: 4 },
{ key: "3-4", from: 3, to: 4 },
]
});
// P and INTERSECTS are optional Point and go.Set values,
// to potentially avoid unnecessary memory allocation, and
// to be able to tell which Nodes it crossed over.
function doesBezierLinkCrossOverAnotherNode(link, p, intersects) {
if (link.curve !== go.Curve.Bezier) return false;
if (!p) p = new go.Point();
if (!intersects) intersects = new go.Set();
const fromB = link.fromNode.actualBounds;
const toB = link.toNode.actualBounds;
const geo = link.geometry;
const linkB = link.routeBounds;
const intv = 1/(Math.sqrt(linkB.width * linkB.width + linkB.height * linkB.height) / 8);
for (let frac = intv; frac < 1.0; frac += intv) {
geo.getPointAlongPath(frac, p);
p.offset(linkB.x, linkB.y);
// crossing over the fromNode or the toNode is OK
if (fromB.containsPoint(p)) continue;
if (toB.containsPoint(p)) continue;
// see if there are any other Parts at this point
myDiagram.findPartsAt(p, false, intersects);
}
return intersects.any(part => part instanceof go.Node);
}
document.getElementById("myTestButton").addEventListener("click", e => {
myDiagram.links.each(link => {
if (doesBezierLinkCrossOverAnotherNode(link)) console.log(link.key);
})
});
</script>
</body>
</html>