From 3b7c9011c4fbac07c0cd6dbda997ac7743eac7cb Mon Sep 17 00:00:00 2001 From: Daniel Santillan Date: Wed, 23 Sep 2026 11:19:15 -0400 Subject: [PATCH] Salud: one colour per family of metric, so the grid reads at a glance MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Every card carried the same white number, which meant reading fourteen labels to find the one you came for. Each family now has a colour — activity green, heart pink, body blue, sleep indigo, vitals teal, everything unrecognised grey — and the card's number, its icon, its sparkline and a low wash behind it all read from a single `--tint` property set by lib/vitals-view.js. The detail sheet follows the same tint, so opening a card keeps its colour. The tints are the app's own palette variables, not hex values: the light theme redefines every one of them, so a card stays legible in both. They are deliberately not `var(--acc)` — the accent is whatever the person chose in Settings, and a dashboard whose "steps" colour changes with the theme accent is one nobody can learn. Grey for the unknown group is the honest choice: an unrecognised metric has no family to colour. The wash is 8% on purpose. The colour is there to sort the grid, not to shout, and a saturated tile behind a 26px number fights the number it is meant to highlight; the value itself carries the colour at full strength. Guarded twice: vitals-view.test.js checks every group resolves to a tint and that no two groups share one (sharing would defeat the point), and the render test checks the cards actually carry `--tint` — the wiring, not the shades, which is the part that can silently break. --- frontend/src/index.css | 13 +++++++++++-- frontend/src/lib/vitals-view.js | 20 ++++++++++++++++++++ frontend/src/lib/vitals-view.test.js | 18 +++++++++++++++++- frontend/src/views/Health.jsx | 13 ++++++++----- frontend/src/views/Health.render.test.jsx | 10 ++++++++++ 5 files changed, 66 insertions(+), 8 deletions(-) diff --git a/frontend/src/index.css b/frontend/src/index.css index 1aca342..bdf16b1 100644 --- a/frontend/src/index.css +++ b/frontend/src/index.css @@ -1271,9 +1271,18 @@ body.chips-dragging *{cursor:inherit} A health card is a tile with three more things in it: a unit, a trend arrow and a four-point sparkline. The sparkline is what makes the grid readable at a glance — a bare "12,481" says nothing about whether that is a good week — so it gets its own fixed-height box rather than - being allowed to stretch the card when a metric has only one day of data. */ -.vh-card{width:100%;text-align:left;display:block;font:inherit;color:inherit;padding-bottom:10px} + being allowed to stretch the card when a metric has only one day of data. + + Each card carries a `--tint` from lib/vitals-view.js (one colour per family of metric), and + everything coloured on the card reads from it: the number, the icon, the sparkline and a wash + behind the card. The wash is kept low (8%) on purpose — the colour is there to sort the grid at + a glance, not to shout, and a saturated tile behind a 26px number would fight the number. */ +.vh-card{--tint:var(--grey);width:100%;text-align:left;display:block;font:inherit;color:inherit;padding-bottom:10px; + background:color-mix(in srgb,var(--tint) 8%,var(--surface))} +.vh-card .l .icn{color:var(--tint)} +.vh-card .v{color:var(--tint)} .vh-unit{margin-left:4px;font-size:14px;font-weight:500;color:var(--label-2);letter-spacing:0} +.vh-big{font-size:34px;color:var(--tint)} .vh-trend{ float:right;display:inline-flex;align-items:center;gap:1px; font-size:13px;font-weight:500;letter-spacing:0; diff --git a/frontend/src/lib/vitals-view.js b/frontend/src/lib/vitals-view.js index f4bbc12..feafe31 100644 --- a/frontend/src/lib/vitals-view.js +++ b/frontend/src/lib/vitals-view.js @@ -20,6 +20,25 @@ const GROUP_LABEL = { activity: 'Activity', heart: 'Heart', body: 'Body', sleep: 'Sleep', vitals: 'Vitals', other: 'Other' } +/* One colour per family, so a glance tells you what kind of number you are looking at — the same + job the group heading does, but readable while scrolling past. The tints come from the app's + own palette variables rather than fixed hex values: the light theme redefines every one of them + (`:root[data-theme="light"]` in index.css), so a card stays legible in both. + * + * Deliberately NOT `var(--acc)`: the accent is whatever the person picked in Settings, and a + * dashboard whose "steps" colour changes with the theme accent is a dashboard nobody can learn. + * Grey for `other` matches the group's meaning — an unrecognised metric has no family to colour. + */ +export const GROUP_TINT = { + activity: 'var(--green)', + heart: 'var(--pink)', + body: 'var(--blue)', + sleep: 'var(--indigo)', + vitals: 'var(--teal)', + other: 'var(--grey)' +} +export const tintOf = group => GROUP_TINT[group] || GROUP_TINT.other + const spec = (label, group, o = {}) => ({ label, group, @@ -167,6 +186,7 @@ export function metricCards(data, { days = 90 } = {}) { name, label: s.unknown ? s.label : t(s.label), group: s.group, + tint: tintOf(s.group), unit: s.unit || (m && m.units) || '', icon: s.icon, dec: s.dec, diff --git a/frontend/src/lib/vitals-view.test.js b/frontend/src/lib/vitals-view.test.js index f28bcb3..f3f9b92 100644 --- a/frontend/src/lib/vitals-view.test.js +++ b/frontend/src/lib/vitals-view.test.js @@ -2,7 +2,7 @@ import { describe, it, expect } from 'vitest' import { METRICS, specOf, humanize, valueOfDay, metricCards, sortCards, groupedCards, trendOf, chartPoints, workoutRows, hasVitals, activeDays, ingestUrl, unitLabel, fmtValue, agoLabel, - detailRows, workoutIcon + detailRows, workoutIcon, GROUP_ORDER, tintOf } from './vitals-view.js' /* The mapping from HAE's metric names to what a card shows. Worth testing because it is the one @@ -100,6 +100,22 @@ describe('metricCards', () => { expect(steps.day).toBe('2026-05-03') expect(steps.requestedDays).toBe(90) }) + + it('gives every family its own colour, and the unknown ones grey', () => { + // The tints are CSS variables, not hex: the light theme redefines them. + const tints = Object.fromEntries(metricCards(doc).map(c => [c.name, c.tint])) + expect(tints.step_count).toBe('var(--green)') // activity + expect(tints.heart_rate).toBe('var(--pink)') // heart + expect(tints.weight_body_mass).toBe('var(--blue)') // body + expect(tints.sleep_analysis).toBe('var(--indigo)') // sleep + expect(tints.some_new_metric).toBe('var(--grey)') // other + // Every group in the catalogue has one, and they are all distinct — two families sharing a + // colour would defeat the point of colouring them. + const perGroup = GROUP_ORDER.map(tintOf) + expect(perGroup.every(Boolean)).toBe(true) + expect(new Set(perGroup).size).toBe(GROUP_ORDER.length) + expect(tintOf('a-group-that-does-not-exist')).toBe('var(--grey)') + }) }) describe('trendOf', () => { diff --git a/frontend/src/views/Health.jsx b/frontend/src/views/Health.jsx index 541f96b..ebcd069 100644 --- a/frontend/src/views/Health.jsx +++ b/frontend/src/views/Health.jsx @@ -48,7 +48,10 @@ function Trend({ card }) { /** One card. Everything is a button: the detail sheet is where the chart and the fields live. */ function MetricCard({ card, onOpen }) { - return } @@ -73,8 +76,8 @@ function MetricSheet({ card, metric, close }) { const tr = trendOf(card) return <>

{card.label}

-
-
+
+
{fmtValue(card.value, card.dec)} {unitLabel(card.unit) ? {unitLabel(card.unit)} : null}
@@ -83,7 +86,7 @@ function MetricSheet({ card, metric, close }) { {tr ? ` · ${tr.dir === 'up' ? '+' : '−'}${Math.round(tr.pct * 100)}% ${t('vs your average')}` : ''}
-
+
{rows.length > 0 && <>

{t('What the watch sent')}

{rows.map(r => { expect(api).toHaveBeenCalledWith('/api/vitals?days=30') }) + it('paints each card with its family colour, which is what makes the grid scannable', async () => { + // The tint is a CSS variable on the card, so the number, the icon, the sparkline and the wash + // behind them all come from one property — this checks the wiring, not the shades. + api.mockResolvedValue(VITALS) + await mount() + const tints = cards().map(c => c.style.getPropertyValue('--tint')) + expect(tints).toEqual(['var(--green)', 'var(--pink)', 'var(--indigo)', 'var(--teal)', 'var(--grey)']) + expect(cards().every(c => c.getAttribute('style').includes('--tint'))).toBe(true) + }) + it('offers the setup steps instead of a blank screen when nothing has arrived', async () => { api.mockResolvedValue({ ok: true, days: 30, key: null, updatedAt: 0, last: null, metrics: {}, workouts: [] }) await mount()