How to remove connectors from diagram if it do not gets connected to any node in Vue?
This article explains how to remove connectors from a diagram if they do not get connected to any node in Vue. In the Vue Diagram, the connectors are used to create a link between two points, ports, or nodes to represent the relationship between them. To connect the connector between two nodes, the connector must have a sourceID and a targetID.
You can remove a connector from the diagram when the connector’s end is not connected to a node. The connector’s sourceID and targetID properties are used to identify whether the connector is connected to a node or not. The following code shows how to remove the connector when it is not connected to a node on each end.
// Remove the connector when it is not connected to the node
function remove() {
for (let i = 0; i < diagramInstance.connectors.length; i++) {
let connector = diagramInstance.connectors[i];
if (connector.sourceID === '' || connector.targetID === '') {
diagramInstance.remove(connector);
--i;
}
}
};
<ejs-button :isPrimary="true" v-on:click="btnClick">Remove</ejs-button>
// Initialize the diagram
<ejs-diagram style='display:block' ref="diagramObj" id="diagram" :width='width' :height='height' :nodes='nodes' :connectors= connectors :getNodeDefaults='getNodeDefaults' :getConnectorDefaults= 'getConnectorDefaults'></ejs-diagram>
In the above code sample, the onClick event is used to remove the connectors that are not connected to any nodes. The onClick event will get triggered after the Remove button is clicked. In that event, all the connectors in the diagram are iterated to check whether the sourceID and targetID are present in the connector. If the connector is not connected to any node, the sourceID and targetID will be set as “”. If the sourceID and targetID are empty, the remove() method will remove that connector.
Refer to the working sample for additional details and implementation: Sample
Conclusion
We hope you enjoyed learning about how to remove connectors from a diagram if they are connected to any node in Vue.
You can refer to our Vue Diagram feature tour page to learn about its other groundbreaking feature representations and documentation, and how to quickly get started with configuration specifications. You can also explore our Vue 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!