How to Convert Connectors to Connector While Joining Angular Diagram?
In this article, you can learn about how to convert connectors to a single connector while joining nodes in Angular Diagram. The Syncfusion® Angular Diagram allows you to merge two separate connectors into a single connector as you drag and join nodes. This can be achieved by handling the sourcePointChange and targetPointChange events, which allow you to dynamically update the source and target points of the connectors.
In this article, we will walk through the steps to handle the source and target points to convert two connectors into a single connector when one connector end is dragged and attached to the port of another connector.
The sourcePointChange and targetPointChange events are triggered when a connector’s source or target point is moved.These events provide an opportunity to update the source and target IDs of the connector dynamically. By handling these events, you can merge two connectors into one by removing the old connectors and updating the diagram with the new connection.
public sourcePointChange(args) {
if (args.state == 'Completed') {
var sourceConnector = this.diagram.getObject(args.connector.sourceID);
var sourceNode = this.diagram.getObject((sourceConnector as any).sourceID);
args.connector.sourceID = (sourceNode as any).id;
this.diagram.dataBind();
this.diagram.remove(sourceConnector);
this.diagram.clearSelection();
}
}
public targetPointChange(args) {
if (args.state == 'Completed') {
var targetConnector = this.diagram.getObject(args.connector.targetID);
var targetNode = this.diagram.getObject((targetConnector as any).targetID);
args.connector.targetID = (targetNode as any).id;
this.diagram.dataBind();
this.diagram.remove(targetConnector);
this.diagram.clearSelection();
}
}
You can find a working example of this implementation on StackBlitz
Conclusion
We hope you enjoyed learning how to convert two connectors into single connector while dragging and joining using Angular Diagram.
You can refer to our Angular Diagram feature tour page to know about its other groundbreaking feature representations and documentation and how to quickly get started for configuration specifications. You can also explore our Angular Diagram example to understand how to create and manipulate data.
For current customers, you can check out our 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 other controls.
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, BoldDesk Support, or feedback portal. We are always happy to assist you!