Articles in this section
Category / Section

How to create layout with HTML nodes at runtime in Angular Diagram?

3 mins read

This article explains how to create layouts with HTML nodes at runtime in Angular Diagram. Using Syncfusion® Angular Diagram, you can create automatic layouts that visually represent the structure of an organization and its relationships. In this knowledge base article, we will explain how to dynamically create layouts with HTML nodes using the event-handling mechanisms provided by Syncfusion®. For instance, you can utilize the created event to dynamically render a layout.

To implement an automatic layout, define the layout property of the diagram and specify the desired layout type. To add an assistant to the organizational chart, use the getLayoutInfo function.

Here’s a code snippet demonstrating this:

public created(): void {
   //set the Layout properties
   this.diagram.layout = {
     type: 'OrganizationalChart',
     getLayoutInfo: (node: Node, options: any) => {
       if ((node.data as DataInfo)['Role'] === 'General Manager') {
         options.assistants.push(options.children[0]);
         options.children.splice(0, 1);
       }
       if (!options.hasSubTree) {
         options.type = 'Right';
       }
     },
   };
   this.diagram.doLayout();
 } 

To render the layout, it’s essential to assign the JSON data to the dataSource property within the dataSourceSettings object of the diagram.

public created(): void {
   this.diagram.dataSourceSettings = {
     id: 'Id',
     parentId: 'Manager',

     //you need to set your data from db to dataManager
     dataSource: new DataManager(this.localBindData),
     doBinding: (nodeModel: NodeModel, data: object, diagram: Diagram) => {
       nodeModel.shape = {
         type: 'HTML',
       };
     },
   };    
 } 

We have created the layout using the HTML node. When creating HTML nodes dynamically, you define a nodeTemplate that specifies the structure and appearance of each node. Here’s an example of how you might define a nodeTemplate for HTML nodes:

<ng-template #nodeTemplate let-data>
   <ng-container>
     <div [ngStyle]="{ 'background': data.color, 'height': '100%', 'width': '100%', 'position': 'absolute' }">
       <div class="details">
         <p class="myTitle">{{ data.data.Role }}</p>
         <p>Description</p>
         <button
           type="button"
           id="nodeBtn_{{ data.data.Role }}"
           (click)="nodeBtnClick()"
           style="width:100px;margin-bottom: 30px;"
         >
           {{ data.data.Role }}
         </button>
       </div>
     </div>
   </ng-container>
 </ng-template> 

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

Conclusion

We hope you enjoyed learning how to create layout with HTML nodes at runtime 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