How to prevent a connector from being drawn from a port in Angular Diagram?
In Ej2 Angular Diagram Ports act as the connection points of the node and allows to create connections with only those specific points. To enable drawing connectors from a port, you need to set the Port constraints to Draw. The following code snippet demonstrates how to enable port constraints for drawing:
public nodes = [
{
id: 'start',
offsetX: 50,
offsetY: 110,
ports: [
{
id: 'port1',
offset: { x: 1, y: 0.5 },
visibility: PortVisibility.Visible,
tooltip: { content: 'port1' },
constraints: PortConstraints.Default | PortConstraints.Draw,
},
],
annotations: [
{
content: 'node1',
}
]
}
]
Here we have described how to restrict connector drawing from a port if the port already has a connection established. When drawing a connector from the port, the elementDraw event is triggered.
Using this event, we can prevent the connector from being drawn based on the number of existing incoming or outgoing edges at the port. If the port already has one or more incoming or outgoing connections, you can set args.cancel to true to block further connector drawing.
The following code snippet shows how to prevent drawing connectors:
public elementDraw(args: any): void {
if (args.state == 'Start') {
let ports = args.source.ports;
if (ports && this.diagram.nodes !== undefined) {
for (let j = 0; j < ports.length; j++) {
let port = ports[j];
if (port && (port.outEdges.length > 0 || port.inEdges.length > 0)) {
args.cancel = true;
}
}
}
}
}
Refer to the working sample for additional details and implementation:
Sample
Conclusion
We hope you enjoyed learning how to prevent a connector from being drawn from a port in Angular Diagram.
You can refer to our Angular Diagram feature tour page to learn about its other groundbreaking feature representations. You can explore our Angular Diagram documentation to understand how to present and manipulate data.
For current customers, you can check out our Angular components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our Angular Diagram and other Angular components.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!