Limit number of connections from/to a port

Hi

I wanted to know if, natively, Node or Port componentes allow to handle the amount of in/out connections based on attributes. 

I was able to think on a way of using the CollectionChange and ConnectionChange events to abort an invalid connection, but I wanted to know if there's some native or alternative way of achieving this behavior.

Thanks in advance,
Ramiro.

1 Reply 1 reply marked as answer

AR Aravind Ravi Syncfusion Team August 20, 2020 04:49 AM UTC

Hi Ramiro,  
  
We have created a sample to limit the connections in node by using collectionChange event. In the collectionChange event at the state of Changing we can able to perform cancel operations. We can able to get the node using diagram getObject method. In the getObject method pass the node id, so that respective node gets returned from diagram. In the state of Changing args.element is get as object ,because the connector does not gets added in the diagram. We can check if the adding element is connector or node through connector sourceID property. For node we do not have a sourceID property. So by using sourceID property we can get whether adding element is connector or node. After get the node, check if the node outedges has greater than 2 or not. If we try to connect the third connector means then connector gets removed from the diagram. Please refer below code snippet  
  
public collectionChange(args: ICollectionChangeEventArgs) {  
   if(args.state === 'Changing' && args.type === 'Addition') {  
     if((args.element as ConnectorModel).sourceID) {  
       let node: NodeModel = this.diagram.getObject((args.element as Connector).sourceID);  
         if (2 < (node as Node).outEdges.length) {  
          args.cancel = true;  
        }  
     }  
   }  
 }  
  
  
Regards  
Aravind Ravi  
 


Marked as answer
Loader.
Up arrow icon