Socket
Socket
Sign inDemoInstall

dagre

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dagre

Graph layout for JavaScript


Version published
Weekly downloads
556K
increased by4.76%
Maintainers
1
Weekly downloads
 
Created

What is dagre?

The dagre npm package is a JavaScript library that provides facilities for graph layout. It is particularly useful for arranging nodes and edges in a directed graph, ensuring that the layout is visually appealing and easy to understand. Dagre uses a combination of algorithms to position nodes and edges in a way that minimizes edge crossings and distributes nodes evenly.

What are dagre's main functionalities?

Graph Creation

This feature allows you to create a new graph, add nodes, and define edges between them. The code sample demonstrates how to initialize a graph, set default properties, and add nodes and edges.

const dagre = require('dagre');
const g = new dagre.graphlib.Graph();
g.setGraph({});
g.setDefaultEdgeLabel(() => ({}));
g.setNode('a', { label: 'Node A', width: 50, height: 50 });
g.setNode('b', { label: 'Node B', width: 50, height: 50 });
g.setEdge('a', 'b');

Graph Layout

This feature performs the layout of the graph, positioning the nodes and edges in a visually appealing manner. The code sample shows how to apply the layout algorithm to the graph and retrieve the computed positions of the nodes.

const dagre = require('dagre');
const g = new dagre.graphlib.Graph();
g.setGraph({});
g.setDefaultEdgeLabel(() => ({}));
g.setNode('a', { label: 'Node A', width: 50, height: 50 });
g.setNode('b', { label: 'Node B', width: 50, height: 50 });
g.setEdge('a', 'b');
dagre.layout(g);
console.log(g.node('a')); // { label: 'Node A', width: 50, height: 50, x: 50, y: 50 }
console.log(g.node('b')); // { label: 'Node B', width: 50, height: 50, x: 150, y: 50 }

Other packages similar to dagre

Keywords

FAQs

Package last updated on 30 Jul 2015

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc