Гант: порядок и цвета этапов из khbuild_stages (ord, color_fill, color_stroke), без константы в коде
All checks were successful
ci / test (push) Successful in 24s
ci / deploy (push) Successful in 1m30s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-17 09:11:26 +03:00
parent bfe6b4338b
commit 5cd07f709b
4 changed files with 33 additions and 34 deletions

View File

@@ -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]);