Salud: one colour per family of metric, so the grid reads at a glance
Tests / test (push) Canceled after 0s
Publish Docker images / build (., ./web/Dockerfile, web) (push) Canceled after 0s
Publish Docker images / build (./api, ./api/Dockerfile, api) (push) Canceled after 0s

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.
This commit is contained in:
dsantillan committed 2026-09-23 11:19:15 -04:00
1 parent 4222e8d86b
commit 3b7c9011c4
5 files changed
+66 -8

No files matched your search

+11 -2
View File
@@ -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;
+20
View File
@@ -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,
+17 -1
View File
@@ -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', () => {
+8 -5
View File
@@ -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 <button className="tile tappable vh-card" onClick={() => onOpen(card)}>
// `--tint` is the card's family colour (lib/vitals-view.js). The number, the icon, the chart and
// the wash behind the card all read from it, so one variable re-skins the whole card and the
// grid becomes scannable by colour instead of by reading every label.
return <button className="tile tappable vh-card" style={{ '--tint': card.tint }} onClick={() => onOpen(card)}>
<div className="l"><Icon name={card.icon} />{card.label}</div>
<div className="v">
{fmtValue(card.value, card.dec)}
@@ -56,7 +59,7 @@ function MetricCard({ card, onOpen }) {
<Trend card={card} />
</div>
{card.series.length > 1
? <div className="vh-spark"><LineChart points={chartPoints(card)} h={36} axes={false} /></div>
? <div className="vh-spark"><LineChart points={chartPoints(card)} h={36} axes={false} color={card.tint} /></div>
: <div className="vh-spark-ph" />}
</button>
}
@@ -73,8 +76,8 @@ function MetricSheet({ card, metric, close }) {
const tr = trendOf(card)
return <>
<h3>{card.label}</h3>
<div className="vh-sheet-top">
<div className="stat-v" style={{ fontSize: 34 }}>
<div className="vh-sheet-top" style={{ '--tint': card.tint }}>
<div className="stat-v vh-big">
{fmtValue(card.value, card.dec)}
{unitLabel(card.unit) ? <span className="vh-unit">{unitLabel(card.unit)}</span> : null}
</div>
@@ -83,7 +86,7 @@ function MetricSheet({ card, metric, close }) {
{tr ? ` · ${tr.dir === 'up' ? '+' : '−'}${Math.round(tr.pct * 100)}% ${t('vs your average')}` : ''}
</div>
</div>
<div className="card vh-chart"><LineChart points={chartPoints(card)} h={160} unit={unitLabel(card.unit)} /></div>
<div className="card vh-chart"><LineChart points={chartPoints(card)} h={160} unit={unitLabel(card.unit)} color={card.tint} /></div>
{rows.length > 0 && <>
<h4 className="sec">{t('What the watch sent')}</h4>
<div className="list">{rows.map(r => <Row key={r.key} title={r.label}
+10
View File
@@ -87,6 +87,16 @@ describe('Salud', () => {
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()