@foblex/flow-dagre-layout

中文文档
19.4.0发布于 2026/10/25MITTypeScriptESM + CJS近 30 天下载 1.4万

Dagre layout engine adapter for Foblex Flow.

原始使用文档
文档目录7 节
  1. Install
  2. What The Engine Does
  3. Minimal Setup
  4. Main Options
  5. Typical Integration Flow
  6. Example
  7. When To Choose Dagre

@foblex/flow-dagre-layout

@foblex/flow-dagre-layout adds a manual layout adapter for Dagre in Foblex Flow.

Use this package when your graph is mostly hierarchical and you want predictable left-to-right or top-to-bottom layout for workflows, trees, dependency maps, or org-chart style editors.

Install

The easiest path is:

ng add @foblex/flow-dagre-layout

If your app already manages Flow styles on its own, you can skip the default theme wiring:

ng add @foblex/flow-dagre-layout --skipTheme

For Nx workspaces:

nx g @foblex/flow-dagre-layout:add

ng add ensures these packages are present and only adds the missing ones:

  • @foblex/flow
  • @foblex/platform
  • @foblex/mediator
  • @foblex/2d
  • @foblex/utils
  • the Dagre package itself

It also adds node_modules/@foblex/flow/styles/default.scss to application styles when the theme entry is missing.

If you prefer manual installation:

npm install @foblex/flow @foblex/flow-dagre-layout @foblex/platform@^1.0.4 @foblex/mediator@^1.1.3 @foblex/2d@^1.2.2 @foblex/utils@^1.1.1

The underlying dagre package is shipped as a runtime dependency of this package, so you do not need to install it separately.

What The Engine Does

DagreLayoutEngine calculates node positions from:

  • node ids
  • optional node sizes
  • source/target connections
  • layout options such as direction, spacing, and algorithm

The engine returns only calculated node positions. Your app stays in charge of graph state and decides how to merge those positions back into your own node model.

Minimal Setup

import { Component, inject } from '@angular/core';
import {
  EFLayoutDirection,
  IFLayoutConnection,
  IFLayoutNode,
  provideFLayout,
} from '@foblex/flow';
import {
  DagreLayoutEngine,
  EDagreLayoutAlgorithm,
} from '@foblex/flow-dagre-layout';

@Component({
  standalone: true,
  providers: [provideFLayout(DagreLayoutEngine)],
  template: '',
})
export class WorkflowLayoutExample {
  private readonly _layout = inject(DagreLayoutEngine);

  protected async relayout(): Promise<void> {
    const nodes: IFLayoutNode[] = [
      { id: 'A' },
      { id: 'B' },
      { id: 'C' },
    ];
    const connections: IFLayoutConnection[] = [
      { source: 'A', target: 'B' },
      { source: 'B', target: 'C' },
    ];

    const result = await this._layout.calculate(nodes, connections, {
      direction: EFLayoutDirection.LEFT_RIGHT,
      algorithm: EDagreLayoutAlgorithm.NETWORK_SIMPLEX,
      nodeGap: 32,
      layerGap: 48,
    });

    const positions = new Map(result.nodes.map((node) => [node.id, node.position]));

    console.log(positions.get('A'));
  }
}

Main Options

  • direction: EFLayoutDirection
  • algorithm: EDagreLayoutAlgorithm
  • nodeGap: horizontal or sibling spacing
  • layerGap: spacing between ranks or levels
  • defaultNodeSize: fallback size when a node does not provide size

Available algorithms:

  • EDagreLayoutAlgorithm.NETWORK_SIMPLEX
  • EDagreLayoutAlgorithm.TIGHT_TREE
  • EDagreLayoutAlgorithm.LONGEST_PATH

Typical Integration Flow

  1. Build your own graph data.
  2. Convert it to IFLayoutNode[] and IFLayoutConnection[].
  3. Call calculate(...).
  4. Merge returned positions into your view model.
  5. Render nodes in f-flow.

Example

When To Choose Dagre

Choose Dagre when you want:

  • fast directed layout
  • tree-like or layered structure
  • simple and predictable spacing controls
  • a smaller option surface than ELK.js

版本与发布记录

@foblex/flow-dagre-layout 共发布 15 个版本,首次发布于 2026/04/14;过去 12 个月发布了 15 个版本。

版本发布日期距今
19.4.0latest2026/10/2521 天前
19.3.02026/09/281 个月前
19.2.02026/09/211 个月前
19.1.72026/09/062 个月前
19.1.62026/07/283 个月前
19.1.52026/07/283 个月前

关于 @foblex/flow-dagre-layout 的常见问题

@foblex/flow-dagre-layout 是什么?

Dagre layout engine adapter for Foblex Flow.

如何安装 @foblex/flow-dagre-layout?

在项目目录运行 npm install @foblex/flow-dagre-layout,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@foblex/flow(^19.4.0)、@angular/core(>=17.3.0)、@angular/common(>=17.3.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@foblex/flow-dagre-layout 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@foblex/flow-dagre-layout 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@foblex/flow-dagre-layout 可以商用吗?

@foblex/flow-dagre-layout 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@foblex/flow-dagre-layout 的下载量有多少?

根据 npm 官方下载统计,@foblex/flow-dagre-layout 在 2026/10/15 – 2026/11/13 这 30 天内被下载 13,558 次,日均约 452 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@foblex/flow-dagre-layout 还在维护吗?

最新版本 19.4.0 发布于 2026/10/25(21 天前);至今共发布 15 个版本,其中过去 12 个月发布了 15 个;首次发布于 2026/04/14。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。