How can we create dynamic port on junction of two link

When one link is already connected to one port. When I connect another link from different direction to same port. It merges with the first node before connecting. I want to auto generate a port on merging point. how can I do it?

Do you have a screenshot or sketch of what you want it to look like?


Node 1 is already connect to node 3. When I should connect node 2 to node 3’s port it should create a port on junction point of both the links.

First, for the basic technique of connecting links with links using link label nodes, have you examined Links to Links ?

Second, it isn’t clear to me what you really want to do. Could you please describe more precisely the conditions under which you want to change a link drawn to a node to be a link drawn to a link? What if there is more than one link already connected with the node?

Is there a reason you cannot implement such behavior in a “LinkDrawn” DiagramEvent listener?

Hi Walter. Thanks for replying. so the requirement is whenever I connect a second link to a port. it should automatically create a port on junction of those two links. so that from next link connection user can directly connect to junction instead of all the way to node. I am using addModelChangedListener event listener because when I tried “LinkDrawn” it was not giving link.points as I was using link points to add a port. But link points attach a port to one link I wanted it to be attached on junction. So that even if we move the node, it should always be on the junction.

I was suggesting that in your “LinkDrawn” listener you checked to see if there was already an existing Link coming into the port.

If there was, you would check to see if that link already had a label node.
Link | GoJS API
link.labelNodes.first()

If it did not already have such a Node, you would create it and add it to the model and to the link.
GraphLinksModel | GoJS API
The value would be an Array with a single item, the key of the label node data that you had just added to the model.

Then you would reconnect the newly drawn Link with the new label Node, by setting Link.toNode.

Such a scheme will cause the link to always be routed to the path of the earlier link, no matter how the nodes are moved. This is much easier and much more reliable than trying to figure out how to do the routing, especially when what you are routing to is frequently changing on its own.

Hi walter, Above suggestion helped. Thanks a lot

What do you want?

Actually according to your reply I set Link.toNode to the new port. But I didnot set the portid of the link to the portid of the new port. Because of which. The last segment was bending after connection. It is resolved now. Thanks