Here’s some code demonstrating what I was suggesting:
function init() {
const $ = go.GraphObject.make;
myDiagram =
$(go.Diagram, "myDiagramDiv",
{
layout: $(go.ForceDirectedLayout)
});
myDiagram.nodeTemplate =
$(go.Node, "Auto",
$(go.Shape,
{ fill: "white", portId: "", fromLinkable: true, toLinkable: true, cursor: "pointer" },
new go.Binding("fill", "color")),
$(go.TextBlock,
{ margin: 8 },
new go.Binding("text"))
);
myDiagram.linkTemplate =
$(go.Link,
{
routing: go.Link.Orthogonal, corner: 10,
relinkableFrom: true, relinkableTo: true,
mouseHover: (e, link) => {
const idx = link.findClosestSegment(e.diagram.lastInput.documentPoint);
if (idx === 2) {
console.log("hovered over " + link.fromNode.key + " --> " + link.toNode.key);
}
}
},
$(go.Shape, { isPanelMain: true, strokeWidth: 6, stroke: "transparent" }),
$(go.Shape, { isPanelMain: true }),
$(go.Shape, { toArrow: "OpenTriangle" }),
$("Button",
$(go.TextBlock, "Button"),
{
segmentIndex: 2, segmentFraction: 0.5,
click: (e, button) => console.log("clicked " + button.part.fromNode.key + " --> " + button.part.toNode.key)
})
);
myDiagram.model = new go.GraphLinksModel(
[
{ key: 1, text: "Alpha", color: "lightblue" },
{ key: 2, text: "Beta", color: "orange" },
{ key: 3, text: "Gamma", color: "lightgreen" },
{ key: 4, text: "Delta", color: "pink" }
],
[
{ from: 1, to: 2 },
{ from: 1, to: 3 },
{ from: 2, to: 2 },
{ from: 3, to: 4 },
{ from: 4, to: 1 }
]);
}