diff --git a/packages/khbuild_process_viz/src/gantt.ts b/packages/khbuild_process_viz/src/gantt.ts index c15841c..834a9bc 100644 --- a/packages/khbuild_process_viz/src/gantt.ts +++ b/packages/khbuild_process_viz/src/gantt.ts @@ -148,6 +148,32 @@ export function placeLabels(items: Array<{ x: number; row: ProcessRow }>): { lab return { labels, levels: labels.length ? Math.max(...labels.map((l) => l.level)) + 1 : 0 }; } +/** Зависимости, которые следуют из цепочки других зависимостей (A→B, если B достижим из A через другие шаги): на Ганте не рисуются, смысл графа не меняется. Ключ - `от>к`. */ +export function redundantDependencies(rows: ProcessRow[]): Set { + const ids = new Set(rows.map((r) => r.id)); + const succ = new Map(); + for (const r of rows) for (const d of r.dependsOn) if (ids.has(d)) succ.set(d, [...(succ.get(d) ?? []), r.id]); + const reachable = (from: string, to: string): boolean => { + const stack = [from]; + const seen = new Set(); + while (stack.length) { + const cur = stack.pop()!; + for (const next of succ.get(cur) ?? []) { + if (cur === from && next === to) continue; + if (next === to) return true; + if (!seen.has(next)) { + seen.add(next); + stack.push(next); + } + } + } + return false; + }; + const out = new Set(); + for (const r of rows) for (const d of r.dependsOn) if (ids.has(d) && reachable(d, r.id)) out.add(`${d}>${r.id}`); + return out; +} + export function renderGantt(model: ProcessModel, schedule: Schedule, opts: GanttOptions = {}): string { const px = clampPx(opts.px); const collapsedSet = new Set(opts.collapsed ?? []); @@ -247,9 +273,11 @@ export function renderGantt(model: ProcessModel, schedule: Schedule, opts: Gantt }; if (opts.deps !== false) { const arrows: string[] = []; + const redundant = redundantDependencies(model.rows); for (const g of groups) { for (const { row } of g.rows) { for (const dep of row.dependsOn) { + if (redundant.has(`${dep}>${row.id}`)) continue; const from = anchor(dep); const to = anchor(row.id); if (!from || !to) continue; diff --git a/packages/khbuild_process_viz/src/viz.test.ts b/packages/khbuild_process_viz/src/viz.test.ts index 9636cca..15b206b 100644 --- a/packages/khbuild_process_viz/src/viz.test.ts +++ b/packages/khbuild_process_viz/src/viz.test.ts @@ -1,7 +1,7 @@ import { describe, expect, it } from "vitest"; import { renderPage } from "./html.js"; import { renderAris } from "./aris.js"; -import { clampPx, placeLabels, renderGantt, stageOrder, summarizeGroup } from "./gantt.js"; +import { clampPx, placeLabels, redundantDependencies, renderGantt, stageOrder, summarizeGroup } from "./gantt.js"; import { buildApi } from "./http-api.js"; import { buildModel, describeResponsible, loadModel, mapRow, type ProcessModel } from "./model.js"; import { computeSchedule, parseConstraint, parseDuration, parseDurationInfo } from "./schedule.js"; @@ -332,6 +332,12 @@ describe("Гант: группы, вехи, свёртывание, масшта expect(arrows(renderGantt(ms, sch, {}))).toBeGreaterThan(arrows(shut)); }); + it("зависимость, следующая из цепочки других, не рисуется стрелкой (A→C при A→B→C)", () => { + const rows = [row({ id: "A" }), row({ id: "B", depends_on: "A" }), row({ id: "C", depends_on: "B", depends_on2: "A" })]; + const redundant = redundantDependencies(rows); + expect([...redundant]).toEqual(["A>C"]); + }); + it("подпись полосы - название работы (внутри полосы или над ней), id справа снизу, без дат", () => { const svg = renderGantt(ms, sch, { px: 20 }); expect(svg).toContain('fill="#fff">Работа'); // название внутри длинной полосы