How to create layout with HTML nodes at runtime in Vue Diagram?
Using Syncfusion® Vue 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:
created: function () {
// Configures automatic layout
diagramInstance.layout = {
type: 'OrganizationalChart',
getLayoutInfo: (node, options) => {
/* tslint:disable:no-string-literal */
if (
node.data['Role'] === 'General Manager' &&
options.assistants &&
options.children
) {
options.assistants.push(options.children[0]);
options.children.splice(0, 1);
}
if (!options.hasSubTree) {
options.type = 'Right';
}
},
};
},
To render the layout, it’s essential to assign the JSON data to the dataSource property within the dataSourceSettings object of the diagram.
created: function () {
var diagramInstance =
document.getElementById('diagram').ej2_instances[0];
diagramInstance.dataSourceSettings = {
id: 'Id',
parentId: 'Manager',
dataSource: new DataManager(localBindData),
doBinding: (nodeModel, data, 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:
<template>
<div
:style="{
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>
</template>
Refer to the working sample for additional details and implementation: Sample
Conclusion
We hope you enjoyed learning how to create a layout with HTML nodes at runtime in Vue Diagram.
You can refer to our Vue 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 Vue 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!