Dagre is a JavaScript library designed for laying out directed graphs programmatically on the client-side. The package `dagre` at version 0.8.5, which is the latest available on the public npm registry under this name, was last published over six years ago and is effectively abandoned. While the GitHub repository shows recent activity and releases (v2.x, v3.x), these are published under the `@dagrejs/dagre` scoped package. Users attempting to install `dagre` directly will receive the unmaintained 0.8.5 version. This library's core functionality relies on `graphlib` for graph data structures, and it is often paired with rendering libraries like D3 for visualization. Its primary purpose is to automatically compute optimal node and edge positions in directed graphs, differentiating it from manual layout tools.
npm install dagreVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to create a graph using `graphlib`, add nodes and edges, apply the `dagre` layout, and then retrieve the calculated positions for nodes and bend points for edges. It uses CommonJS `require` for compatibility with `dagre@0.8.5`.
For actively maintained and modern features, install `@dagrejs/dagre` instead: `npm install @dagrejs/dagre`.
Use CommonJS `const dagre = require('dagre');` for module loading, or switch to the `@dagrejs/dagre` package for ESM support.Ensure `graphlib` is installed (`npm install graphlib`) and imported/required separately to create graph objects (e.g., `new graphlib.Graph()`).
Use a module loader (e.g., CommonJS `require` for `dagre@0.8.5`) or migrate to `@dagrejs/dagre` for modern ESM approaches.
Ensure `const dagre = require('dagre');` is used for CommonJS environments, or `dagre` is available globally if using a script tag. Also ensure `graphlib` is installed and its `Graph` class is used to create the graph object passed to `dagre.layout`.Verify that `dagre` is properly installed (`npm install dagre`) and imported/required in your module system. For older `dagre` versions, ensure it's available in the global scope if your integrating library expects it that way.