Stats: activity heatmap as a rolling window of the last 14 days

One row per calendar day (today at the bottom) instead of weekdays
aggregated over the selected range.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Richard ZinkandClaude Opus 5.5 committed 2026-11-09 06:22:36 +01:00
1 parent 01c1484033
commit d14c609576
5 files changed
+46 -23

No files matched your search

+9 -10
View File
@@ -173,33 +173,32 @@ export function StackedBars({
);
}
/** Weekday × hour heatmap with a 7-step sequential ramp. cells[weekday*24+hour]. */
/** Day × hour heatmap with a 7-step sequential ramp. cells[row*24+hour]; rows top to bottom. */
export function Heatmap({
cells,
weekdays,
rows,
format,
firstDay = 1,
}: {
cells: number[];
weekdays: string[];
/** Short label (axis) and long label (tooltip) per row. */
rows: { label: string; title: string }[];
format: (v: number) => string;
firstDay?: number;
}) {
const t = useT();
const [ref, width] = useWidth<HTMLDivElement>();
const [tip, setTip] = useState<Tip>();
const left = 40;
const left = 64;
const top = 18;
// Cells stretch with the width but stay at most 26 px tall.
const cellW = Math.max(Math.floor((width - left) / 24), 8);
const cell = Math.min(cellW, 26);
const max = Math.max(...cells, 0);
const order = Array.from({ length: 7 }, (_, i) => (firstDay + i) % 7);
const order = rows.map((_, i) => i);
const bin = (v: number) => (v <= 0 || max === 0 ? 0 : Math.min(6, 1 + Math.floor((v / max) * 5.999)));
return (
<div className="chart" ref={ref} onMouseLeave={() => setTip(undefined)}>
<svg height={top + cell * 7 + 4} role="img" aria-label={t("stats.heatmap")}>
<svg height={top + cell * rows.length + 4} role="img" aria-label={t("stats.heatmap")}>
<g className="axis">
{Array.from({ length: 24 }, (_, h) => h)
.filter((h) => h % (cellW >= 22 ? 1 : cellW >= 12 ? 3 : 6) === 0)
@@ -210,7 +209,7 @@ export function Heatmap({
))}
{order.map((d, row) => (
<text key={d} x={left - 6} y={top + row * cell + cell / 2 + 4} textAnchor="end">
{weekdays[d]}
{rows[d].label}
</text>
))}
</g>
@@ -234,7 +233,7 @@ export function Heatmap({
content: (
<>
<b>
{weekdays[d]} {String(h).padStart(2, "0")}:00–{String(h).padStart(2, "0")}:59
{rows[d].title} {String(h).padStart(2, "0")}:00–{String(h).padStart(2, "0")}:59
</b>
<div>{format(v)}</div>
</>