Articles in this section
Category / Section

How To Increase Height When Child Nodes are Added in Angular Diagram?

2 mins read

In this article, you can learn about how to increase height when child nodes are added in an Angular Diagram. The Syncfusion® Angular Diagram component makes it possible to dynamically adjust the diagram’s height as new child nodes are added. This ensures that all nodes remain visible without the need for scrollbars. This is particularly useful in scenarios where nodes are added to the diagram dynamically, and you want the diagram to resize automatically.

Below is a code example demonstrating how to achieve this:

//Method called when we add a new node dynamically using buttons.
public addChild() {
   let parent =
     this.diagram.selectedItems.nodes.length > 0
       ? this.diagram.selectedItems.nodes[0]
       : this.diagram.nodes[0];
   // Define a new node with a unique ID and specified dimensions.
   let newNode = { id: randomId(), width: 100, height: 50 };
   this.diagram.add(newNode);

   // Create a new connector between the parent node and the new node.
   let newCon = { id: randomId(), sourceID: parent.id, targetID: newNode.id };
   this.diagram.add(newCon);
   
   // Execute the layout to arrange the nodes and connectors.
   this.diagram.doLayout();
   
   // Calculate the current diagram height.
   let diagramHeight = Number(this.diagram.height);
   // Retrieve the newly added node object.
   let newlyAddedNode: NodeModel = this.diagram.getObject(newNode.id);  
   // Calculate the bottom position of the newly added node.
   let bottom = newlyAddedNode.offsetY + newlyAddedNode.height / 2;
   // Adjust the diagram height if the new node extends beyond its current height.
   if (newlyAddedNode && bottom > diagramHeight) {
     this.diagram.height = bottom + 20;
     this.diagram.dataBind();
   }
}

Refer to the working sample for additional details and implementation: Click Here

Conclusion:

We hope you enjoyed about how to increase diagram height when new child nodes are added 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!

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