Max Link count not working

Hello Everyone,

I have an issue where my node template is not adhering to the properties ‘fromMaxLinks’ and ‘toMaxLinks

I have a model that describes the nodeTemplate map where each type of node has its own definition of the max to and from links. I have a function that generates the map template (as below)


function createNodeTemplate(fill, activity) {

            var tileText = activity.TileText;
            if (tileText === undefined || tileText == null || tileText == '')
                tileText = activity.Name;

            return GO(go.Node, 'Vertical', {
                locationSpot: go.Spot.Center,
                locationObjectName: 'activity',
                selectionAdorned: true,
                selectionObjectName: 'activity',
                resizable: false,
                rotatable: false,
                layoutConditions: go.Part.LayoutStandard & ~go.Part.LayoutNodeSized,
            }, new go.Binding('location', 'loc', go.Point.parse).makeTwoWay(go.Point.stringify),
                GO(go.Panel, 'Auto', {
                    height: 78,
                    width: 78,
                    <font color="#009933">portId: '1',</font>
<font color="#009933">                    fromLinkable: true,</font>
<font color="#009933">                    toLinkable: true,</font>
<font color="#009933">                    fromMaxLinks: activity.OutboundLinks,</font>
<font color="#009933">                    toMaxLinks: activity.InboundLinks,</font>
                },
                GO(go.Shape, 'Rectangle', {
                    name: 'activity',
                    fill: fill,
                    strokeWidth: 2,
                    stroke: '#666',
                    height: 72,
                    width: 72
                }),
                GO(go.Picture, {
                    source: activity.TileImage,
                    height: 44,
                    width: 44,
                    alignment: go.Spot.TopCenter,
                    margin: new go.Margin(6, 0, 0, 0),
                    stretch: go.GraphObject.UniformToFill
                }),
                GO(go.TextBlock, { font: '10px Arial', textAlign: 'center', width: 72, text: tileText, alignment: go.Spot.BottomCenter, margin: new go.Margin(0, 0, 2, 0) })),
                GO(go.TextBlock, { margin: 2, font: '10px sans-serif', editable: false }, new go.Binding('text', 'name').makeTwoWay(go.Point.stringify)));
        }

Now lets assume that all the activities are passing in a 1 for the toMaxLinks & fromMaxLinks properties. I would imagine that (as I only have 1 port on the node) that we should only be able to draw 1 link from the node and 1 link to the node. However the user can draw as many as they like.

Now if I change the model to pass in 0 for either of the properties then it functions correctly.

The full project code is rather lengthy but can provide more details if you wish.

Thank you for your time,

Nico

I think the problem is that you have set the portId on your port element to be “1”. If you change that to be “”, an empty string and the default port name, link validity checking seems to work just fine with your template.

What is happening when the portId===“1” is that links are successfully being drawn to the Node as a whole, using the default port. They are being prevented from linking with your “1” port.

Just to be sure that there wasn’t a problem when there are multiple ports, I modified the Dynamic Ports sample so that certain ports had a { toMaxLinks: 1 } limit. A second Link was correctly disallowed to such ports while still being allowed to connect to other ports on the same Node. Furthermore when the only ports on a Node were ones limited to 1 input link and when they all already had a link connected coming in, links could not be made to the whole Node. But note that the Dynamic Ports sample has GraphLinksModel.linkFromPortIdProperty and linkToPortIdProperty set to the property names used on the link data objects.

That did the trick. Thank you very much for your help!

I am glad this can be sorted as that would of been a major issue if it wasnt.

Thank you again!