Гант: подписи работ на полосах, id справа снизу, зависимости между вехами свёрнутых групп; тесты; docs
All checks were successful
ci / test (push) Successful in 19s
ci / deploy (push) Successful in 1m21s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-14 18:55:05 +03:00
parent 3a14ead196
commit 60ad1db12e
3 changed files with 81 additions and 23 deletions

View File

@@ -24,3 +24,4 @@
20. **Включение/выключение проектов (14.10.2026)**: флаг `assistant_project.is_enabled` (уже был) теперь действует во всех шагах. Шаг 2 и список менеджеров берут только включённые проекты; в шаге 4 агенту в «Ограничениях среды» перечисляются ОТКЛЮЧЁННЫЕ проекты менеджера: не обсуждать, не напоминать, не писать (id таких проектов исключаются из `allowedJobIds`), на сообщения о них отвечать, что ассистент по проекту отключён. Переключение: `update assistant_project set is_enabled = false where jt_job_id = '...'` (Supabase Studio); вступает в силу со следующего запуска агента. Тест `agents.int.test.ts` («отключённый проект»).
21. **Сообщения от любых участников чата (14.10.2026)**: в чате менеджера (`construction_manager.slack_channel_id`) принимаются сообщения всех участников канала и обрабатываются как сообщения менеджера; отправитель сохраняется в `slack_message_log.sender_slack_user_id` (миграция 008; для файлов из папки Drive - null). Каналы из `slack.channelIds` без закреплённого менеджера по-прежнему определяют менеджера по автору. В промт шага 4 добавлена строка про других участников чата. Причина: аудио Arthur Atanoff в чате Zachary Gange не обрабатывалось, т.к. отправитель не совпадал с `slack_user_id` менеджера.
22. **Права на таблицы (14.10.2026)**: после подключения Mathesar все таблицы public стали принадлежать роли mathesar_process, и миграция 008 под khb_app падала (`must be owner of table`). Роль khb_app включена в mathesar_process (`grant mathesar_process to khb_app`), владельцы не менялись. Если Mathesar снова сменит владельцев - так же работает; при отзыве членства деплой с миграциями упадёт.
23. **Гант процесса: формат по образцу SlideFormat (14.10.2026)**: на полосах вместо дат - название работы (внутри полосы белым, если помещается, иначе над полосой цветом этапа); id шага (CP-x, S-x) мелко справа снизу под полосой (у ромба вехи - справа от него); строка шага стала выше (36 px); ромбы вех чёрные; стрелки зависимостей тёмные с вертикалью от конца предшественника. Свёрнутая группа сохраняет зависимости между вехами: стрелки идут между ромбами сводных полос (для шагов свёрнутых групп, не являющихся вехами, стрелки не рисуются). Тесты в `viz.test.ts`.

View File

@@ -21,7 +21,9 @@ export const GANTT_DEFAULT_PX = 5;
export const GANTT_MIN_PX = 0.5;
export const GANTT_MAX_PX = 40;
const ROW = 24;
const ROW = 36; // строка шага: подпись над полосой, полоса, id справа снизу
const BAR_CY = 21; // центр полосы от верха строки
const BAR_H = 14;
const HEAD = 76;
const GROUP_BAR_H = 14; // высота сводной полосы
const GROUP_PAD = 8; // отступ сверху и снизу в строке группы
@@ -148,7 +150,7 @@ export function renderGantt(model: ProcessModel, schedule: Schedule, opts: Gantt
if (!g.collapsed) {
for (const { row } of g.rows) {
rowTop.set(row.id, y);
yOf.set(row.id, y + ROW / 2);
yOf.set(row.id, y + BAR_CY);
y += ROW;
}
}
@@ -157,7 +159,11 @@ export function renderGantt(model: ProcessModel, schedule: Schedule, opts: Gantt
const height = y + 40;
const days = Math.ceil((schedule.maxDay + 10) / 10) * 10;
// подписи вех могут выступать за правый край оси
const labelRight = Math.max(0, ...groups.flatMap((g) => g.labels.map((l) => l.x + (l.text.length * CHAR_W) / 2)));
const labelRight = Math.max(
0,
...groups.flatMap((g) => g.labels.map((l) => l.x + (l.text.length * CHAR_W) / 2)),
...groups.flatMap((g) => (g.collapsed ? [] : g.rows.map(({ row, t }) => x(Math.max(t.start, t.end)) + 14 + (row.actionName ?? row.description ?? "").length * CHAR_W))),
);
const width = Math.round(Math.max(GANTT_LEFT + days * px + 30, labelRight + 16));
const out: string[] = [];
@@ -188,24 +194,36 @@ export function renderGantt(model: ProcessModel, schedule: Schedule, opts: Gantt
}
}
// Зависимости под полосами (только между видимыми строками)
// Зависимости под полосами. Если группа свёрнута, от неё остаются вехи: стрелки идут между ромбами сводных полос.
const groupOf = new Map<string, Group>();
for (const g of groups) for (const { row } of g.rows) groupOf.set(row.id, g);
const anchor = (id: string): { xs: number; xe: number; y: number } | null => {
const tm = schedule.timings.get(id);
const g = groupOf.get(id);
if (!tm || !g) return null;
if (!g.collapsed) {
const yy = yOf.get(id);
return yy === undefined ? null : { xs: x(tm.start), xe: x(tm.end), y: yy };
}
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;
};
if (opts.deps !== false) {
const arrows: string[] = [];
for (const g of groups) {
for (const { row, t } of g.rows) {
for (const { row } of g.rows) {
for (const dep of row.dependsOn) {
const dt = schedule.timings.get(dep);
const y1 = yOf.get(dep);
const y2 = yOf.get(row.id);
if (!dt || y1 === undefined || y2 === undefined) continue;
const x1 = x(dt.end);
const x2 = x(t.start);
const xm = Math.min(x2 - 4, Math.max(x1 + 4, (x1 + x2) / 2));
arrows.push(`<path d="M${x1} ${y1} H${xm} V${y2} H${x2}" fill="none" stroke="#9aa0a6" stroke-width="0.8" marker-end="url(#arr)"/>`);
const from = anchor(dep);
const to = anchor(row.id);
if (!from || !to) continue;
const x1 = from.xe;
const x2 = to.xs;
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(`<path d="${d}" fill="none" stroke="#444" stroke-width="1.1" marker-end="url(#arr)"/>`);
}
}
}
out.push(`<g opacity="0.7">${arrows.join("")}</g>`);
out.push(`<g opacity="0.75">${arrows.join("")}</g>`);
}
// Строки раскрытых групп
@@ -214,7 +232,7 @@ export function renderGantt(model: ProcessModel, schedule: Schedule, opts: Gantt
const c = color(g.stage);
for (const { row, t } of g.rows) {
const top = rowTop.get(row.id)!;
const cy = top + ROW / 2;
const cy = top + BAR_CY;
const warn = conflicts.get(row.id);
const tip = tooltip([
`${row.id} - ${row.actionName ?? ""}${row.isMilestone ? " (веха)" : ""}`,
@@ -228,24 +246,46 @@ export function renderGantt(model: ProcessModel, schedule: Schedule, opts: Gantt
row.questions ? `Вопрос: ${row.questions}` : null,
]);
const ms = row.isMilestone;
const name = row.actionName ?? row.description ?? "";
out.push(`<g${t.fromConstraint || t.kind === "recurring" ? "" : ' opacity="0.65"'}>${tip}`);
out.push(`<text x="12" y="${cy + 4}" font-weight="${ms ? 700 : 500}" fill="${warn ? "#b00020" : "#222"}">${esc(row.id)}</text>`);
out.push(`<text x="62" y="${cy + 4}" font-weight="${ms ? 600 : 400}" fill="#222">${esc(truncate(row.actionName ?? row.description ?? "", 52))}</text>`);
out.push(`<text x="62" y="${cy + 4}" font-weight="${ms ? 600 : 400}" fill="#222">${esc(truncate(name, 52))}</text>`);
if (row.questions) out.push(`<circle cx="${GANTT_LEFT - 14}" cy="${cy}" r="4" fill="#e6a100"><title>${esc(row.questions)}</title></circle>`);
const stroke = warn ? "#d32f2f" : c.stroke;
const dash = t.approx ? ' stroke-dasharray="4 2"' : "";
const textW = name.length * CHAR_W;
const idText = (tx: number, anchor: "start" | "end") =>
out.push(`<text x="${tx}" y="${top + ROW - 3}" text-anchor="${anchor}" font-size="9" letter-spacing="0.5" fill="#777">${esc(row.id)}</text>`);
if (t.kind === "recurring") {
out.push(`<rect x="${x(t.start)}" y="${cy - 4}" width="${Math.max(2, (t.end - t.start) * px)}" height="8" rx="3" fill="url(#hatch)" stroke="${c.stroke}" stroke-width="0.8"/>`);
const w = Math.max(2, (t.end - t.start) * px);
out.push(`<rect x="${x(t.start)}" y="${cy - 4}" width="${w}" height="8" rx="3" fill="url(#hatch)" stroke="${c.stroke}" stroke-width="0.8"/>`);
out.push(`<text x="${x(t.start) + 2}" y="${cy - 9}" font-size="11" font-weight="600" fill="${c.stroke}">${esc(name)}</text>`);
idText(x(t.end), "end");
} else {
if (t.end > t.start) {
out.push(`<rect x="${x(t.start)}" y="${cy - 7}" width="${Math.max(3, (t.end - t.start) * px)}" height="14" rx="3" fill="${ms ? c.stroke : c.fill}" fill-opacity="${ms ? 0.55 : 1}" stroke="${stroke}" stroke-width="${warn ? 1.6 : 1.1}"${dash}/>`);
const hasBar = t.end > t.start;
const w = Math.max(3, (t.end - t.start) * px);
const solid = !t.approx;
if (hasBar) {
out.push(`<rect x="${x(t.start)}" y="${cy - BAR_H / 2}" width="${w}" height="${BAR_H}" rx="3" fill="${solid ? c.stroke : c.fill}" fill-opacity="${ms ? 0.8 : 1}" stroke="${stroke}" stroke-width="${warn ? 1.6 : 1.1}"${dash}/>`);
if (name) {
if (textW + 8 <= w) out.push(`<text x="${x(t.start) + 5}" y="${cy + 4}" font-size="11" font-weight="600" fill="${solid ? "#fff" : "#222"}">${esc(name)}</text>`);
else {
out.push(`<text x="${x(t.start)}" y="${cy - BAR_H / 2 - 3}" font-size="11" font-weight="600" fill="${c.stroke}">${esc(name)}</text>`);
}
}
}
if (ms || t.kind === "milestone") {
const px0 = x(t.end);
out.push(`<path d="M${px0} ${cy - 8} L${px0 + 8} ${cy} L${px0} ${cy + 8} L${px0 - 8} ${cy} Z" fill="${ms ? c.stroke : c.fill}" stroke="${stroke}" stroke-width="${ms ? 1.5 : 1}"${dash}/>`);
out.push(`<text x="${px0 + 12}" y="${cy + 4}" fill="#555" font-size="11">день ${t.end}</text>`);
out.push(`<path d="M${px0} ${cy - 8} L${px0 + 8} ${cy} L${px0} ${cy + 8} L${px0 - 8} ${cy} Z" fill="#1f1f1f" stroke="#fff" stroke-width="1.2"/>`);
if (!hasBar && name) {
out.push(`<text x="${px0 + 12}" y="${cy + 4}" font-size="11" font-weight="600" fill="${c.stroke}">${esc(name)}</text>`);
}
idText(px0 + 10, "start");
} else {
out.push(`<text x="${x(t.end) + 5}" y="${cy + 4}" fill="#555" font-size="11">${t.start}–${t.end}</text>`);
if (!hasBar && name) {
out.push(`<text x="${x(t.end) + 6}" y="${cy + 4}" font-size="11" font-weight="600" fill="${c.stroke}">${esc(name)}</text>`);
}
idText(hasBar ? x(t.end) : x(t.end) + 6, hasBar ? "end" : "start");
}
}
out.push("</g>");
@@ -302,7 +342,7 @@ export function renderGantt(model: ProcessModel, schedule: Schedule, opts: Gantt
})
.join("");
const defs =
`<marker id="arr" viewBox="0 0 6 6" refX="5" refY="3" markerWidth="5" markerHeight="5" orient="auto"><path d="M0 0 L6 3 L0 6 z" fill="#9aa0a6"/></marker>` +
`<marker id="arr" viewBox="0 0 6 6" refX="5" refY="3" markerWidth="6" markerHeight="6" orient="auto"><path d="M0 0 L6 3 L0 6 z" fill="#444"/></marker>` +
`<pattern id="hatch" width="6" height="6" patternUnits="userSpaceOnUse" patternTransform="rotate(45)"><rect width="6" height="6" fill="#ffffff"/><line x1="0" y1="0" x2="0" y2="6" stroke="#9aa0a6" stroke-width="2"/></pattern>` +
hatches +
// запасной шаблон для легенды, если этапов нет

View File

@@ -165,6 +165,23 @@ describe("Гант: группы, вехи, свёртывание, масшта
expect(shut.match(/<svg[^>]*height="(\d+)"/)![1]!).not.toBe(open.match(/<svg[^>]*height="(\d+)"/)![1]!);
});
it("свёрнутая группа: зависимости между вехами сохраняются (стрелка от ромба вехи до зависимой строки)", () => {
const arrows = (svg: string) => svg.split('marker-end="url(#arr)"').length - 1;
const shut = renderGantt(ms, sch, { collapsed: ["A"] });
expect(arrows(shut)).toBeGreaterThanOrEqual(1); // X-9 (группа A свёрнута) -> S-3
expect(arrows(renderGantt(ms, sch, { collapsed: ["A", "B"] }))).toBe(0); // S-3 - не веха, к нему стрелки нет
expect(arrows(renderGantt(ms, sch, {}))).toBeGreaterThan(arrows(shut));
});
it("подпись полосы - название работы (внутри полосы или над ней), id справа снизу, без дат", () => {
const svg = renderGantt(ms, sch, { px: 20 });
expect(svg).toContain('fill="#fff">Работа</text>'); // название внутри длинной полосы
expect(svg).toMatch(/text-anchor="end" font-size="9"[^>]*>S-1<[/]text>/); // id справа снизу
expect(svg).not.toMatch(/>[0-9]+–[0-9]+<[/]text>/); // подписей-интервалов дат у полос нет
const narrow = renderGantt(ms, sch, { px: 0.5 });
expect(narrow).toMatch(/font-weight="600" fill="#[0-9a-f]{6}">Работа<[/]text>/); // не влезло - подпись над полосой
});
it("масштаб времени меняет только ось: ширина растёт, шрифты и высота остаются", () => {
const a = renderGantt(ms, sch, { px: 5 });
const b = renderGantt(ms, sch, { px: 20 });