🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

elkjs

Package Overview
Dependencies
Maintainers
0
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

elkjs

Automatic graph layout based on Sugiyama's algorithm. Specialized for data flow diagrams and ports.

0.10.0
latest
Source
npm
Version published
Weekly downloads
773K
-9.52%
Maintainers
0
Weekly downloads
 
Created

What is elkjs?

elkjs is a JavaScript library for layouting graphs and diagrams. It provides a powerful and flexible way to automatically arrange nodes and edges in a visually appealing manner.

What are elkjs's main functionalities?

Basic Graph Layout

This feature allows you to create a basic graph layout using the 'layered' algorithm. The code sample demonstrates how to define nodes and edges and then apply the layout algorithm to arrange them.

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 }
  ],
  edges: [
    { id: 'e1', sources: ['n1'], targets: ['n2'] }
  ]
};

elk.layout(graph).then((layout) => {
  console.log(layout);
});

Custom Layout Options

This feature allows you to customize the layout algorithm. The code sample demonstrates how to use the 'force' algorithm to arrange nodes and edges in a graph.

const ELK = require('elkjs');
const elk = new ELK();

const graph = {
  id: 'root',
  layoutOptions: { 'elk.algorithm': 'force' },
  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: ['n2'], targets: ['n3'] }
  ]
};

elk.layout(graph).then((layout) => {
  console.log(layout);
});

Hierarchical Layout

This feature allows you to create hierarchical layouts using the 'layered' algorithm. The code sample demonstrates how to arrange nodes and edges in a hierarchical manner.

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((layout) => {
  console.log(layout);
});

Other packages similar to elkjs

Keywords

graph

FAQs

Package last updated on 13 Mar 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts