How to show or hide userHandles based on some constraints
This article explains how to show or hide user handles based
on certain constraints. The UserHandle feature
is utilized to add frequently used commands around the selector in a diagram.
The user handle is visible only when a node with a value is selected. This blog
will detail how to dynamically show or hide user handles for diagram objects
using the SelectionChange event.
To hide the user handle in a node, set the visibility of the diagram's
selection item's user handles to false. This ensures that the user handle is
not visible when a node is selected.
Here's an example of how to set the user handle visibility to false for a node:
JS
function selectionChange(args) {
if (args.state === 'Changed' && args.type === 'Addition') {
if ((args.newValue[0] instanceof ej.diagrams.Node) && args.newValue[0].id === "node1")
// Hides the userhandle for specified node id
diagram.selectedItems.userHandles[0].visible = false;
else if ((args.newValue[0]instanceof ej.diagrams.Connector) && args.newValue[0].id === "connector1")
// Hides the userhandle for specified connector id
diagram.selectedItems.userHandles[0].visible = false;
else {
// Sets the visible property to true
diagram.selectedItems.userHandles[0].visible = true;
}
}
}
Refer to the working sample for additional details and implementation: Sample
Conclusion
We hope you enjoyed learning about how to load an SVG file into a diagram.
You can refer to our JavaScript Diagram feature tour page to learn about its other groundbreaking feature representations and documentation, 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,BoldDesk Support, or feedback portal. We are always happy to assist you!