Link labels

Hi all,

I try to make different link-labels per port.

So my object will have a different label on the link coming out of the right, then coming out of the bottom.

The code below sets the linktabel if the category of the object is “IF”.

function showLinkLabel(e) {
var label = e.subject.findObject(“LABEL”);
<span =“Apple-tab-span” style=“line-height: 1.4; white-space: pre;”>
if (label !== null) label.visible = ( === “IF”);

But I want different labels comming out of this object,

So I want to write something like:

function showLinkLabel(e) {
var label = e.subject.findObject("LABEL");
if (label !== null) label.visible = (e.subject.fromNode.Port === "R");

How can I make this work?

Thanks for your advice.

So you have three or four ports per node, yes?

Why not always have the label TextBlock be visible, and just modify the text that it shows according to the port that it is connected with. In fact you could just have a Binding determine the label. Here’s a minimal Link template. Caution, I haven’t tried this. I’m assuming your link data object has not only “from” but “fromPort” as well as “to” and “toPort” properties.

myDiagram.linkTemplate =
new go.Binding(“text”, “fromPort”, function§ {
switch § {
case “R”: return “right side”;
case “B”: return “bottom side”;
case “L”: return “left side”;
default: return “”;

Wonderfull !


I finally had a chance to try it, and I confirmed that it works.

It also updates automatically if Link.relinkableFrom and/or Link.relinkableTo are set to true and the user actually reconnects the link to a port on a different side of the same or a different node. The magic of data binding!