Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@dagrejs/dagre
Advanced tools
@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.
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'
Cytoscape is a graph theory library for visualization and analysis. It provides a rich set of features for graph manipulation and visualization, including support for various layouts, styles, and interaction capabilities. Compared to @dagrejs/dagre, Cytoscape offers more comprehensive visualization options and is more suitable for complex graph analysis tasks.
d3-force is a module of the D3.js library that provides force-directed graph layout algorithms. It is highly customizable and integrates well with other D3 modules for creating interactive visualizations. While @dagrejs/dagre focuses on directed graphs and hierarchical layouts, d3-force is more general-purpose and can be used for a wider range of graph types.
vis-network is part of the vis.js library and provides tools for network visualization. It supports dynamic, interactive, and customizable network graphs. Compared to @dagrejs/dagre, vis-network offers more built-in interactivity and is easier to use for creating interactive network visualizations out of the box.
Dagre is a JavaScript library that makes it easy to lay out directed graphs on the client-side.
For more details, including examples and configuration options, please see our wiki.
There are 2 versions on NPM, but only the one in the DagreJs org is receiving updates right now.
dagre is licensed under the terms of the MIT License. See the LICENSE file for details.
FAQs
Graph layout for JavaScript
The npm package @dagrejs/dagre receives a total of 189,615 weekly downloads. As such, @dagrejs/dagre popularity was classified as popular.
We found that @dagrejs/dagre demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.