Гант: порядок и цвета этапов из khbuild_stages (ord, color_fill, color_stroke), без константы в коде
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
|---|---|
|
||||
| `khbuild_process` | `id` PK (номер Дмитрия `CP-0`…`CP-17`, новые шаги `S-001`…), `stage` (FK на `khbuild_stages.id`), `action_name`, `action_description`, `responsible`, `responsible2`, `responsible3` (FK на `khbuild_responsible.id`: основной ответственный и до двух дополнительных), `system_as_is`, `system_to_be` (FK на `khbuild_systems.id`), `data_in1..3`, `data_out1..3` (FK на `khbuild_data_objects.id`), `depends_on`, `depends_on2`, `depends_on3` (FK на `khbuild_process.id`), `duration` (канонический формат ниже), `date_constraint` (дни от kick-off: `день 7`, `не позже дня 7`, `день 45–47`, `день 80 → день 90`, `еженедельно`, `ежедневно`), `questions` (открытые вопросы по шагу), `ord` (integer: порядок строк как в визуализации - группы в порядке презентации, внутри группы по началу, концу и номеру; шаг 1000, чтобы можно было вставлять промежуточные значения; сортировка по `ord` показывает шаги, в том числе вехи, в той же последовательности, что и Гант; для новых строк пусто), `is_milestone` (boolean, по умолчанию `false`: признак вехи; у чек-пойнтов `CP-*` стоит `true`, любую другую строку можно пометить вручную - она появится вехой на сводной полосе группы в Ганте) |
|
||||
| `khbuild_responsible` | справочник ответственных: `id` PK (обычный ключ: роль, для второго человека в той же роли `роль_2`, например `architect`, `specs_client_mgr`, `specs_client_mgr_2`), `role` (идентификатор роли), `person` (имя человека или компании), `comment` (открытые вопросы) |
|
||||
| `khbuild_stages` | справочник этапов (групп) процесса: `id` PK (на него ссылается `khbuild_process.stage`), `stage_name` (название для показа), `comment` |
|
||||
| `khbuild_stages` | справочник этапов (групп) процесса: `id` PK (на него ссылается `khbuild_process.stage`), `stage_name` (название для показа), `ord` (порядок групп на Ганте, меньше - выше), `color_fill` и `color_stroke` (цвета группы, `#rrggbb`), `comment`; колонки `ord` и цвета необязательны (нет - порядок по срокам, цвета по кругу) |
|
||||
| `khbuild_systems` | `id` PK, `system_name`, `comment` |
|
||||
| `khbuild_data_objects` | `id` PK, `data_description`, `responsible` (FK на `khbuild_responsible.id`), `comment` |
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { describeResponsible, type ProcessModel, type ProcessRow } from "./model.js";
|
||||
import { describeResponsible, type ProcessModel, type ProcessRow, type StageRow } from "./model.js";
|
||||
import type { Schedule, Timing } from "./schedule.js";
|
||||
import { esc, svgDoc, tooltip, truncate } from "./svg.js";
|
||||
|
||||
@@ -45,27 +45,16 @@ export const clampPx = (px: number | undefined): number => {
|
||||
return Math.min(GANTT_MAX_PX, Math.max(GANTT_MIN_PX, v));
|
||||
};
|
||||
|
||||
/** Группы презентации «Pre-construction»: порядок сверху вниз и цвета (сплошная полоса / светлый тон для примерных сроков). */
|
||||
export const STAGE_STYLES: ReadonlyArray<{ stage: string; fill: string; stroke: string }> = [
|
||||
{ stage: "До CP-0", stroke: "#8a6bb5", fill: "#e5dcf1" },
|
||||
{ stage: "Договоры PreConstruction", stroke: "#7a808f", fill: "#dde0e6" },
|
||||
{ stage: "Пермит", stroke: "#d8622f", fill: "#f7d9cc" },
|
||||
{ stage: "Архитектура", stroke: "#3f9a78", fill: "#d4ece3" },
|
||||
{ stage: "Спецификации", stroke: "#3f7ea6", fill: "#d3e4ef" },
|
||||
{ stage: "Финансы", stroke: "#d4982f", fill: "#f5e6c8" },
|
||||
{ stage: "Договор Construction", stroke: "#7a808f", fill: "#dde0e6" },
|
||||
{ stage: "Закупки", stroke: "#6f93ab", fill: "#dbe6ee" },
|
||||
{ stage: "Стройка", stroke: "#1f7a52", fill: "#cfe6da" },
|
||||
];
|
||||
const OTHER_STYLES: ReadonlyArray<{ fill: string; stroke: string }> = [
|
||||
/** Цвета этапов без заданных в справочнике (`color_fill`, `color_stroke`): по кругу. */
|
||||
const FALLBACK_STYLES: ReadonlyArray<{ fill: string; stroke: string }> = [
|
||||
{ stroke: "#8a6bb5", fill: "#e5dcf1" },
|
||||
{ stroke: "#b44b7c", fill: "#f5cfe0" },
|
||||
{ stroke: "#2f9a8f", fill: "#c9f0ec" },
|
||||
{ stroke: "#a39a1c", fill: "#f3efb0" },
|
||||
];
|
||||
|
||||
/** Порядок этапов: сначала группы презентации в её порядке, остальные - по самому раннему сроку окончания среди шагов с заданным сроком (шаги без срока не тянут этап в начало), затем по появлению. */
|
||||
export function stageOrder(rows: ProcessRow[], schedule: Schedule): string[] {
|
||||
/** Порядок этапов: сначала этапы с `ord` в справочнике (по возрастанию), остальные - по самому раннему сроку окончания среди шагов с заданным сроком (шаги без срока не тянут этап в начало), затем по появлению. */
|
||||
export function stageOrder(rows: ProcessRow[], schedule: Schedule, stageRefs: StageRow[] = []): string[] {
|
||||
const key = new Map<string, number>();
|
||||
for (const r of rows) {
|
||||
const s = r.stage ?? NO_STAGE;
|
||||
@@ -77,13 +66,12 @@ export function stageOrder(rows: ProcessRow[], schedule: Schedule): string[] {
|
||||
const v = t.fromConstraint ? t.end : t.end + 0.5; // выведенные сроки чуть слабее заданных
|
||||
key.set(s, Math.min(key.get(s) ?? Infinity, v));
|
||||
}
|
||||
const known = (s: string) => STAGE_STYLES.findIndex((x) => x.stage === s);
|
||||
const ordOf = (s: string): number => stageRefs.find((r) => r.name === s)?.ord ?? Infinity;
|
||||
return [...key.entries()]
|
||||
.sort((a, b) => {
|
||||
const ka = known(a[0]);
|
||||
const kb = known(b[0]);
|
||||
if (ka >= 0 || kb >= 0) return (ka >= 0 ? ka : Infinity) - (kb >= 0 ? kb : Infinity) || a[1] - b[1];
|
||||
return a[1] - b[1];
|
||||
const oa = ordOf(a[0]);
|
||||
const ob = ordOf(b[0]);
|
||||
return oa === ob ? a[1] - b[1] : oa - ob;
|
||||
})
|
||||
.map(([s]) => s);
|
||||
}
|
||||
@@ -163,10 +151,11 @@ export function placeLabels(items: Array<{ x: number; row: ProcessRow }>): { lab
|
||||
export function renderGantt(model: ProcessModel, schedule: Schedule, opts: GanttOptions = {}): string {
|
||||
const px = clampPx(opts.px);
|
||||
const collapsedSet = new Set(opts.collapsed ?? []);
|
||||
const stages = stageOrder(model.rows, schedule).filter((s) => !opts.stages?.length || opts.stages.includes(s));
|
||||
const others = stages.filter((s) => !STAGE_STYLES.some((x) => x.stage === s));
|
||||
const stages = stageOrder(model.rows, schedule, model.stages).filter((s) => !opts.stages?.length || opts.stages.includes(s));
|
||||
const stageColor = new Map(model.stages.filter((r) => r.fill && r.stroke).map((r) => [r.name, { fill: r.fill!, stroke: r.stroke! }]));
|
||||
const others = stages.filter((s) => !stageColor.has(s));
|
||||
const color = (stage: string): { fill: string; stroke: string } =>
|
||||
STAGE_STYLES.find((x) => x.stage === stage) ?? OTHER_STYLES[Math.max(0, others.indexOf(stage)) % OTHER_STYLES.length]!;
|
||||
stageColor.get(stage) ?? FALLBACK_STYLES[Math.max(0, others.indexOf(stage)) % FALLBACK_STYLES.length]!;
|
||||
const roleName = new Map(model.roles.map((r) => [r.id, r.person ?? r.id]));
|
||||
const conflicts = new Map<string, string[]>();
|
||||
for (const w of schedule.warnings) conflicts.set(w.id, [...(conflicts.get(w.id) ?? []), w.message]);
|
||||
|
||||
@@ -31,8 +31,8 @@ export interface ProcessRow {
|
||||
export interface ResponsibleRow { id: string; role: string | null; person: string | null; comment: string | null }
|
||||
/** Роль (производная от справочника ответственных): имена всех ответственных этой роли. */
|
||||
export interface RoleRow { id: string; person: string | null; comment: string | null }
|
||||
/** Этап процесса (справочник `<набор>_stages`): `id` - ключ, на который ссылается `stage` шага, `name` - название для показа. */
|
||||
export interface StageRow { id: string; name: string; comment: string | null }
|
||||
/** Этап процесса (справочник `<набор>_stages`): `id` - ключ, на который ссылается `stage` шага, `name` - название для показа; `ord`, `color_fill`, `color_stroke` - порядок и цвета группы на Ганте (необязательные колонки). */
|
||||
export interface StageRow { id: string; name: string; comment: string | null; /** порядок групп на Ганте (меньше - выше) */ ord: number | null; /** цвета группы: светлый тон и цвет полосы/рамки */ fill: string | null; stroke: string | null }
|
||||
export interface SystemRow { id: string; name: string | null; comment: string | null }
|
||||
export interface DataRow { id: string; description: string | null; role: string | null; comment: string | null }
|
||||
|
||||
@@ -92,7 +92,7 @@ export function buildModel(set: ProcessSet, raw: RawStar): ProcessModel {
|
||||
);
|
||||
const byId = new Map(responsible.map((r) => [r.id, r]));
|
||||
|
||||
const stages: StageRow[] = (raw.stages ?? []).map((r) => ({ id: String(r.id), name: str(r.stage_name) ?? String(r.id), comment: str(r.comment) }));
|
||||
const stages: StageRow[] = (raw.stages ?? []).map((r) => ({ id: String(r.id), name: str(r.stage_name) ?? String(r.id), comment: str(r.comment), ord: r.ord === null || r.ord === undefined ? null : Number(r.ord), fill: str(r.color_fill), stroke: str(r.color_stroke) }));
|
||||
const stageName = new Map(stages.map((r) => [r.id, r.name]));
|
||||
|
||||
const rows = raw.process.map(mapRow).map((row0) => {
|
||||
|
||||
@@ -143,9 +143,9 @@ describe("справочник ответственных", () => {
|
||||
describe("справочник этапов", () => {
|
||||
it("название этапа берётся из справочника, без справочника остаётся значение колонки stage", () => {
|
||||
const base = { refs: [], legacyRoles: false, systems: [], data: [] };
|
||||
const withRef = buildModel("khbuild", { ...base, process: [{ id: "S1", stage: "st_arch" }, { id: "S2", stage: "нет в справочнике" }, { id: "S3" }], stages: [{ id: "st_arch", stage_name: "Архитектура", comment: "уточнить границы" }] });
|
||||
const withRef = buildModel("khbuild", { ...base, process: [{ id: "S1", stage: "st_arch" }, { id: "S2", stage: "нет в справочнике" }, { id: "S3" }], stages: [{ id: "st_arch", stage_name: "Архитектура", comment: "уточнить границы", ord: 40, color_fill: "#d4ece3", color_stroke: "#3f9a78" }] });
|
||||
expect(withRef.rows.map((r) => r.stage)).toEqual(["Архитектура", "нет в справочнике", null]);
|
||||
expect(withRef.stages).toEqual([{ id: "st_arch", name: "Архитектура", comment: "уточнить границы" }]);
|
||||
expect(withRef.stages).toEqual([{ id: "st_arch", name: "Архитектура", comment: "уточнить границы", ord: 40, fill: "#d4ece3", stroke: "#3f9a78" }]);
|
||||
const without = buildModel("khnata", { ...base, process: [{ id: "S1", stage: "Architecture" }] });
|
||||
expect(without.rows[0]?.stage).toBe("Architecture");
|
||||
expect(without.stages).toEqual([]);
|
||||
@@ -341,11 +341,21 @@ describe("Гант: группы, вехи, свёртывание, масшта
|
||||
expect(narrow).toMatch(/font-weight="600" fill="#[0-9a-f]{6}">Работа<[/]text>/); // не влезло - подпись над полосой
|
||||
});
|
||||
|
||||
it("группы презентации: порядок и цвета фиксированы, заливка сплошная (без штриховки)", () => {
|
||||
const rows = ["Стройка", "Пермит", "Договоры PreConstruction", "Финансы", "Свой этап", "Спецификации", "Архитектура", "Закупки"].map((s, i) => row({ id: "S-" + i, stage: s, date_constraint: "день " + (10 + i) }));
|
||||
const m: ProcessModel = { ...model, rows };
|
||||
it("этапы: порядок и цвета берутся из справочника (ord, color_fill, color_stroke), заливка сплошная (без штриховки)", () => {
|
||||
const names = ["Стройка", "Пермит", "Договоры PreConstruction", "Финансы", "Свой этап", "Спецификации", "Архитектура", "Закупки"];
|
||||
const rows = names.map((s, i) => row({ id: "S-" + i, stage: s, date_constraint: "день " + (10 + i) }));
|
||||
const refs: ProcessModel["stages"] = [
|
||||
{ id: "Договоры PreConstruction", name: "Договоры PreConstruction", comment: null, ord: 20, fill: "#dde0e6", stroke: "#7a808f" },
|
||||
{ id: "Пермит", name: "Пермит", comment: null, ord: 30, fill: "#f7d9cc", stroke: "#d8622f" },
|
||||
{ id: "Архитектура", name: "Архитектура", comment: null, ord: 40, fill: "#d4ece3", stroke: "#3f9a78" },
|
||||
{ id: "Спецификации", name: "Спецификации", comment: null, ord: 50, fill: "#d3e4ef", stroke: "#3f7ea6" },
|
||||
{ id: "Финансы", name: "Финансы", comment: null, ord: 60, fill: "#f5e6c8", stroke: "#d4982f" },
|
||||
{ id: "Закупки", name: "Закупки", comment: null, ord: 80, fill: "#dbe6ee", stroke: "#6f93ab" },
|
||||
{ id: "Стройка", name: "Стройка", comment: null, ord: 90, fill: "#cfe6da", stroke: "#1f7a52" },
|
||||
];
|
||||
const m: ProcessModel = { ...model, rows, stages: refs };
|
||||
const sc = computeSchedule(m.rows);
|
||||
expect(stageOrder(m.rows, sc)).toEqual(["Договоры PreConstruction", "Пермит", "Архитектура", "Спецификации", "Финансы", "Закупки", "Стройка", "Свой этап"]);
|
||||
expect(stageOrder(m.rows, sc, refs)).toEqual(["Договоры PreConstruction", "Пермит", "Архитектура", "Спецификации", "Финансы", "Закупки", "Стройка", "Свой этап"]);
|
||||
const svg = renderGantt(m, sc, {});
|
||||
expect(svg).toContain("#7a808f"); // Договоры
|
||||
expect(svg).toContain("#d8622f"); // Пермит
|
||||
|
||||
Reference in New Issue
Block a user