web: right-align list miniatures and color pinned run graphs

This commit is contained in:
2026-10-20 17:30:42 +01:00
parent a670610497
commit a77e54beab
7 changed files with 261 additions and 61 deletions
+93
View File
@@ -0,0 +1,93 @@
// Label-free list cue, sharing the detail graph's layout and route evidence.
import { h } from "./dom.js";
import { layoutGraph, edgeIsExecuted, edgeStrokeColor } from "./graph.js";
import { runGraphState } from "./runDetail.js";
const METRICS = Object.freeze({ nodeWidth: 26, nodeHeight: 12, hGap: 12, pad: 2,
laneSpacing: 8, terminalGap: 8, trackStep: 6, portSpacing: 4,
labelCharWidth: 0, labelPadding: 0, labelHeight: 0, labelGap: 0 });
const NS = "http://www.w3.org/2000/svg";
const STATUSES = new Set(["succeeded", "failed", "running", "waiting", "queued",
"interrupted", "canceled", "blocked", "skipped"]);
export function miniatureColor(status) {
return `var(--status-${STATUSES.has(status) ? status : "unknown"})`;
}
export function miniatureModel(graph, run = null) {
const stages = graph?.stages ?? [];
const keys = new Set(stages.map((stage) => stage.key));
const shape = { stages: stages.map((stage) => ({ ...stage,
edges: Object.fromEntries(Object.entries(stage.edges ?? {}).filter(([, target]) => keys.has(target))),
})) };
const layout = layoutGraph(shape, METRICS);
const evidence = run && Array.isArray(run.steps) ? runGraphState(run) : null;
const visits = new Map((run?.steps ?? []).map((step) => [step.stage, step]));
return { ...layout, evidence: evidence != null,
nodes: layout.nodes.map((node) => {
const step = visits.get(node.key);
// A recorded current stage is evidence even in a compact list summary.
const current = run?.executing && run.current_stage === node.key;
const status = current ? run.status : step?.status;
const color = status === "completed" ? edgeStrokeColor(step.outcome) : status ? miniatureColor(status) : null;
return { ...node, color,
untaken: evidence != null && !step && !current };
}),
edges: layout.edges.map((edge) => ({ ...edge,
untaken: evidence != null && !edgeIsExecuted(edge, evidence),
color: evidence && edgeIsExecuted(edge, evidence) ? edgeStrokeColor(edge.outcome) : null,
})),
};
}
export function renderMiniGraph(graph, run = null) {
if (!graph?.stages?.length) return null;
const model = miniatureModel(graph, run);
if (!model.nodes.length || !model.width || !model.height) return null;
const svg = document.createElementNS(NS, "svg");
svg.setAttribute("class", "pipeline-mini-graph");
svg.setAttribute("viewBox", `0 0 ${Math.ceil(model.width)} ${Math.ceil(model.height)}`);
svg.setAttribute("preserveAspectRatio", "xMaxYMid meet");
svg.setAttribute("aria-hidden", "true");
svg.setAttribute("focusable", "false");
for (const edge of model.edges) {
if (edge.points.length < 2) continue;
const line = document.createElementNS(NS, "polyline");
line.setAttribute("class", `pipeline-mini-edge${edge.untaken ? " mini-untaken" : ""}`);
line.setAttribute("points", edge.points.map((p) => `${p.x},${p.y}`).join(" "));
if (edge.color) line.style.color = edge.color;
svg.append(line);
}
for (const node of model.nodes) {
const rect = document.createElementNS(NS, "rect");
rect.setAttribute("class", `pipeline-mini-node${node.untaken ? " mini-untaken" : ""}`);
for (const key of ["x", "y", "width", "height"]) rect.setAttribute(key, String(node[key]));
rect.setAttribute("rx", "3");
if (node.color) rect.style.color = node.color;
svg.append(rect);
}
const wrap = h("span", { class: `pipeline-mini${run ? " run-mini" : ""}`,
"aria-hidden": "true", "data-evidence": model.evidence ? "visits" : "summary" }, svg);
if (run) wrap.style.color = miniatureColor(run.status);
return wrap;
}
/** One read per pinned pipeline version, never get_run per row or latest fallback. */
export function createMiniGraphCache(readPipeline, changed) {
const cache = new Map();
return (run, pipelines = [], scope = "") => {
if (run.graph?.stages?.length) return run.graph;
if (!(run.pipeline_id > 0 && run.version > 0)) return null;
const summary = pipelines.find((p) => p.id === run.pipeline_id && p.version === run.version);
if (summary?.shape?.stages?.length) return summary.shape;
const key = JSON.stringify([scope, run.pipeline_id, run.version]);
if (!cache.has(key)) {
cache.set(key, null);
Promise.resolve().then(() => readPipeline(run.pipeline_id, run.version)).then((detail) => {
if (detail?.version !== run.version) return;
cache.set(key, detail.graph ?? null);
changed();
}).catch(() => { /* Missing topology stays absent, never invented. */ });
}
return cache.get(key);
};
}
+2 -60
View File
@@ -3,6 +3,7 @@
// The pure models live in pipelines.js and graph.js; this module owns the DOM.
import { h } from "../dom.js";
import { renderMiniGraph } from "../miniGraph.js";
import { describeError } from "../format.js";
import {
PIPELINE_SORTS,
@@ -240,67 +241,8 @@ function fillPipelineRows(rowsEl) {
rowsEl.replaceChildren(...nodes);
}
// A list row's graph is a shape cue, not a reading surface: tiny nodes and
// straight routes, no labels or chips. The detail Graph tab is the real one.
const MINI_GRAPH_METRICS = Object.freeze({
nodeWidth: 26,
nodeHeight: 12,
hGap: 12,
pad: 2,
laneSpacing: 8,
terminalGap: 8,
trackStep: 6,
portSpacing: 4,
labelCharWidth: 0,
labelPadding: 0,
labelHeight: 0,
labelGap: 0,
});
const SVG_NS = "http://www.w3.org/2000/svg";
/** The pipeline's stages and their stage-to-stage routes, without terminals. */
function miniGraphShape(graph) {
const stages = graph?.stages ?? [];
const keys = new Set(stages.map((stage) => stage.key));
return {
stages: stages.map((stage) => ({
...stage,
edges: Object.fromEntries(
Object.entries(stage.edges ?? {}).filter(([, target]) => keys.has(target)),
),
})),
};
}
function renderPipelineMiniGraph(pipeline) {
const shape = pipeline.shape ?? pipeline.graph;
if (!shape?.stages?.length) return null;
const layout = layoutGraph(miniGraphShape(shape), MINI_GRAPH_METRICS);
if (!layout.nodes.length || !layout.width || !layout.height) return null;
const svg = document.createElementNS(SVG_NS, "svg");
svg.setAttribute("class", "pipeline-mini-graph");
svg.setAttribute("viewBox", `0 0 ${Math.ceil(layout.width)} ${Math.ceil(layout.height)}`);
svg.setAttribute("preserveAspectRatio", "xMidYMid meet");
svg.setAttribute("aria-hidden", "true");
svg.setAttribute("focusable", "false");
for (const edge of layout.edges) {
if (edge.points.length < 2) continue;
const line = document.createElementNS(SVG_NS, "polyline");
line.setAttribute("class", "pipeline-mini-edge");
line.setAttribute("points", edge.points.map((point) => `${point.x},${point.y}`).join(" "));
svg.append(line);
}
for (const node of layout.nodes) {
const rect = document.createElementNS(SVG_NS, "rect");
rect.setAttribute("class", "pipeline-mini-node");
rect.setAttribute("x", String(node.x));
rect.setAttribute("y", String(node.y));
rect.setAttribute("width", String(node.width));
rect.setAttribute("height", String(node.height));
rect.setAttribute("rx", "3");
svg.append(rect);
}
return h("span", { class: "pipeline-mini", "aria-hidden": "true" }, svg);
return renderMiniGraph(pipeline.shape ?? pipeline.graph);
}
function renderPipelineRow(pipeline, latestRuns, runsKnown, now) {
+8
View File
@@ -4,6 +4,7 @@
import { h } from "../dom.js";
import { statusIcon } from "../statusIcon.js";
import { renderMiniGraph, createMiniGraphCache } from "../miniGraph.js";
import {
RUN_STATES,
RUN_TIME_RANGES,
@@ -31,6 +32,9 @@ export function createRunsView(rt) {
const renderContent = (...args) => rt.renderContent(...args);
const selectRun = (...args) => rt.selectRun(...args);
const renderAttentionBell = () => rt.renderAttentionBell();
const miniGraphFor = createMiniGraphCache((id, version) => rt.repo.getPipeline(id, version), () => {
if (state.view === "runs") renderContent();
});
function renderRunList(now = Date.now()) {
@@ -160,6 +164,10 @@ function renderRunRow(run, now) {
}),
);
}
const evidence = state.runDetail?.id === run.id ? state.runDetail : run;
const graph = miniGraphFor(evidence, state.pipelines, state.url);
const mini = renderMiniGraph(graph, evidence);
if (mini) row.append(mini);
return row;
}