diff --git a/packages/khbuild_process_viz/src/gantt.ts b/packages/khbuild_process_viz/src/gantt.ts index 0c38b75..3bdef9d 100644 --- a/packages/khbuild_process_viz/src/gantt.ts +++ b/packages/khbuild_process_viz/src/gantt.ts @@ -149,6 +149,9 @@ export function placeLabels(items: Array<{ x: number; row: ProcessRow }>): { lab } /** Зависимости, которые следуют из цепочки других зависимостей (A→B, если B достижим из A через другие шаги): на Ганте не рисуются, смысл графа не меняется. Ключ - `от>к`. */ +/** Часть имени CSS-класса из id шага (точка в CP-4.5 и т. п. заменяется). */ +const safeId = (id: string): string => id.replace(/[^A-Za-z0-9]/g, "_"); + export function redundantDependencies(rows: ProcessRow[]): Set { const ids = new Set(rows.map((r) => r.id)); const succ = new Map(); @@ -271,10 +274,12 @@ export function renderGantt(model: ProcessModel, schedule: Schedule, opts: Gantt const m = g.summary.milestones.find((mm) => mm.row.id === id); return m ? { xs: x(m.day), xe: x(m.day), y: g.top + GROUP_PAD + g.levels * LABEL_STEP + GROUP_BAR_H / 2 } : null; }; + const ghostMarks: string[] = []; // контурные ромбы вех на строках зависимых шагов (рисуются поверх строк) + const vlines: string[] = []; + const vlIds = new Set(); // вехи, у которых есть контурные ромбы (вертикаль показывается при наведении) if (opts.deps !== false) { const arrows: string[] = []; const ghostLines: string[] = []; - const ghostMarks: string[] = []; const redundant = redundantDependencies(model.rows); for (const g of groups) { for (const { row } of g.rows) { @@ -291,23 +296,26 @@ export function renderGantt(model: ProcessModel, schedule: Schedule, opts: Gantt // зависимость от вехи: вместо вертикали через весь план - контурный ромб вехи на строке зависимого шага, стрелка идёт от него const gc = color(groupOf.get(dep)!.stage).stroke; const gy = to.y; - const ghost = ``; + const sid = safeId(dep); + vlIds.add(sid); + vlines.push(``); + const ghost = ``; const several = row.dependsOn.filter((d) => model.rows.find((r) => r.id === d)?.isMilestone && !redundant.has(`${d}>${row.id}`)).length > 1; const gl = `${esc(several ? dep : truncate(`${dep} ${depRow.actionName ?? ""}`, 40))}`; // несколько вех на одной строке: только id, чтобы подписи не налезали const x2e = row.isMilestone ? x2 - 10 : x2; // у вехи-цели стрелка заканчивается перед ромбом, иначе остриё закрыто ромбом const lp = x2e > x1 + 7 ? `M${x1 + 7} ${gy} H${x2e}` : x2e < x1 - 7 ? `M${x1 - 7} ${gy} H${x2e}` : ""; // назад - если шаг начинается раньше вехи (противоречие) - if (lp) ghostLines.push(`${tooltip([label])}`); + if (lp) ghostLines.push(`${tooltip([label])}`); ghostMarks.push(`${tooltip([label])}${ghost}${gl}`); continue; } const d = x2 >= x1 ? `M${x1} ${from.y} V${to.y} H${x2}` : `M${x1} ${from.y} H${x1 + 6} V${to.y} H${x2}`; - arrows.push(`${tooltip([label])}`); + arrows.push(`${tooltip([label])}`); } } } // слои снизу вверх: линии от контурных вех (почти фон), обычные зависимости, контурные ромбы с подписями (поверх линий) out.push(`${ghostLines.join("")}${arrows.join("")}`); - out.push(`${ghostMarks.join("")}`); + } // Строки раскрытых групп @@ -362,7 +370,7 @@ export function renderGantt(model: ProcessModel, schedule: Schedule, opts: Gantt const px0 = x(t.end); const late = t.deadline !== null && t.end > t.deadline; if (t.deadline !== null && t.end !== t.deadline) out.push(``); - out.push(``); + out.push(``); if (!hasBar && name) { out.push(`${esc(name)}`); } @@ -376,7 +384,7 @@ export function renderGantt(model: ProcessModel, schedule: Schedule, opts: Gantt } if (t.deadline !== null) { const rx = x(t.deadline); - out.push(`${esc(`Крайний срок: день ${t.deadline}`)}`); + out.push(`${esc(`Крайний срок: день ${t.deadline}`)}`); } out.push(""); } @@ -412,18 +420,18 @@ export function renderGantt(model: ProcessModel, schedule: Schedule, opts: Gantt for (const [a, b] of s.segments) { out.push(``); } - const diamond = (dx: number, size: number, late = false) => ``; + const diamond = (dx: number, size: number, late = false, id?: string) => ``; const markDays = new Set(s.milestones.map((m) => m.day)); if (!markDays.has(s.start)) out.push(diamond(x(s.start), 6)); if (!markDays.has(s.end)) out.push(diamond(x(s.end), 6)); for (const m of s.milestones) { if (m.deadline !== null && m.day !== m.deadline) out.push(``); - out.push(diamond(x(m.day), 8, m.deadline !== null && m.day > m.deadline)); + out.push(diamond(x(m.day), 8, m.deadline !== null && m.day > m.deadline, m.row.id)); } for (const m of s.milestones) { if (m.deadline === null) continue; const rx = x(m.deadline); - out.push(`${esc(`Крайний срок: ${m.row.id}, день ${m.deadline}`)}`); + out.push(`${esc(`Крайний срок: ${m.row.id}, день ${m.deadline}`)}`); } for (const l of g.labels) { const ly = barY - 4 - l.level * LABEL_STEP; @@ -433,6 +441,8 @@ export function renderGantt(model: ProcessModel, schedule: Schedule, opts: Gantt } // Легенда + out.push(`${vlines.join("")}`); + out.push(`${ghostMarks.join("")}`); const ly = height - 20; out.push( `веха` + @@ -445,6 +455,7 @@ export function renderGantt(model: ProcessModel, schedule: Schedule, opts: Gantt `крайний срок`, ); - const defs = ``; + const hoverCss = `.vl{opacity:0;pointer-events:none}.dep:hover .dl{stroke:#e91e63;stroke-width:3}` + [...vlIds].map((i) => `svg:has(.ms-${i}:hover) .vl-${i}{opacity:1}`).join(""); + const defs = ``; return svgDoc(width, height, defs, out.join("\n"), `data-left="${GANTT_LEFT}" data-px="${px}"`); }