Articles in this section
Category / Section

How to Set ExcludeFromLayout in GetNodeDefaults JavaScript Diagram?

2 mins read

This article explains how to set the excludeFromLayout option in the getNodeDefaults method of the JavaScript Diagram component.

In some scenarios, you may want one or more nodes in your diagram to maintain a fixed position rather than being automatically arranged by the layout algorithm. This can be achieved by excluding those nodes from the layout using the excludeFromLayout property.

You can set the excludeFromLayout property to true inside the getNodeDefaults method of the diagram component. This method allows you to customize the properties of nodes as they are created. Along with this, you can manually set the position of the node using the offsetX and offsetY properties.

For example, by checking a specific property such as the node’s name, you can identify which node should be excluded from the layout and fix its position explicitly. Consider the following code snippet where the node with the name “Robert” is excluded from the layout and positioned at coordinates (100, 75). The node’s width and height are also set in this method.

getNodeDefaults: (obj) => {
   obj.annotations = [{
     content: obj.data.Name
   }]
   if (obj.data.Name === 'Robert') {
     //Excludes node from layout
     obj.excludeFromLayout = true;
     obj.offsetX = 100;
     obj.offsetY = 75;
   }
   obj.width = 100;
   obj.height = 50;
   return obj;
 }, 

In this example, the layout algorithm will arrange all nodes except the one where excludeFromLayout is set to true. This allows the excluded node to remain in a fixed position as specified.

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

Conclusion

We hope you enjoyed learning on how to set excludeFromLayout in getNodeDefaults method to fix node position in a JavaScript Diagram.

You can refer to our JavaScript 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 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)
Please  to leave a comment
Access denied
Access denied