How to Prevent Node Interaction Dynamically in Angular Diagram?
This article provides a detailed explanation of how to restrict node interactions, except for selection, in the Syncfusion® Angular Diagram component. In the diagram, we create two nodes and connect them using a connector to demonstrate this functionality. The objective is to allow users to select nodes without enabling other interactions such as dragging, resizing, or rotating.
To achieve this, it is essential to configure specific constraints. By enabling the Select constraint for the nodes, you limit their interaction capabilities to selection only. Additionally, the PointerEvents property within the NodeConstraints must also be appropriately set to ensure that the nodes do not respond to other interaction types. This configuration ensures precise control over the behavior of nodes within the diagram.
node.constraints = NodeConstraints.Select | NodeConstraints.PointerEvents;
To implement this functionality, we handle the logic within the selectionChange event of the diagram component. This event allows us to monitor and control the selection process dynamically, ensuring that only the intended interaction, i.e., selection, is permitted. This approach provides a seamless and controlled user experience, particularly in scenarios where strict interaction rules are required.
public selectionChange(args: ISelectionChangeEventArgs) {
if (this.diagram) {
for (let i: number = 0; i < this.diagram.nodes.length; i++) {
let node: NodeModel = this.diagram.nodes[i];
node.constraints =
NodeConstraints.Select | NodeConstraints.PointerEvents;
this.diagram.dataBind();
}
for (let i: number = 0; i < this.diagram.connectors.length; i++) {
let connector: ConnectorModel = this.diagram.connectors[i];
connector.constraints = ConnectorConstraints.None;
this.diagram.dataBind();
}
}
}
Conclusion
I hope you enjoyed learning about how to prevent node interaction dynamically in 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!