Maximum no of links to and from a particular node

Hi Team,

Suppose I have a node in myDiagram. I want that only one link can be drawn to and from the node.

If user tried to draw more links to or from this particular node than it should not be allowed.

Please suggest.

This discusses your subject in detail: Linking Validation

Hi Walter,

I refer to the following example http://www.gojs.net/latest/samples/flowchart.html

We can see that there are multiple links drawn from the ‘Start’ node to the other nodes. I tried to use links validations in this example but it is not working for me.

Can you please suggest what would the code changes here so that only one link can emerge from the ‘Start’ node.

Please advice.

What did you try that did not work?

The Introduction page about Linking Validation talked about what I think you want. The API reference lists all of the relevant properties at http://www.gojs.net/latest/api/symbols/GraphObject.html.

In the code section

myDiagram.nodeTemplateMap.add(“Start”,
$(go.Node, “Spot”, nodeStyle(),
new go.Binding(“location”, “loc”, go.Point.parse).makeTwoWay(go.Point.stringify),
$(go.Panel, “Auto”,
$(go.Shape, “Octagon”,
{ name: “SHAPE”, minSize: new go.Size(40, 60), fill: startColor, stroke: null, fromLinkable: true, toLinkable: true, toMaxLinks: 1,fromMaxLinks: 1}),
$(go.TextBlock, “Start”,
{ name: “TEXT”, margin: 5,
font: “bold 11pt Helvetica, Arial, sans-serif”,
stroke: lightText })
),
// three named ports, one on each side except the top, all output only:
//makePort(“L”, go.Spot.Left, true, false),
//makePort(“R”, go.Spot.Right, true, false),
makePort(“B”, go.Spot.Bottom, true, false)
));

I added the highlighted text in green.

Ah, the problem is that you set those properties on a GraphObject that is not a port. As you can see in tne template, there is a port object created by the call to “makePort”. That object is what needs “fromMaxLinks: 1”.

Note that if you have more than one port on a Node and you want there to be at most one Link from all ports counted together, you won’t be able to use the fromMaxLinks property – instead you will need to implement LinkingBaseTool.linkValidation or (in version 1.3) Node.linkValidation.

That doesn’t work either.

I think the control is from the following code

// replace the default Link template in the linkTemplateMap
myDiagram.linkTemplate =
$(go.Link, // the whole link panel





);

No property of a Link can control whether the user can draw a new Link from a Node’s port, since no Link might yet exist. All of the properties are on the port (i.e. GraphObject properties starting with “from…” and “to…”) or on the Diagram.toolManager.linkingTool.

Was the Introduction page http://gojs.net/latest/intro/validation.html not self-explanatory?

Hi Walter,

In the example, for the start node there is only one port. I am using fromMaxLinks: 1 for this port in the makePort() function.

Still it is allowing multiple links for this port.

If there is any code section in this example which is overriding the default linking template.

Please suggest.

Logic circuit uses toMaxLinks to limit the number of incoming links to one:

http://gojs.net/latest/samples/logicCircuit.html

A post was split to a new topic: Preventing duplicate links

Dear kulbhushan,
I have the same problem, could you find any solution for your problem?

Did you set { fromMaxLinks: 1, toMaxLinks: 0 }?

Or have you set https://gojs.net/latest/api/symbols/LinkingTool.html#direction?

$(go.Diagram, . . .,
  { . . .,
    "linkingTool.direction": go.LinkingTool.ForwardsOnly
  })