@foblex/flow-elk-layout

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

ELK.js 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 ELK.js

@foblex/flow-elk-layout

@foblex/flow-elk-layout adds a manual layout adapter for ELK.js in Foblex Flow.

Use this package when you need richer layout strategies than a simple directed tree and want access to layered, radial, force-style, or other ELK.js algorithms while still rendering and interacting through Foblex Flow.

Install

The easiest path is:

ng add @foblex/flow-elk-layout

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

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

For Nx workspaces:

nx g @foblex/flow-elk-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 ELK.js 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-elk-layout @foblex/platform@^1.0.4 @foblex/mediator@^1.1.3 @foblex/2d@^1.2.2 @foblex/utils@^1.1.1

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

What The Engine Does

ElkLayoutEngine calculates node positions from:

  • node ids
  • optional node sizes
  • source/target connections
  • shared layout options such as direction, spacing, and algorithm
  • optional ELK.js-specific layoutOptions

The engine returns only calculated node positions. Your app remains responsible for state management and for applying those positions to your own graph model.

For non-directional algorithms such as force, radial, random, or packing-oriented modes, the example integration can switch connectors into calculate mode so connection anchors follow the actual node geometry instead of a fixed left/right or top/bottom rule.

Minimal Setup

import { Component, inject } from '@angular/core';
import {
  EFLayoutDirection,
  IFLayoutConnection,
  IFLayoutNode,
  provideFLayout,
} from '@foblex/flow';
import {
  EElkLayoutAlgorithm,
  ElkLayoutEngine,
} from '@foblex/flow-elk-layout';

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

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

    const result = await this._layout.calculate(nodes, connections, {
      direction: EFLayoutDirection.TOP_BOTTOM,
      algorithm: EElkLayoutAlgorithm.LAYERED,
      nodeGap: 32,
      layerGap: 48,
      layoutOptions: {
        'elk.layered.spacing.nodeNodeBetweenLayers': '64',
      },
    });

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

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

Main Options

  • direction: EFLayoutDirection
  • algorithm: EElkLayoutAlgorithm
  • nodeGap: spacing between nodes
  • layerGap: spacing between layout layers
  • defaultNodeSize: fallback size when a node does not provide size
  • layoutOptions: raw ELK.js options passed through to the engine

Available algorithms:

  • EElkLayoutAlgorithm.FIXED
  • EElkLayoutAlgorithm.BOX
  • EElkLayoutAlgorithm.RANDOM
  • EElkLayoutAlgorithm.LAYERED
  • EElkLayoutAlgorithm.STRESS
  • EElkLayoutAlgorithm.MRTREE
  • EElkLayoutAlgorithm.RADIAL
  • EElkLayoutAlgorithm.FORCE
  • EElkLayoutAlgorithm.DISCO
  • EElkLayoutAlgorithm.SPORE_OVERLAP
  • EElkLayoutAlgorithm.SPORE_COMPACTION
  • EElkLayoutAlgorithm.RECT_PACKING

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 ELK.js

Choose ELK.js when you want:

  • more layout algorithms
  • richer spacing and routing controls
  • denser or less tree-like graphs
  • an engine you can tune further through raw ELK.js options

版本与发布记录

@foblex/flow-elk-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-elk-layout 的常见问题

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

ELK.js layout engine adapter for Foblex Flow.

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

在项目目录运行 npm install @foblex/flow-elk-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-elk-layout 支持 TypeScript 吗?

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

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

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

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

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

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

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

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

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