Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 45 additions & 5 deletions pm-stack/aggregator/src/assets/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -5130,11 +5130,6 @@ pre {
border-color: #d29922;
color: #e3b341;
}
.badge.lapsed {
background: #6e768133;
border-color: #6e7681;
color: #8b949e;
}
.badge.conflict {
background: #bc8cff33;
border-color: #bc8cff;
Expand Down Expand Up @@ -6025,6 +6020,51 @@ nav {
.foot {
padding-bottom: 8px;
}
.flow-scroll {
overflow-x: auto;
}
.flow-tp-bar {
fill: #58a6ff;
}
.flow-tp-value {
fill: #e6edf3;
font-size: 11px;
}
.flow-tp-week-label {
fill: #8b949e;
font-size: 9px;
}
.flow-axis {
stroke: #30363d;
stroke-width: 1;
}
.flow-tis-0 {
fill: #58a6ff;
}
.flow-tis-1 {
fill: #3fb950;
}
.flow-tis-2 {
fill: #d29922;
}
.flow-tis-3 {
fill: #bc8cff;
}
.flow-tis-4 {
fill: #f778ba;
}
.flow-tis-5 {
fill: #79c0ff;
}
html[data-theme="light"] .flow-tp-value {
fill: #1f2328;
}
html[data-theme="light"] .flow-tp-week-label {
fill: #59636e;
}
html[data-theme="light"] .flow-axis {
stroke: #d1d9e0;
}
@layer base {
:where(:root),:root:has(input.theme-controller[value=dark]:checked),[data-theme=dark] {
color-scheme: dark;
Expand Down
117 changes: 117 additions & 0 deletions pm-stack/aggregator/src/flow-charts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// Flow analytics charts (#4830, step 3 of the #1281 split): the
// server-rendered charts for the #4829 flow-analytics JSON twin
// (/api/flow-analytics.json). Rendering only — this module computes
// nothing: every number it draws is read from the twin object the
// endpoint serves, so the charts can never disagree with the JSON
// (one computation path, #4829).
//
// Honesty rules, carried from the twin onto the page:
// - The computation window is stated on the section (first/last
// cutoff, complete cutoffs of total), never left implicit.
// - Coverage gaps are named on the chart (cutoff + incomplete /
// unavailable): intervals spanning a gap are excluded by the twin,
// and the page says so instead of smoothing over them.
// - A complete week with zero completions renders as a zero bar with
// a visible 0 — preserved by the twin, never dropped here.

import type { FlowAnalytics, FlowGroup, FlowWindow } from "./flow-analytics.ts";

function esc(s: unknown): string {
return String(s ?? "")
.replace(/&/g, "&")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#39;");
}

/** Days as the twin states them: integers plain, fractions to 2dp. */
function fmtDays(v: number): string {
return Number.isInteger(v) ? String(v) : v.toFixed(2);
}

const TP_WIDTH = 560;
const TP_HEIGHT = 110;
const TP_BASELINE = 92;

/** The stated window + named coverage gaps for the whole twin. */
export function flowWindowHtml(window: FlowWindow): string {
if (window.fromCutoff === null || window.toCutoff === null) {
return `<div class="flow-window"><p class="muted">Flow analytics window: no item history stored yet — no cutoffs, no charts.</p></div>`;
}
const gaps = window.gaps.length
? `<div class="flag">Coverage gaps in this window: ${window.gaps
.map(
(g) =>
`<span class="flow-gap" data-gap="${esc(g.cutoffAt)}">${esc(g.cutoffAt)} (${g.unavailable ? "unavailable" : "incomplete"})</span>`,
)
.join(", ")} — intervals spanning a gap are excluded from every number below; nothing is zero-filled or smoothed over.</div>`
: "";
return `<div class="flow-window" data-from="${esc(window.fromCutoff)}" data-to="${esc(window.toCutoff)}"><p class="muted">Computation window: ${esc(window.fromCutoff)} → ${esc(window.toCutoff)} · ${window.completeCutoffs} of ${window.cutoffCount} cutoffs complete. Source: <a href="/api/flow-analytics.json">/api/flow-analytics.json</a> — the charts below render that JSON twin and nothing else.</p>${gaps}</div>`;
}

const TP_SLOT = 56;

/** Weekly throughput bar chart for one group, from the twin series.
* The chart grows with the retained history (a full store holds a
* year or more of weekly cutoffs): every week keeps a full slot and
* its date label, and the container scrolls horizontally instead of
* squeezing labels together. No week is ever dropped or merged. */
export function throughputChartHtml(group: FlowGroup): string {
const weeks = group.throughput;
if (weeks.length === 0) {
return `<p class="muted">Throughput: no complete weeks in this window.</p>`;
}
const max = Math.max(1, ...weeks.map((w) => w.completed));
const width = Math.max(TP_WIDTH, weeks.length * TP_SLOT);
const slot = width / weeks.length;
const barWidth = Math.max(6, slot * 0.62);
const bars = weeks
.map((w, i) => {
const h = Math.round((w.completed / max) * (TP_BASELINE - 24));
const x = i * slot + (slot - barWidth) / 2;
const y = TP_BASELINE - h;
return `<g class="flow-tp-week" data-cutoff="${esc(w.cutoffAt)}" data-completed="${w.completed}"><rect x="${x.toFixed(1)}" y="${y}" width="${barWidth.toFixed(1)}" height="${h}" class="flow-tp-bar"></rect><text x="${(i * slot + slot / 2).toFixed(1)}" y="${y - 4}" text-anchor="middle" class="flow-tp-value">${w.completed}</text><text x="${(i * slot + slot / 2).toFixed(1)}" y="${TP_BASELINE + 13}" text-anchor="middle" class="flow-tp-week-label">${esc(w.cutoffAt.slice(0, 10))}</text></g>`;
Comment thread
dezren39 marked this conversation as resolved.
Resolved
})
.join("");
return `<div class="flow-chart"><h4>Weekly throughput (issues completed)</h4><div class="flow-scroll"><svg viewBox="0 0 ${width} ${TP_HEIGHT}" width="${width}" height="${TP_HEIGHT}" role="img" aria-label="Weekly throughput">${bars}<line x1="0" y1="${TP_BASELINE}" x2="${width}" y2="${TP_BASELINE}" class="flow-axis"></line></svg></div></div>`;
}

const TIS_WIDTH = 560;
const TIS_HEIGHT = 26;

/** Time-in-status stacked bar + exact-value legend for one group. */
export function timeInStatusHtml(group: FlowGroup): string {
const total = group.timeInStatus.reduce((sum, s) => sum + s.itemDays, 0);
if (total <= 0) {
return `<p class="muted">Time in status: no complete-interval time recorded for this group in this window.</p>`;
}
let x = 0;
const segs = group.timeInStatus
.map((s, i) => {
const w = (s.itemDays / total) * TIS_WIDTH;
const out = `<rect class="flow-tis-seg flow-tis-${i % 6}" data-status="${esc(s.status)}" data-item-days="${s.itemDays}" x="${x.toFixed(1)}" y="0" width="${w.toFixed(1)}" height="${TIS_HEIGHT}"></rect>`;
x += w;
return out;
})
.join("");
const legend = group.timeInStatus
.map(
(s) =>
`<li data-status="${esc(s.status)}" data-item-days="${s.itemDays}">${esc(s.status)} — ${fmtDays(s.itemDays)} item-days</li>`,
)
.join("");
return `<div class="flow-chart"><h4>Time in status (item-days)</h4><svg viewBox="0 0 ${TIS_WIDTH} ${TIS_HEIGHT}" width="100%" role="img" aria-label="Time in status">${segs}</svg><ul class="flow-tis-legend">${legend}</ul></div>`;
}

/** One group's charts: throughput + time-in-status. */
export function flowGroupHtml(group: FlowGroup): string {
const name = group.groupRef === null ? "Unassigned" : group.groupRef;
return `<div class="flow-group" data-group="${esc(group.groupRef ?? "")}"><h3>${esc(name)}</h3><p class="muted">${group.itemCount} item${group.itemCount === 1 ? "" : "s"} observed in this window.</p>${throughputChartHtml(group)}${timeInStatusHtml(group)}</div>`;
}

/** The full flow-analytics section for the Projects/Roadmap pages. */
export function flowChartsHtml(analytics: FlowAnalytics): string {
const groups = analytics.groups.map(flowGroupHtml).join("");
return `<section class="flow-analytics"><h2>Flow analytics</h2>${flowWindowHtml(analytics.window)}${groups || '<p class="muted">No groups observed in this window.</p>'}</section>`;
}
9 changes: 7 additions & 2 deletions pm-stack/aggregator/src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import { diffCoverage, staleIssueState, type CoverageSnapshotFile } from "./cove
import { DIGEST_SECTION_LIMIT, type Digest, type DigestKind } from "./digest.ts";
import { registryQueryString, type RegistryView } from "./registry-view.ts";
import { formatForecastSummary, type ForecastContract } from "./forecast-contract.ts";
import type { FlowAnalytics } from "./flow-analytics.ts";
import { flowChartsHtml } from "./flow-charts.ts";
import { latestInFamily, newClientToken, type DashAction } from "./actions.ts";
import { applyBoardDonePolicy, DONE_STRIP_RENDER_LIMIT, selectVisibleDoneCards } from "./board-policy.ts";
import { summarizeWipLanes } from "./wip-limits.ts";
Expand Down Expand Up @@ -1770,6 +1772,7 @@ export function renderRoadmap(
viewQuery = "",
briefs?: Map<RefKey, ItemBrief>,
forecasts?: Map<RefKey, ForecastContract[]>,
flowAnalytics?: FlowAnalytics,
): string {
// #1144: when the Grist rows and the Project's Kind=Epic pool items
// disagree, say so on the page itself — drift the reader can see,
Expand Down Expand Up @@ -1823,7 +1826,7 @@ export function renderRoadmap(
}
return layout(
"Roadmap",
`<h1>Roadmap</h1><p class="muted">Grist's <em>Program roadmap</em> table at every grain — one data model, switchable horizon. Rows with a calendar date land on their day; quarter-labelled rows stay at quarter grain. Every row remains visible at every grain.</p><div class="chips">${chips}</div>${driftFlag}${horizonFlag}${body}`,
`<h1>Roadmap</h1><p class="muted">Grist's <em>Program roadmap</em> table at every grain — one data model, switchable horizon. Rows with a calendar date land on their day; quarter-labelled rows stay at quarter grain. Every row remains visible at every grain.</p><div class="chips">${chips}</div>${driftFlag}${horizonFlag}${body}${flowAnalytics ? flowChartsHtml(flowAnalytics) : ""}`,
provenance,
"/roadmap",
"",
Expand Down Expand Up @@ -6604,6 +6607,8 @@ export function renderProgram(
/** Prebuilt briefs (#1279), e.g. with comment activity folded in. */
briefs?: Map<RefKey, ItemBrief>;
forecasts?: Map<RefKey, ForecastContract[]>;
/** The #4829 flow twin the #4830 charts render on this page. */
flowAnalytics?: FlowAnalytics;
} | null,
): string {
const poolSectionHtml = poolSection
Expand Down Expand Up @@ -6632,7 +6637,7 @@ ${poolSummaryHtml(live)}
${orchestrationHtml(live)}
<h2>The PM dashboard's own record</h2>
<p class="muted">This dashboard's architecture, what's built, what's next, and its long-term roadmap live on its project page: <a href="/program/pm-dashboard">PM dashboard →</a>. Its tracked issues, resolved live:</p>
${trackedTable(live.tracked)}${poolSectionHtml}`;
${trackedTable(live.tracked)}${poolSectionHtml}${poolSection?.flowAnalytics ? flowChartsHtml(poolSection.flowAnalytics) : ""}`;
return layout(
"Program status",
body,
Expand Down
9 changes: 9 additions & 0 deletions pm-stack/aggregator/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1700,6 +1700,9 @@ async function handler(req: Request): Promise<Response> {
orchestrationStatus,
});
const forecasts = (await allForecastContracts(pool)).byRef;
// #4830: the same twin /api/flow-analytics.json serves, computed
// the same way — the Roadmap charts render exactly this object.
const flowAnalytics = computeFlowAnalytics(await itemHistoryStore.readAll().catch(() => []));
const g = url.searchParams.get("h") ?? "quarter";
const grain: RoadmapGrain = GRAINS.has(g) ? (g as RoadmapGrain) : "quarter";
const resolved = await resolveView(url);
Expand Down Expand Up @@ -1731,6 +1734,7 @@ async function handler(req: Request): Promise<Response> {
viewQuery,
briefs,
forecasts,
flowAnalytics,
),
);
}
Expand Down Expand Up @@ -1768,6 +1772,7 @@ async function handler(req: Request): Promise<Response> {
viewQuery,
briefs,
forecasts,
flowAnalytics,
),
);
}
Expand Down Expand Up @@ -2037,6 +2042,10 @@ async function handler(req: Request): Promise<Response> {
identities: formOpts.identities,
briefs,
forecasts: (await allForecastContracts(viewPool)).byRef,
// #4830: the Projects page (merged into /program, #1497)
// renders the #4829 twin as charts, computed as the endpoint
// computes it.
flowAnalytics: computeFlowAnalytics(await itemHistoryStore.readAll().catch(() => [])),
}),
);
}
Expand Down
16 changes: 16 additions & 0 deletions pm-stack/aggregator/src/ui.css
Original file line number Diff line number Diff line change
Expand Up @@ -434,3 +434,19 @@ html[data-theme="dark"] a { color: #58a6ff; }
nav { z-index: 40; backdrop-filter: blur(6px); }
.theme-toggle-wrap { margin-left: auto; display: inline-flex; align-items: center; }
.foot { padding-bottom: 8px; }

/* --- Flow analytics charts (#4830) --- */
.flow-scroll { overflow-x: auto; }
.flow-tp-bar { fill: #58a6ff; }
.flow-tp-value { fill: #e6edf3; font-size: 11px; }
.flow-tp-week-label { fill: #8b949e; font-size: 9px; }
.flow-axis { stroke: #30363d; stroke-width: 1; }
.flow-tis-0 { fill: #58a6ff; }
.flow-tis-1 { fill: #3fb950; }
.flow-tis-2 { fill: #d29922; }
.flow-tis-3 { fill: #bc8cff; }
.flow-tis-4 { fill: #f778ba; }
.flow-tis-5 { fill: #79c0ff; }
html[data-theme="light"] .flow-tp-value { fill: #1f2328; }
html[data-theme="light"] .flow-tp-week-label { fill: #59636e; }
html[data-theme="light"] .flow-axis { stroke: #d1d9e0; }
Loading
Loading