How to create layout with HTML node in JavaScript Diagram?
Html elements can be embedded in the JavaScript Diagram through Html type node. The shape property of node allows you to set the type of node and to create a HTML node it should be set as "HTML"
Diagram provides a set of built-in automatic layout algorithms, which are used to arrange nodes automatically based on a predefined layout logic. It includes the following layout modes:
- Hierarchical layout
- Organization chart layout
- Radial tree layout
- Symmetric layout
- Mind Map layout
- Complex hierarchical tree layout
Create layout in diagram
- To generate layout from DataSource, you have to define the business object and add the necessary data to the DataSource collection. During the layout generation, nodes and connectors can be generated automatically with the information provided through data source and those items will be added to NodeCollection and ConnectorCollection respectively.
- Diagram as various layout you can set as per requirement. Layout to be defined while initializing the diagram."OrganizationalChart" type layout is used in this example. The following code explains how to define layout.
let diagram: Diagram = new Diagram({
width: '100%', height: '499px',
//Configures automatic layout
layout: {
type: 'OrganizationalChart',
getLayoutInfo: (node, options) => {
/* tslint:disable:no-string-literal */
if (node.data['Role'] === 'General Manager') {
options.assistants.push(options.children[0]);
options.children.splice(0, 1);
}
if (!options.hasSubTree) {
options.type = 'Right';
}
}
},
nodeTemplate:'#nodetemplate',
getNodeDefaults: nodeDefaults,
}
Create the layout with HTML Node
- To create a HTML Node, you should set the type of the shape as HTML. following code example explains the defining of shape type as HTML.
- To add template define the template in html file and append the id to the nodeTemplate property
function nodeDefaults(obj, diagram) { obj.style = { fill: 'none', strokeColor: 'none', color: 'white' }; obj.expandIcon = { height: 10, width: 10, shape: 'None', fill: 'lightgray', offset: {x: 0.5, y: 1} }; obj.shape = { type: 'HTML' }; }<script id="nodetemplate" type="text/x-template">
<div>
<div class=" componentSummary">
<h1 class="myTitle">${data.Role}</h1>
<div class="componentSummaryDetails">
<div class="details">
<h2>0.2 GB</h2>
<span class="pf-emphasis">DATA2</span>
</div>
<div class="details">
<h2>0.3%</h2>
<span class="pf-emphasis">DATA3</span>
</div>
</div>
</div>
</div>
</script>
Sample Link: https://stackblitz.com/edit/7du2vj-29p2mh?file=index.ts,index.html
Conclusion
I hope you enjoyed learning how to create layout with HTML node in 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, Direct-Trac, or feedback portal. We are always happy to assist you!