How Can i Restrict connections through ports like if already a connection between A to B then i shall not be able to draw from B to A ?

Also i need to restrict input connections to some nodes or symbols , so that they can only connect to others but no other node shall connect to that node.

1 Reply 1 reply marked as answer

GG Gowtham Gunashekar Syncfusion Team March 11, 2021 03:28 PM UTC

Hi Jayesh, 
 
We have added a sample link to demonstrate how to add restrict the drawn connector at collection change event and achieve you requirement. While draw a connector using drawing tool we don’t have any option to restrict but after add the connector we can add restriction in the collectionChange event and cancel the connector addition.  
 
Code snippet: 
public collectionChange(arg: ICollectionChangeEventArgs) { 
    if (arg.state === "Changing") { 
      for (var i = 0; i < this.diagram.connectors.length; i++) { 
        let currentConnector: Connector = arg.element as Connector; 
        var connector = this.diagram.connectors[i]; 
        if ( 
          connector.sourceID === currentConnector.targetID && 
          connector.targetID === currentConnector.sourceID && 
          connector.sourcePortID === currentConnector.targetPortID && 
          connector.targetPortID === currentConnector.sourcePortID 
        ) { 
          arg.cancel = true; 
        } 
      } 
    } 
  } 
 
  
 
Regards, 
Gowtham 
  


Marked as answer
Loader.
Up arrow icon