Search code examples
jointjs

JointJS how to unset a passive port when link from that port is removed


Is it possible to disable changing link from dragging at the source end of the link?

I'm using DEV plug-in with inPorts in passive mode; So that only out ports can start a link.

I'll set out port to passive mode when a link is made, so no more links could be created from same port.

However, I want to re-enable the outPort when the link is removed.

following code works when a link is broken from target port side, but not when link is broken at source port side (because source will be a point at this time) or via remove icon in the link.

graph.on('remove', function(cell) {
    console.log('event: remove');
    if (cell instanceof joint.dia.Link) {
        var sElemid = cell.get('source').id;
        var sElem = graph.getCell(sElemid);
        sElem && sElem.attr('.outPorts circle/magnet', 'true');
    }
});

How to re-enable the port in other two cases?


Solution

  • Something is better than nothing. I disabled those two offending features. ie., no more remove icon or draggable arrow head at source end. :->

            defaultLink: new joint.dia.Link({
                attrs: {
                    '.marker-arrowhead-group-source': {
                        display: 'none'
                    },
                    '.link-tools': {
                        display: 'none'
                    }
                }