Гант: свёртывание групп, сводные полосы с вехами, масштаб времени
Каждый этап - группа со сводной штрихованной полосой; вехи (колонка is_milestone, по умолчанию чек-пойнты CP-*) отмечены ромбами с подписями над полосой и пунктирными направляющими вниз. Группы сворачиваются кликом, кнопками «Свернуть все / Развернуть все». Масштаб времени (кнопки и Shift+колесо) меняет только ось, шрифты и интервалы не меняются. Состояние в адресе: px, collapsed. Параметры px и collapsed у /gantt.svg. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { renderAris } from "./aris.js";
|
||||
import { renderGantt, stageOrder } from "./gantt.js";
|
||||
import { clampPx, placeLabels, renderGantt, stageOrder, summarizeGroup } from "./gantt.js";
|
||||
import { buildApi } from "./http-api.js";
|
||||
import { mapRow, type ProcessModel } from "./model.js";
|
||||
import { computeSchedule, parseConstraint, parseDuration } from "./schedule.js";
|
||||
@@ -106,6 +106,94 @@ describe("renderGantt", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("Гант: группы, вехи, свёртывание, масштаб времени", () => {
|
||||
const ms: ProcessModel = {
|
||||
...model,
|
||||
rows: [
|
||||
row({ id: "CP-0", stage: "A", action_name: "Старт", date_constraint: "день 0" }),
|
||||
row({ id: "S-1", stage: "A", action_name: "Работа", depends_on: "CP-0", date_constraint: "день 0 → день 20" }),
|
||||
row({ id: "S-2", stage: "A", action_name: "Обычный шаг", depends_on: "S-1", date_constraint: "день 25", is_milestone: false }),
|
||||
row({ id: "X-9", stage: "A", action_name: "Своя веха", depends_on: "S-1", date_constraint: "день 30", is_milestone: true }),
|
||||
row({ id: "S-3", stage: "B", action_name: "Другое", depends_on: "X-9", duration: "10 дней" }),
|
||||
],
|
||||
};
|
||||
const sch = computeSchedule(ms.rows);
|
||||
|
||||
it("признак вехи: колонка is_milestone, а без неё чек-поинты CP-*", () => {
|
||||
const byId = new Map(ms.rows.map((r) => [r.id, r.isMilestone]));
|
||||
expect(byId.get("CP-0")).toBe(true); // колонки нет -> по префиксу
|
||||
expect(byId.get("S-2")).toBe(false);
|
||||
expect(byId.get("X-9")).toBe(true); // явный признак
|
||||
expect(row({ id: "CP-5", is_milestone: false }).isMilestone).toBe(false); // явное «нет» сильнее префикса
|
||||
});
|
||||
|
||||
it("сводка группы: границы и вехи по датам завершения", () => {
|
||||
const rows = ms.rows.filter((r) => r.stage === "A").map((r) => ({ row: r, t: sch.timings.get(r.id)! }));
|
||||
const g = summarizeGroup("A", rows);
|
||||
expect([g.start, g.end]).toEqual([0, 30]);
|
||||
expect(g.milestones.map((m) => [m.row.id, m.day])).toEqual([["CP-0", 0], ["X-9", 30]]);
|
||||
});
|
||||
|
||||
it("повторяющиеся шаги и шаги без срока не растягивают группу", () => {
|
||||
const rows = [row({ id: "R", date_constraint: "еженедельно" }), row({ id: "Q", date_constraint: "день 10 → день 20" }), row({ id: "Z" })];
|
||||
const s2 = computeSchedule(rows);
|
||||
const g = summarizeGroup("G", rows.map((r) => ({ row: r, t: s2.timings.get(r.id)! })).concat([]));
|
||||
expect([g.start, g.end]).toEqual([10, 20]);
|
||||
});
|
||||
|
||||
it("подписи вех не налезают друг на друга: близкие вехи уходят на другой уровень или сокращаются до id", () => {
|
||||
const r = (id: string) => row({ id, action_name: "Очень длинное название вехи" });
|
||||
const { labels, levels } = placeLabels([{ x: 100, row: r("CP-1") }, { x: 110, row: r("CP-2") }, { x: 500, row: r("CP-3") }]);
|
||||
expect(labels).toHaveLength(3);
|
||||
expect(levels).toBeGreaterThanOrEqual(2);
|
||||
expect(labels.find((l) => l.row.id === "CP-3")?.level).toBe(0);
|
||||
expect(labels.find((l) => l.row.id === "CP-3")?.text).toContain("Очень длинное");
|
||||
});
|
||||
|
||||
it("свёрнутая группа остаётся одной сводной строкой, развёрнутые строки и направляющие остаются", () => {
|
||||
const open = renderGantt(ms, sch, {});
|
||||
const shut = renderGantt(ms, sch, { collapsed: ["A"] });
|
||||
expect(open).toContain(">S-2<");
|
||||
expect(shut).not.toContain(">S-2<");
|
||||
expect(shut).toContain(">S-3<"); // группа B осталась раскрытой
|
||||
expect(shut).toContain('data-toggle="A"'); // группа по-прежнему кликабельна
|
||||
expect(shut).toContain("▸");
|
||||
expect(open).toContain("▾");
|
||||
expect(open).toContain("stroke-dasharray=\"4 4\""); // направляющие вех
|
||||
expect(shut.split("\n").filter((l) => l.includes('stroke-dasharray="4 4"')).length).toBeLessThan(open.split("\n").filter((l) => l.includes('stroke-dasharray="4 4"')).length);
|
||||
expect(open).toContain("X-9 · Своя веха"); // подпись над вехой
|
||||
expect(shut.match(/<svg[^>]*height="(\d+)"/)![1]!).not.toBe(open.match(/<svg[^>]*height="(\d+)"/)![1]!);
|
||||
});
|
||||
|
||||
it("масштаб времени меняет только ось: ширина растёт, шрифты и высота остаются", () => {
|
||||
const a = renderGantt(ms, sch, { px: 5 });
|
||||
const b = renderGantt(ms, sch, { px: 20 });
|
||||
const attr = (svg: string, n: string) => Number(svg.match(new RegExp(`<svg[^>]*\\s${n}="([\\d.]+)"`))![1]);
|
||||
expect(attr(b, "width")).toBeGreaterThan(attr(a, "width"));
|
||||
expect(attr(b, "height")).toBe(attr(a, "height"));
|
||||
expect(a).toContain('data-px="5"');
|
||||
expect(b).toContain('data-px="20"');
|
||||
expect(a).toContain('data-left="420"');
|
||||
const fonts = (svg: string) => [...new Set([...svg.matchAll(/font-size="(\d+)"/g)].map((m) => m[1]))].sort().join(","); // набор размеров, а не их число: подписей на оси больше или меньше
|
||||
expect(fonts(b)).toBe(fonts(a));
|
||||
expect(clampPx(1000)).toBe(40);
|
||||
expect(clampPx(0)).toBe(0.5);
|
||||
expect(clampPx(undefined)).toBe(5);
|
||||
});
|
||||
|
||||
it("API: параметры px и collapsed", async () => {
|
||||
const app2 = buildApi({ token: "t", defaultSet: "khbuild", load: async () => ms, dbOk: async () => true });
|
||||
const h = { authorization: "Bearer t" };
|
||||
const svg = (await app2.inject({ url: "/gantt.svg?px=12&collapsed=A", headers: h })).body;
|
||||
expect(svg).toContain('data-px="12"');
|
||||
expect(svg).not.toContain(">S-2<");
|
||||
const page = (await app2.inject({ url: "/", headers: h })).body;
|
||||
expect(page).toContain('id="colAll"');
|
||||
expect(page).toContain('id="expAll"');
|
||||
expect(page).toContain('id="tzp"');
|
||||
});
|
||||
});
|
||||
|
||||
describe("renderAris", () => {
|
||||
it("рисует дорожки ролей, функции, события и системы", () => {
|
||||
const svg = renderAris(model, computeSchedule(model.rows), {});
|
||||
|
||||
Reference in New Issue
Block a user