Articles in this section

How to Prevent the Node Interaction Dynamically in JavaScript Diagram?

This article explains how to restrict node interactions, except for selection, in the Syncfusion® JavaScript 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 = ej.diagrams.NodeConstraints.Select | ej.diagrams.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.

       selectionChange: function (){
           if (diagram) {
               for (let i = 0; i < diagram.nodes.length; i++) {
                 let node = diagram.nodes[i];
                 node.constraints =
                 ej.diagrams.NodeConstraints.Select | ej.diagrams.NodeConstraints.PointerEvents;
                 diagram.dataBind();
               }
               for (let i = 0; i < diagram.connectors.length; i++) {
                 let connector = diagram.connectors[i];
                 connector.constraints = ej.diagrams.ConnectorConstraints.None;
                 diagram.dataBind();
               }
           }
       } 

Refer to the working sample for additional details and implementation: Sample

Conclusion

We hope you enjoyed learning about how to prevent node interaction dynamically in JavaScript Diagram.

You can refer to our JavaScript Diagram feature tour page to learn about its other groundbreaking features and representations and documentation to quickly get started with 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!

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