How to automatically increase the node size when text exceeds the node size in Angular Diagram?
This article explains how to automatically increase the node size when text exceeds the node size in Angular Diagram. Annotations can be added to both nodes and connectors in Angular Diagram. When the height and width of an annotation increase, the height and width of the associated node can also be adjusted accordingly.
The following code sample demonstrates how the height and width of a node increase with the corresponding increase in the height and width of its annotation:
// Initialize the diagram
<ejs-diagram #diagram id="diagram" width="100%" height="600"
[nodes]="nodes" [connectors]="connectors"
(textEdit)='textEdit($event)'>
</ejs-diagram>
// to automatically increase the node size when text exceeds the node size
public textEdit() {
let nodes = this.diagram.selectedItems.nodes[0];
setTimeout(() => {
let id = nodes.id;
let node = nodes;
let annotation = node.annotations[0].id;
let bounds = document
.getElementById(node.id + '_' + annotation)
.getBoundingClientRect();
if (bounds.height > node.height) {
node.height = bounds.height + 15;
this.diagram.dataBind();
} else if (bounds.height < 50) {
node.height = 50;
this.diagram.dataBind();
} else {
node.height = bounds.height + 15;
this.diagram.dataBind();
}
if (bounds.width > node.width) {
node.width = bounds.width + 15;
this.diagram.dataBind();
} else if (bounds.width < 50) {
node.width = 50;
this.diagram.dataBind();
} else {
node.width = bounds.width + 15;
this.diagram.dataBind();
}
}, 50);
}
The height and width of the annotation are obtained from the selected node. The bounds of the node’s annotation are stored in the variable “bounds”. If the annotation’s height is greater than the node’s height, then the node’s height is assigned the value of the annotation’s height plus 15. If the annotation’s width is greater than the node’s width, then the node’s width is assigned the value of the annotation’s width plus 15. A value of 15 is added to the annotation’s height or width to prevent the annotation from becoming congested in the node.
Refer to the working sample for additional details and implementation:Sample
Conclusion
We hope you enjoyed learning about how to automatically increase the node size when text exceeds the node size in Angular Diagram.
You can refer to our Angular Diagram feature tour page to learn about its other groundbreaking feature representations. You can explore our Angular Diagram documentation to understand how to present and manipulate data.
For current customers, you can check out our Angular 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 Angular Diagram and other Angular components. 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!