I’m binding my fromMaxLinks and toMaxLinks in an itemTemplate to represent ports as I want to dynamically support changing the max number of links for a given port.
new go.Binding("fromMaxLinks", "services"),
This works great when trying to add new links (as the LinkingTool understands these properties), however, I’m wondering what should be done if I, for instance, add 5 links to a port, then reduce the number of services to 3. Currently, all 5 links stay connected, even though I cannot add new ones.
I would like to either have these links break (FILO order) or color the links (red) until I manually remove them to max the *MaxLinks value I’ve set.
Those events aren’t the right time for this situation.
I’m using *MaxLinks to determine how many links can be added to a port (service is this max number of links on the nodeData)
The service value is modifiable by the user outside of the diagram. This means that the user can get into a state where there are more links connected to a given port than should be allowed. At this point, I want to highlight the offending links (all links connected to the offending port).
Node.linkConnected and Node.linkDisconnected will not be fired at this time, since a link has not been added or removed.
Ah, OK, so you can’t use either bindings or the link-connected event handlers.
You’ll have to iterate through all of the modified nodes and their ports to highlight connected links the way that you want. Perhaps you want to implement support for highlighting in your link template(s), GoJS Highlighting -- Northwoods Software. Then it’s just a matter of setting Link.isHighlighted to true or false, as appropriate.
Is that service property on an item object corresponding to each port? So if you updated a particular port’s service property, you just want to update all of the links connecting with that port?
If that’s the case for a small number of ports, it seems iterating over all of the Diagram.links is indeed very inefficient. You just need to find the Node for the port being updated, call Node.findLinksConnected with the particular portId, and then, depending on the count of that collection, update the appearance of those Links.
On the other hand, if you are updating that property on a lot of nodes at once, then it might be faster to iterate over all links in the diagram.
Yeah, you’re right. I forgot that I could pass a portId into the Node.findLinksConnected, thanks for the reminder! That makes the problem much more manageable, as I should only be check a handful of ports, each with just a few links.