Articles in this section
Category / Section

How to Convert Connectors to Single While Joining JavaScript Diagram?

3 mins read

The Syncfusion® JavaScript 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.

   sourcePointChange: function (args) {
       if (args.state == 'Completed') {
           var sourceConnector = diagram.getObject(args.connector.sourceID);
           var sourceNode = diagram.getObject((sourceConnector).sourceID);
           args.connector.sourceID = (sourceNode).id;
           diagram.dataBind();
           diagram.remove(sourceConnector);
           diagram.clearSelection();
       }
   },
   targetPointChange: function (args) {
       if (args.state == 'Completed') {
           var targetConnector = diagram.getObject(args.connector.targetID);
           var targetNode = diagram.getObject((targetConnector).targetID);
           args.connector.targetID = (targetNode).id;
           diagram.dataBind();
           diagram.remove(targetConnector);
           diagram.clearSelection();
       }
   },

You can find a working example of this implementation on StackBlitz

Conclusion

I hope you enjoyed learning how to convert two connectors into single connector while dragging and joining using JavaScript Diagram.
You can refer to our JavaScript Diagram feature tour page to know about its other groundbreaking feature representations and [documentation]
(https://ej2.syncfusion.com/documentation/diagram/getting-started), and how to quickly get started for configuration specifications.

You can also explore our JavaScript 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, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied