Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta
#293 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
Mezza giornata
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
typescript

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

版本
  • @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 协助修复。

Lingua principale
TypeScript
Stelle
279
Fork
62
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di antvis/layout

Tutte le issue di antvis/layout

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.