Relinking an existing link


I have a scenario where I have to update the content of a node based on the nodes connected to it.

For Eg: In the picture below:

  • If I connect node “Sensor1” to port “Input1”, I want to update the name “Sensor1” next to the port name in the node

  • Similarly when I connect “Sensor2” to “Input2”. I want the name “Sensor2” to appear next to the port name.

I have achieved this by tapping into the linkDrawn diagram event.

But I am facing an issue when I try to update this when links are re-linked.

While re-linking, How can I get the “to” and “from” properties of the existing link?

There is the “LinkRelinked” DiagramEvent:

Yes, but even while using that event, how do i find the “to” and “from” properties of the existing link?

That documentation says that e.subject is the modified Link.
And e.parameter is the original port that the Link had been disconnected from.

All the output ports in all nodes in my palette have the name “Out”, and the input ports have the name “In”. I’m only able to get this name from e.parameter.
But I want the Node from which it is connected.

For eg: If my existing link was connecting node 1 to node 5. Then i want to be able to fetch node 1


e.parameter.part is undefined

For the “LinkRelinked” DiagramEvent, e.parameter should be a GraphObject that is the port from which the link was disconnected.

So basically, i want to override linkRelinked functionality to specifically remove the existing link and draw a link to the new node, since i have certain event being triggered on removal and drawing of links.

Could you help me out on how to do this?

Instead of defining a “LinkRelinked” DiagramEvent listener, I suggest that you override RelinkingTool.reconnectLink,

Don’t call the base method, but just replace the link:

      $(go.Diagram, . . .,
            . . .,
            "relinkingTool.reconnectLink": function(existinglink, newnode, newport, toend) {
              // this example assumes only one port per node
              var fromnode = existinglink.fromNode;
              var tonode = existinglink.toNode;
              // this assumes it's a GraphLinksModel, not a TreeModel:
              if (toend) {
                this.diagram.model.addLinkData({ from: fromnode.key, to: newnode.key });
              } else {
                this.diagram.model.addLinkData({ from: newnode.key, to: tonode.key });