From 7f7650252d77995ad361d56278d88780e8c09522 Mon Sep 17 00:00:00 2001 From: Adam French Date: Wed, 14 Oct 2026 22:50:00 +0100 Subject: [PATCH] Add a day timeline, trend chart and goal history to the dashboard The dashboard gains a per-kind timeline of the selected day, a 14-day trend chart per kind, and a goal history grid with streaks, sharing a tooltip and a fixed color per top series. The activities limit rises to 5000 so busy days fit on the timeline. Co-Authored-By: Claude Opus 5.5 --- web/src/api.ts | 15 ++++- web/src/components/DayTimeline.vue | 99 ++++++++++++++++++++++++++++++ web/src/components/GoalHistory.vue | 48 +++++++++++++++ web/src/components/Tooltip.vue | 16 +++++ web/src/components/TrendChart.vue | 71 +++++++++++++++++++++ web/src/style.css | 69 +++++++++++++++++++++ web/src/tip.ts | 19 ++++++ web/src/views/Dashboard.vue | 69 ++++++++++++++++++--- 8 files changed, 395 insertions(+), 11 deletions(-) create mode 100644 web/src/components/DayTimeline.vue create mode 100644 web/src/components/GoalHistory.vue create mode 100644 web/src/components/Tooltip.vue create mode 100644 web/src/components/TrendChart.vue create mode 100644 web/src/tip.ts diff --git a/web/src/api.ts b/web/src/api.ts index ad9aa08..5d1ad44 100644 --- a/web/src/api.ts +++ b/web/src/api.ts @@ -39,5 +39,18 @@ export function dur(s: number): string { } // Friendlier names for the kinds collectors send; anything else shows as is. -const KINDS: Record = { app_focus: "desktop", tab_focus: "browser", at_desk: "at desk", in_bed: "in bed" }; +const KINDS: Record = { app_focus: "desktop", tab_focus: "browser", at_desk: "at desk", in_bed: "in bed", place: "location" }; export const kindName = (k: string) => KINDS[k] || k; + +// Series colors: the day's biggest (kind, label) pairs get a fixed slot each, +// in order; the rest share a neutral "other" color. +export const SLOTS = 7; +export const IDLE = new Set(["idle", "locked"]); +export const seriesKey = (kind: string, label: string) => kind + "\0" + label; +export function seriesSlots(totals: Total[]): Map { + const m = new Map(); + [...totals].filter(t => !IDLE.has(t.kind)).sort((a, b) => b.seconds - a.seconds) + .slice(0, SLOTS).forEach((t, i) => m.set(seriesKey(t.kind, t.label), i)); + return m; +} +export const slotColor = (i: number | undefined) => i === undefined ? "var(--other)" : `var(--s${i + 1})`; diff --git a/web/src/components/DayTimeline.vue b/web/src/components/DayTimeline.vue new file mode 100644 index 0000000..3fce46a --- /dev/null +++ b/web/src/components/DayTimeline.vue @@ -0,0 +1,99 @@ + + + diff --git a/web/src/components/GoalHistory.vue b/web/src/components/GoalHistory.vue new file mode 100644 index 0000000..203cf02 --- /dev/null +++ b/web/src/components/GoalHistory.vue @@ -0,0 +1,48 @@ + + + diff --git a/web/src/components/Tooltip.vue b/web/src/components/Tooltip.vue new file mode 100644 index 0000000..dde74cc --- /dev/null +++ b/web/src/components/Tooltip.vue @@ -0,0 +1,16 @@ + + + diff --git a/web/src/components/TrendChart.vue b/web/src/components/TrendChart.vue new file mode 100644 index 0000000..14ef1a1 --- /dev/null +++ b/web/src/components/TrendChart.vue @@ -0,0 +1,71 @@ + + + diff --git a/web/src/style.css b/web/src/style.css index f41c6be..5dbce35 100644 --- a/web/src/style.css +++ b/web/src/style.css @@ -2,11 +2,18 @@ :root { --bg:#f6f6f4; --card:#ffffff; --fg:#1b1b1b; --muted:#6b6b6b; --line:#e4e4e0; --accent:#3d6fc4; --accent-soft:#e8eefa; --ok:#2e8b57; --bad:#c0392b; --code:#f2f2ef; + /* Chart series, in fixed order (validated for colour-blind separation). */ + --s1:#2a78d6; --s2:#eb6834; --s3:#1baf7a; --s4:#eda100; --s5:#e87ba4; --s6:#008300; --s7:#6250d6; + --other:#b9b8b1; --idle:#e6e5e0; --grid:#ecebe6; --axis:#c3c2b7; + --ok-soft:#e3f2e9; --bad-soft:#f8e4e1; } @media (prefers-color-scheme: dark) { :root { --bg:#121212; --card:#1b1b1b; --fg:#e8e8e8; --muted:#9a9a9a; --line:#2c2c2c; --accent:#7aa2ea; --accent-soft:#1e2a40; --ok:#5cc28a; --bad:#e2685a; --code:#232323; + --s1:#3987e5; --s2:#d95926; --s3:#199e70; --s4:#c98500; --s5:#d55181; --s6:#008300; --s7:#9085e9; + --other:#5a5955; --idle:#2e2e2c; --grid:#262625; --axis:#383835; + --ok-soft:#18301f; --bad-soft:#3a1f1c; } } * { box-sizing:border-box; } @@ -80,3 +87,65 @@ details.collector > summary::before { content:"▸"; color:var(--muted); } details.collector[open] > summary::before { content:"▾"; } details.collector > summary b { font-size:15px; } details.collector > .body { padding:0 16px 16px; } + +/* ---- charts ---- */ +.tooltip { position:fixed; z-index:10; pointer-events:none; transform:translate(-50%, calc(-100% - 12px)); + background:var(--card); border:1px solid var(--line); border-radius:8px; padding:6px 10px; + box-shadow:0 4px 14px rgba(0,0,0,.12); font-size:13px; white-space:nowrap; max-width:80vw; overflow:hidden; text-overflow:ellipsis; } +.tooltip .strong { font-weight:650; font-size:14px; font-variant-numeric:tabular-nums; } +.tooltip .key { display:inline-block; width:10px; height:2px; margin:0 6px 3px 0; vertical-align:middle; border-radius:1px; } +.legend { display:flex; flex-wrap:wrap; gap:6px 14px; margin-top:12px; font-size:13px; } +.legend-item { display:inline-flex; align-items:center; gap:6px; overflow-wrap:anywhere; } +.swatch { width:10px; height:10px; border-radius:3px; flex:none; } + +.timeline .lane { display:flex; align-items:center; gap:8px; } +.timeline .lane + .lane { margin-top:6px; } +.timeline .lane-name { width:64px; flex:none; font-size:13px; color:var(--muted); text-align:right; } +.timeline .track { position:relative; flex:1; height:18px; min-width:0; } +.timeline .axis .track { height:16px; } +.timeline .grid { position:absolute; top:-3px; bottom:-3px; width:1px; background:var(--grid); } +.timeline .seg { position:absolute; top:0; bottom:0; border-radius:3px; } +.timeline .seg:hover { filter:brightness(1.15); } +.timeline .now { position:absolute; top:-4px; bottom:-4px; width:2px; margin-left:-1px; background:var(--fg); border-radius:1px; } +.timeline .tick { position:absolute; transform:translateX(-50%); font-size:12px; color:var(--muted); font-variant-numeric:tabular-nums; white-space:nowrap; } +.timeline .tick.first { transform:none; } +.timeline .tick.last { transform:translateX(-100%); } +@media (max-width:520px) { .timeline .tick:nth-child(even) { display:none; } } + +.meter { position:relative; height:6px; margin-top:6px; border-radius:3px; background:var(--accent-soft); max-width:320px; } +.meter .fill { height:100%; border-radius:3px; background:var(--accent); } +.meter.bad .fill { background:var(--bad); } +.meter .target { position:absolute; top:-3px; bottom:-3px; width:2px; margin-left:-1px; background:var(--fg); border-radius:1px; } + +.trend .plot { display:flex; gap:8px; height:140px; margin-top:22px; } +.trend .yaxis { position:relative; width:32px; flex:none; } +.trend .yaxis span { position:absolute; right:0; transform:translateY(50%); font-size:12px; color:var(--muted); font-variant-numeric:tabular-nums; } +.trend .area { position:relative; flex:1; display:flex; min-width:0; } +.trend .grid { position:absolute; left:0; right:0; height:1px; background:var(--grid); } +.trend .grid.base { background:var(--axis); } +.trend .col { position:relative; flex:1; height:100%; display:flex; align-items:flex-end; justify-content:center; + background:none; border:0; border-radius:4px; padding:0; } +.trend .col:hover { background:var(--accent-soft); } +.trend .bar-v { width:min(24px, calc(100% - 4px)); background:var(--s1); border-radius:4px 4px 0 0; opacity:.55; } +.trend .col.sel .bar-v { opacity:1; } +.trend .cap { position:absolute; transform:translateY(-4px); font-size:12px; font-weight:600; white-space:nowrap; font-variant-numeric:tabular-nums; } +.trend .xaxis { display:flex; margin-left:40px; margin-top:4px; } +.trend .xaxis span { flex:1; text-align:center; font-size:12px; color:var(--muted); font-variant-numeric:tabular-nums; } +.trend .xaxis span.sel { color:var(--fg); font-weight:650; } + +.history .hrow { display:grid; grid-template-columns:minmax(0, 1fr) auto 76px; gap:6px 12px; align-items:center; + padding:7px 0; border-bottom:1px solid var(--line); } +.history .hrow:last-of-type { border-bottom:0; } +.history .name { overflow-wrap:anywhere; } +.history .cells { display:flex; gap:2px; } +.history .streak { text-align:right; white-space:nowrap; } +@media (max-width:620px) { + .history .hrow { grid-template-columns:1fr auto; } + .history .cells { grid-row:2; grid-column:1 / -1; } +} +.history .cell { width:22px; height:22px; padding:0; border:0; border-radius:4px; font-size:12px; line-height:22px; text-align:center; flex:none; } +@media (max-width:420px) { .history .cell { width:auto; flex:1; } } +.history .cell.met { background:var(--ok-soft); color:var(--ok); } +.history .cell.miss { background:var(--bad-soft); color:var(--bad); } +.history .cell.none { background:var(--code); } +.history .cell.sel { outline:2px solid var(--fg); outline-offset:1px; } diff --git a/web/src/tip.ts b/web/src/tip.ts new file mode 100644 index 0000000..16ee1f0 --- /dev/null +++ b/web/src/tip.ts @@ -0,0 +1,19 @@ +import { reactive } from "vue"; + +// One floating tooltip per chart. The first line is the value, shown strongest. +export interface TipRow { text: string; color?: string } +export function useTip() { + const tip = reactive({ show: false, x: 0, y: 0, rows: [] as TipRow[] }); + function show(e: MouseEvent | FocusEvent, rows: TipRow[]) { + if (e instanceof MouseEvent) { + tip.x = e.clientX; tip.y = e.clientY; + } else { + const r = (e.target as Element).getBoundingClientRect(); + tip.x = r.left + r.width / 2; tip.y = r.top; + } + tip.rows = rows; + tip.show = true; + } + const hide = () => { tip.show = false; }; + return { tip, show, hide }; +} diff --git a/web/src/views/Dashboard.vue b/web/src/views/Dashboard.vue index 675547a..d611260 100644 --- a/web/src/views/Dashboard.vue +++ b/web/src/views/Dashboard.vue @@ -1,8 +1,12 @@