To perform a layout in Node.js, require elkjs, instantiate the ELK class, and call the .layout() method with a graph object following the ELK JSON format. The method returns a Promise that resolves with the laid-out graph.
const ELK = require('elkjs')
const elk = new ELK()
const graph = {
id: "root",
layoutOptions: { 'elk.algorithm': 'layered' },
children: [
{ id: "n1", width: 30, height: 30 },
{ id: "n2", width: 30, height: 30 },
{ id: "n3", width: 30, height: 30 }
],
edges: [
{ id: "e1", sources: [ "n1" ], targets: [ "n2" ] },
{ id: "e2", sources: [ "n1" ], targets: [ "n3" ] }
]
}
elk.layout(graph)
.then(console.log)
.catch(console.error)