Гант: при наведении на веху - вертикаль к контурным ромбам; наведение на зависимость подсвечивает её; контурные ромбы поверх строк
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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<string> {
|
||||
const ids = new Set(rows.map((r) => r.id));
|
||||
const succ = new Map<string, string[]>();
|
||||
@@ -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<string>(); // вехи, у которых есть контурные ромбы (вертикаль показывается при наведении)
|
||||
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 = `<path d="M${x1} ${gy - 7} L${x1 + 7} ${gy} L${x1} ${gy + 7} L${x1 - 7} ${gy} Z" fill="#fff" stroke="${gc}" stroke-width="1.6"/>`;
|
||||
const sid = safeId(dep);
|
||||
vlIds.add(sid);
|
||||
vlines.push(`<line class="vl vl-${sid}" x1="${x1}" y1="${from.y}" x2="${x1}" y2="${gy}" stroke="${gc}" stroke-width="1.6"/>`);
|
||||
const ghost = `<path class="ms ms-${sid}" d="M${x1} ${gy - 7} L${x1 + 7} ${gy} L${x1} ${gy + 7} L${x1 - 7} ${gy} Z" fill="#fff" stroke="${gc}" stroke-width="1.6"/>`;
|
||||
const several = row.dependsOn.filter((d) => model.rows.find((r) => r.id === d)?.isMilestone && !redundant.has(`${d}>${row.id}`)).length > 1;
|
||||
const gl = `<text x="${x1 - 11}" y="${gy + 3}" text-anchor="end" font-size="9" fill="${gc}">${esc(several ? dep : truncate(`${dep} ${depRow.actionName ?? ""}`, 40))}</text>`; // несколько вех на одной строке: только 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(`<g>${tooltip([label])}<path d="${lp}" fill="none" stroke="#666" stroke-width="1.1" marker-end="url(#arrg)"/><path d="${lp}" fill="none" stroke="transparent" stroke-width="8" pointer-events="stroke"/></g>`);
|
||||
if (lp) ghostLines.push(`<g class="dep">${tooltip([label])}<path class="dl" d="${lp}" fill="none" stroke="#666" stroke-width="1.1" marker-end="url(#arrg)"/><path d="${lp}" fill="none" stroke="transparent" stroke-width="8" pointer-events="stroke"/></g>`);
|
||||
ghostMarks.push(`<g>${tooltip([label])}${ghost}${gl}</g>`);
|
||||
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(`<g>${tooltip([label])}<path d="${d}" fill="none" stroke="#444" stroke-width="1.1" marker-end="url(#arr)"/><path d="${d}" fill="none" stroke="transparent" stroke-width="8" pointer-events="stroke"/></g>`);
|
||||
arrows.push(`<g class="dep">${tooltip([label])}<path class="dl" d="${d}" fill="none" stroke="#444" stroke-width="1.1" marker-end="url(#arr)"/><path d="${d}" fill="none" stroke="transparent" stroke-width="8" pointer-events="stroke"/></g>`);
|
||||
}
|
||||
}
|
||||
}
|
||||
// слои снизу вверх: линии от контурных вех (почти фон), обычные зависимости, контурные ромбы с подписями (поверх линий)
|
||||
out.push(`<g opacity="0.75">${ghostLines.join("")}${arrows.join("")}</g>`);
|
||||
out.push(`<g>${ghostMarks.join("")}</g>`);
|
||||
|
||||
}
|
||||
|
||||
// Строки раскрытых групп
|
||||
@@ -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(`<line x1="${px0}" y1="${cy}" x2="${x(t.deadline)}" y2="${cy}" stroke="#d32f2f" stroke-width="1" stroke-dasharray="3 3"/>`);
|
||||
out.push(`<path d="M${px0} ${cy - 8} L${px0 + 8} ${cy} L${px0} ${cy + 8} L${px0 - 8} ${cy} Z" fill="#1f1f1f" stroke="${late ? "#d32f2f" : "#fff"}" stroke-width="${late ? 2.5 : 1.2}"/>`);
|
||||
out.push(`<path class="ms ms-${safeId(row.id)}" d="M${px0} ${cy - 8} L${px0 + 8} ${cy} L${px0} ${cy + 8} L${px0 - 8} ${cy} Z" fill="#1f1f1f" stroke="${late ? "#d32f2f" : "#fff"}" stroke-width="${late ? 2.5 : 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>`);
|
||||
}
|
||||
@@ -376,7 +384,7 @@ export function renderGantt(model: ProcessModel, schedule: Schedule, opts: Gantt
|
||||
}
|
||||
if (t.deadline !== null) {
|
||||
const rx = x(t.deadline);
|
||||
out.push(`<line x1="${rx}" y1="${cy - 12}" x2="${rx}" y2="${cy + 12}" stroke="#d32f2f" stroke-width="3"><title>${esc(`Крайний срок: день ${t.deadline}`)}</title></line>`);
|
||||
out.push(`<line x1="${rx}" y1="${cy - 12}" x2="${rx}" y2="${cy + 12}" stroke="#d32f2f" stroke-width="3" pointer-events="none"><title>${esc(`Крайний срок: день ${t.deadline}`)}</title></line>`);
|
||||
}
|
||||
out.push("</g>");
|
||||
}
|
||||
@@ -412,18 +420,18 @@ export function renderGantt(model: ProcessModel, schedule: Schedule, opts: Gantt
|
||||
for (const [a, b] of s.segments) {
|
||||
out.push(`<rect x="${x(a)}" y="${barY}" width="${Math.max(2, (b - a) * px)}" height="${GROUP_BAR_H}" rx="2" fill="${c.stroke}" stroke="${c.stroke}" stroke-width="1.2"/>`);
|
||||
}
|
||||
const diamond = (dx: number, size: number, late = false) => `<path d="M${dx} ${cy - size} L${dx + size} ${cy} L${dx} ${cy + size} L${dx - size} ${cy} Z" fill="${c.stroke}" stroke="${late ? "#d32f2f" : "#fff"}" stroke-width="${late ? 2.5 : 1}"/>`;
|
||||
const diamond = (dx: number, size: number, late = false, id?: string) => `<path${id ? ` class="ms ms-${safeId(id)}"` : ""} d="M${dx} ${cy - size} L${dx + size} ${cy} L${dx} ${cy + size} L${dx - size} ${cy} Z" fill="${c.stroke}" stroke="${late ? "#d32f2f" : "#fff"}" stroke-width="${late ? 2.5 : 1}"/>`;
|
||||
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(`<line x1="${x(m.day)}" y1="${cy}" x2="${x(m.deadline)}" y2="${cy}" stroke="#d32f2f" stroke-width="1" stroke-dasharray="3 3"/>`);
|
||||
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(`<line x1="${rx}" y1="${cy - 12}" x2="${rx}" y2="${cy + 12}" stroke="#d32f2f" stroke-width="3"><title>${esc(`Крайний срок: ${m.row.id}, день ${m.deadline}`)}</title></line>`);
|
||||
out.push(`<line x1="${rx}" y1="${cy - 12}" x2="${rx}" y2="${cy + 12}" stroke="#d32f2f" stroke-width="3" pointer-events="none"><title>${esc(`Крайний срок: ${m.row.id}, день ${m.deadline}`)}</title></line>`);
|
||||
}
|
||||
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(`<g>${vlines.join("")}</g>`);
|
||||
out.push(`<g>${ghostMarks.join("")}</g>`);
|
||||
const ly = height - 20;
|
||||
out.push(
|
||||
`<g font-size="11" fill="#444"><path d="M14 ${ly - 4} l6 6 l-6 6 l-6 -6 z" fill="#777"/><text x="26" y="${ly + 7}">веха</text>` +
|
||||
@@ -445,6 +455,7 @@ export function renderGantt(model: ProcessModel, schedule: Schedule, opts: Gantt
|
||||
`<line x1="1085" y1="${ly - 3}" x2="1085" y2="${ly + 11}" stroke="#d32f2f" stroke-width="3"/><text x="1094" y="${ly + 7}">крайний срок</text></g>`,
|
||||
);
|
||||
|
||||
const defs = `<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><marker id="arrg" 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="#666"/></marker>`;
|
||||
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 = `<style>${hoverCss}</style><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><marker id="arrg" 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="#666"/></marker>`;
|
||||
return svgDoc(width, height, defs, out.join("\n"), `data-left="${GANTT_LEFT}" data-px="${px}"`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user