1import type { Save } from "../mirror/queries.ts";2import { type Html, html } from "./html.ts";3import { formatDate } from "./layout.ts";45const DAY = 86400;67const PACE: [number, string][] = [8 [1, "very active"],9 [0.3, "active"],10 [0.1, "occasional"],11];12131415161718export function timelineSvg(repo: string, saves: Save[]): Html {19 const times = saves.map((save) => save.created_at);20 21 const first = times.reduce((a, b) => Math.min(a, b), times[0] ?? 0);22 const span = times.reduce((a, b) => Math.max(a, b), first) - first;23 const reach = Math.max(span / 40, 3600);24 const dots = saves.map((save) => {25 const x = span === 0 ? 50 : 1 + (98 * (save.created_at - first)) / span;26 27 28 const near = times.filter((t) => Math.abs(t - save.created_at) <= reach).length;29 const level = near >= 8 ? 3 : near >= 4 ? 2 : near >= 2 ? 1 : 0;30 const meta = [formatDate(save.created_at), save.agent, save.session]31 .filter(Boolean)32 .join(" · ");33 const tip = `${save.id}\n${save.message.split("\n")[0]}\n${meta}`;34 return html`<a href="/${35 repo36 }/saves/${save.id}" class="dot d${level}"><title>${tip}</title><circle cx="${x.toFixed(3)}%" cy="28" r="${2.5 + level * 0.5}"/></a>`;37 });38 const perDay = saves.length / Math.max(span / DAY, 1);39 const pace = PACE.find(([min]) => perDay > min)?.[1] ?? "quiet";40 return html`<svg class="timeline" width="100%" height="56" role="img" aria-label="${41 saves.length42 } saves over time">43<line class="timeline-line" x1="0" x2="100%" y1="28" y2="28"/>44${dots}45</svg>46<p class="timeline-legend mono">${pace} · density = activity · position = time</p>`;47}