web: right-align list miniatures and color pinned run graphs
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user