How to Restrict Connector Drawing Using User-Handle in Vue Diagram?
This article explains how to restrict connector drawing using user handles based on specific nodes in the Syncfusion® Vue Diagram component. The diagram provides user handle support for nodes. The code example below demonstrates how to define a user handle in a diagram.
selectedItems: {
constraints: SelectorConstraints.UserHandle,
userHandles: handles
},
let handles= [
{
name: "draw",
offset: 0.5,
pathData:
'M6.09,0 L13.75,6.88 L6.09,13.75 L6.09,9.64 L0,9.64 L0,4.11 L6.09,4.11 Z ',
disableConnectors: true,
side: 'Right',
tooltip: { content: 'Draw' },
}
];
When a user clicks on a user handle, the onUserHandleMouseDown event is triggered. Within this event, custom code can be added to restrict connector drawing using user handles for specific nodes. In the provided example, we demonstrate how to restrict the creation of more than two connectors for a decision node. Within the onUserHandleMouseDown method, a condition is checked: if the number of outgoing connectors is less than two, the user is allowed to draw a new connector. However, if the limit has already been reached, further connector drawing is restricted.
function onUserHandleMouseDown(args) {
if (args.element.name === 'draw') {
if (
!isDecision ||
(isDecision && drawingNode.outEdges.length < 2)
) {
diagram.drawingObject = {
type: 'Orthogonal',
sourceID: drawingNode.id,
};
diagram.tool = DiagramTools.DrawOnce;
diagram.dataBind();
}
}
}
Please refer to the working sample for reference,
Sample
Conclusion
I hope you enjoyed learning how to restrict connector drawing using user-handle in Vue Diagram.
You can refer to our Vue 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 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, Direct-Trac, or feedback portal. We are always happy to assist you!