Socket
Socket
Sign inDemoInstall

@dagrejs/dagre

Package Overview
Dependencies
Maintainers
3
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dagrejs/dagre

Graph layout for JavaScript


Version published
Weekly downloads
205K
decreased by-1.79%
Maintainers
3
Weekly downloads
 
Created

What is @dagrejs/dagre?

@dagrejs/dagre is a JavaScript library that provides facilities for graph layout. It is particularly useful for creating directed graphs and arranging nodes and edges in a visually appealing manner. The library is often used in conjunction with visualization libraries like D3.js to render the graphs.

What are @dagrejs/dagre's main functionalities?

Graph Creation

This feature allows you to create a 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('@dagrejs/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 allows you to compute the layout of the graph. The code sample shows how to use the `dagre.layout` function to calculate the positions of the nodes.

const dagre = require('@dagrejs/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: 25, y: 25 }
console.log(g.node('b')); // { label: 'Node B', width: 50, height: 50, x: 75, y: 75 }

Custom Node and Edge Attributes

This feature allows you to add custom attributes to nodes and edges. The code sample demonstrates how to set and retrieve custom attributes for nodes and edges.

const dagre = require('@dagrejs/dagre');
const g = new dagre.graphlib.Graph();
g.setGraph({});
g.setDefaultEdgeLabel(() => ({}));
g.setNode('a', { label: 'Node A', width: 50, height: 50, customAttr: 'customValue' });
g.setNode('b', { label: 'Node B', width: 50, height: 50 });
g.setEdge('a', 'b', { label: 'Edge from A to B', customEdgeAttr: 'edgeValue' });
dagre.layout(g);
console.log(g.node('a').customAttr); // 'customValue'
console.log(g.edge('a', 'b').customEdgeAttr); // 'edgeValue'

Other packages similar to @dagrejs/dagre

Keywords

FAQs

Package last updated on 23 May 2023

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