From f56c19598daef612dd9e1f7d0e905e55d584bfed Mon Sep 17 00:00:00 2001 From: Yuri Yaryshev Date: Sat, 17 Oct 2026 13:29:10 +0300 Subject: [PATCH] =?UTF-8?q?=D0=93=D0=B0=D0=BD=D1=82:=20=D0=BD=D0=B5=20?= =?UTF-8?q?=D1=80=D0=B8=D1=81=D0=BE=D0=B2=D0=B0=D1=82=D1=8C=20=D0=B7=D0=B0?= =?UTF-8?q?=D0=B2=D0=B8=D1=81=D0=B8=D0=BC=D0=BE=D1=81=D1=82=D0=B8,=20?= =?UTF-8?q?=D1=81=D0=BB=D0=B5=D0=B4=D1=83=D1=8E=D1=89=D0=B8=D0=B5=20=D0=B8?= =?UTF-8?q?=D0=B7=20=D1=86=D0=B5=D0=BF=D0=BE=D1=87=D0=BA=D0=B8=20=D0=B4?= =?UTF-8?q?=D1=80=D1=83=D0=B3=D0=B8=D1=85=20(=D1=82=D1=80=D0=B0=D0=BD?= =?UTF-8?q?=D0=B7=D0=B8=D1=82=D0=B8=D0=B2=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B5?= =?UTF-8?q?=D0=B4=D1=83=D0=BA=D1=86=D0=B8=D1=8F)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 5.5 --- packages/khbuild_process_viz/src/gantt.ts | 28 ++++++++++++++++++++ packages/khbuild_process_viz/src/viz.test.ts | 8 +++++- 2 files changed, 35 insertions(+), 1 deletion(-) 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">Работа'); // название внутри длинной полосы