API doc for the JointJS library is here: http://www.jointjs.com/api I'm using DEVS plugin for Elements with ports.
I need to restrict number of connections from a port to a single one.
Once a link is made from a port, user shouldn't be able to start a connection from the same port unless the existing connection is removed.
Is it possible without code changes in the library itself?
I was not able to get a hook/entry point to implement this requirement even after looking into API doc and the code itself. Any help or pointers are appreciated.
PS:
I've been struggling with this all day. Setting the magnets to passive was not a good enough solution for me. What I've finally ended up with after digging through the source is using the validateMagnet function of the paper object. I get the port from the magnet, and then get all the outbound links from the source model. If any of the links are using the same point I reject the validation. Here's the code:
validateMagnet: function(cellView, magnet) {
// Prevent links from ports that already have a link
var port = magnet.getAttribute('port');
var links = graph.getConnectedLinks(cellView.model, { outbound: true });
var portLinks = _.filter(links, function(o) {
return o.get('source').port == port;
});
if(portLinks.length > 0) return false;
// Note that this is the default behaviour. Just showing it here for reference.
// Disable linking interaction for magnets marked as passive (see below `.inPorts circle`).
return magnet.getAttribute('magnet') !== 'passive';
},
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With