How to Prevent Node Moving Outside the Lane in JavaScript Diagram?
In the Syncfusion® JavaScript Diagram you can manage the movement of nodes using Node Constraints, particularly to prevent nodes from moving outside designated lanes.
To restrict a node’s movement to only within its assigned lane, you can use the AllowMovingOutsideLane option in the node constraints. When this option is enabled, it ensures that the node can only be moved within the confines of the lane, preventing any unwanted positioning outside of it.
// Set constraints as AllowMovingOutsideLane for node
constraints: ej.diagrams.NodeConstraints.Default | ej.diagrams.NodeConstraints.AllowMovingOutsideLane
Set the constraints as follows for the child node:
children: [
{
id: 'node1',
annotations: [{ content: 'Node 1' }],
margin: { left: 60, top: 30 },
height: 40, width: 100, ports: port,
constraints: ej.diagrams.NodeConstraints.Default | ej.diagrams.NodeConstraints.AllowMovingOutsideLane
},
],
You can find a working example of this implementation in the provided sample on StackBlitz.
Click here for the Sample
Conclusion
I hope you enjoyed learning how to prevent nodes from moving outside the lane in the JavaScript 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 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, Direct-Trac, or feedback portal. We are always happy to assist you!