Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

[AntVDagreLayout] ranksep 未透传给 dagre 内核,导致层间距计算与 nodesep 不一致,想确认是否属于设计如此

オープン
#293 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
半日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
typescript

調査の方向性

The padding uses ranksep in src/algorithm/antv-dagre/index.ts (height = size[1] + 2 * vertisep), but the call to the dagre kernel layout(g, {...}) passes only nodesep. Run the reproduction script for edgeLabelSpace true and false with ranksep 50 and 200 to confirm the layer spacing values in the table. Before changing code, the maintainers must decide whether omitting ranksep was intentional. If they agree it is a bug, done means passing ranksep to the kernel and getting the 160/610/160/610 spacings.

索引モデルが issue の本文から書いたものです。

説明

版本
  • @antv/layout 2.0.1(npm beta),在 v5 分支最新代码(62bb479)上同样可复现
  • 对照版本:@antv/layout 0.3.25 的 DagreLayout
现象

在 AntVDagreLayout 中,ranksep 仅被用作节点的上下 padding(src/algorithm/antv-dagre/index.ts 中 height = size[1] + 2 * vertisep)。而在调用底层 dagre 内核的 layout(g, {...}) 时,并没有传入 ranksep(只传了 nodesep)。

这就导致内核在缺少 ranksep 时,实际走了以下兜底处理:

  • edgeLabelSpace: true(默认):makeSpaceForEdgeLabels 内部直接将未传入的 ranksep 视为 0,因此内核贡献的层间距为 0;
  • edgeLabelSpace: false:内核直接使用了内置的默认值 50,用户配置的 ranksep 完全不生效。

对比来看,水平方向的 nodesep 既参与了 padding 扩充,又正常透传给了内核,因此同层间距与层间距的计算逻辑产生了分歧。

复现
const { AntVDagreLayout } = require('@antv/layout');

const data = {
  nodes: [{ id: 'a' }, { id: 'b' }, { id: 'c' }],
  edges: [
    { id: 'e1', source: 'a', target: 'b' },
    { id: 'e2', source: 'a', target: 'c' },
  ],
};

(async () => {
  for (const edgeLabelSpace of [true, false]) {
    for (const ranksep of [50, 200]) {
      const layout = new AntVDagreLayout({ nodeSize: 10, ranksep, edgeLabelSpace });
      await layout.execute(data);
      const pos = {};
      layout.forEachNode((node) => (pos[node.id] = node));
      // 相邻层中心距离 (Δy) / 同层中心距离 (Δx)
      console.log(edgeLabelSpace, ranksep, pos.b.y - pos.a.y, pos.c.x - pos.b.x);
    }
  }
})();

实测结果(nodeSize: 10,nodesep 取默认值 50,测量值为节点中心距):

edgeLabelSpace ranksep 2.0.1 层间距 (Δy) 0.3.25 层间距 (Δy) 同层间距 (Δx,两版本相同)
true 50 110 160 160
true 200 410 610 160
false 50 160 160 160
false 200 460 610 160

间距公式拆解:

  • 2.0.1 层间距:nodeSize + 2 × ranksep + 内核间距(edgeLabelSpace: true 时内核间距为 0;false 时固定为 50)
  • 0.3.25 层间距:nodeSize + 2 × ranksep + 1 × ranksep = nodeSize + 3 × ranksep(与 edgeLabelSpace 无关)
  • 同层间距(两版本一致):nodeSize + 2 × nodesep + 1 × nodesep = nodeSize + 3 × nodesep
想确认的问题
  1. 不给内核传 ranksep 是特意这样设计的,还是属于遗漏?
    如果是特意设计的,那么在 edgeLabelSpace: false 时因内核默认值而固定多出来的 50px 间距,是否也符合预期?

  2. 如果属于遗漏,是否方便统一修复?
    若在调用内核时补齐 ranksep 参数:

    • 上述四种场景的层间距将统一为 160 / 610 / 160 / 610,与 0.3.25 保持一致,同层间距与层间距的公式也能完全对齐;
    • 不过需要注意的是,在默认配置(edgeLabelSpace: true)下,现有用户的实际层间距会普遍增大一个 ranksep(默认参数下由 nodeSize + 100 变为 nodeSize + 150)。

想了解一下维护团队对该改动的看法。如果大家赞同这种对齐方案,我可以提个 PR 协助修复。

主要言語
TypeScript
スター
279
フォーク
62
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

antvis/layout のほかの issue

antvis/layout の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。