diff --git a/CHANGELOG.md b/CHANGELOG.md index 8531411..5f4eca9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,9 +9,16 @@ rate, sleep, weight, oxygen, workouts, and every other metric HAE can export — fork has never heard of, which land under **Other** with a humanised name and a detail sheet listing every field the watch sent. -The cards sit two to a row, on a phone and on a desktop alike — every other grid in the app goes -to four columns once there is width for them, and at four across a health card wraps its unit onto -a second line and flattens the sparkline that makes the grid readable at a glance. +Every metric is one card in one grid, two to a row, on a phone and on a desktop alike — every other +grid in the app goes to four columns once there is width for them, and at four across a health card +wraps its unit onto a second line and flattens the sparkline that makes the grid readable at a +glance. An earlier version put the first four metrics in catalogue order (steps, active energy, +exercise time, stand hours) in a full-width "Trends" section above the grid, with a big chart and +the window's own min/avg/high. It read as two screens stapled together — four huge cards, one per +row, above a tidy grid of small ones — and since those four are the ones most people look at, the +grid looked like it was missing its own headline metrics. The shape of a week is the sparkline on +the card now, and the chart worth reading is one tap away, where it also has the hours and the +day-by-day numbers around it. Per profile, and private by construction. Each profile mints its own **ingest key** (write-only: it can add to that one profile's health file and cannot read a single number back), and rotating it diff --git a/frontend/src/index.css b/frontend/src/index.css index 3619d35..acca52a 100644 --- a/frontend/src/index.css +++ b/frontend/src/index.css @@ -1404,22 +1404,10 @@ body.chips-dragging *{cursor:inherit} /* --- the chart panels ----------------------------------------------------- Full-width panels for the few metrics people open this screen for. Same `--tint` contract as the tiles, so a panel and its card are recognisably the same metric. */ -.vh-charts{display:flex;flex-direction:column;gap:10px;margin-bottom:14px} -.vh-tchart{--tint:var(--grey);width:100%;text-align:left;display:block;font:inherit;color:inherit; - padding:12px 10px 6px;background:color-mix(in srgb,var(--tint) 9%,var(--glass)); - border:var(--hair) solid color-mix(in srgb,var(--tint) 20%,transparent); - -webkit-backdrop-filter:blur(10px) saturate(140%);backdrop-filter:blur(10px) saturate(140%)} -.vh-tchart:active{background:color-mix(in srgb,var(--tint) 14%,var(--glass))} /* Deliberately NO opaque fallback where backdrop-filter is missing, unlike the tab bar. The bar floats over scrolling content, where a see-through panel would put text on text; a card sits in the page flow, and the only thing behind it is the aura. Losing the blur there costs nothing, and the opaque fallback is exactly what made these cards look solid on a device that took it. */ -.vh-tchart-hd{display:flex;align-items:baseline;justify-content:space-between;gap:10px;padding:0 2px;margin-bottom:2px} -.vh-tchart-t{display:flex;align-items:center;gap:5px;font-size:14px;font-weight:500;color:var(--label-2)} -.vh-tchart-t .icn{font-size:15px;color:var(--tint)} -.vh-tchart-v{font-size:22px;font-weight:600;letter-spacing:-.022em;color:var(--tint);font-variant-numeric:tabular-nums} -.vh-tchart-v i{margin-left:3px;font-size:12px;font-weight:500;font-style:normal;color:var(--label-2)} -.vh-tchart-ft{display:flex;gap:12px;padding:0 2px;margin-top:1px;font-size:11.5px;color:var(--label-3);font-variant-numeric:tabular-nums} .vh-window{font-weight:400;color:var(--label-3);text-transform:none;letter-spacing:0} .vh-sheet-top{margin:2px 0 12px} diff --git a/frontend/src/lib/vitals-view.js b/frontend/src/lib/vitals-view.js index 40d3ac8..51c1a9a 100644 --- a/frontend/src/lib/vitals-view.js +++ b/frontend/src/lib/vitals-view.js @@ -314,27 +314,6 @@ export function dayLabel(day, now = new Date()) { return fmtDate(day) } -/** - * The cards worth a full-width chart: the catalogue's own order (steps, heart rate, sleep…), - * only the ones the window has enough days to draw. A chart of a single point is a dot, so those - * are left to the grid's own card rather than given a panel that looks broken. - */ -export function trendCards(cards, { limit = 4, minDays = 2 } = {}) { - return cards.filter(c => c.series.length >= minDays).slice(0, limit) -} - -/** min / max / average over a card's window, for the caption under a chart. */ -export function seriesStats(card) { - const vs = (card?.series || []).map(p => p.v).filter(v => Number.isFinite(v)) - if (!vs.length) return null - return { - min: Math.min(...vs), - max: Math.max(...vs), - avg: vs.reduce((a, b) => a + b, 0) / vs.length, - days: vs.length - } -} - /* ---------- units and numbers ---------- */ // HAE's unit strings are compact and sometimes need a human spelling. Values are never converted: diff --git a/frontend/src/lib/vitals-view.test.js b/frontend/src/lib/vitals-view.test.js index ed14fcf..34c11f2 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, GROUP_ORDER, tintOf, dayLabel, trendCards, seriesStats, + detailRows, workoutIcon, GROUP_ORDER, tintOf, dayLabel, hourRows, hourChartPoints, historyRows } from './vitals-view.js' @@ -213,7 +213,7 @@ describe('aliases', () => { }) }) -describe('dayLabel / trendCards / seriesStats', () => { +describe('dayLabel', () => { const now = new Date('2026-05-03T09:00:00') it('names the newest day in words when it is recent', () => { @@ -226,21 +226,7 @@ describe('dayLabel / trendCards / seriesStats', () => { expect(dayLabel(undefined, now)).toBe('') }) - it('picks the cards a full-width chart is worth, in catalogue order', () => { - const cards = metricCards(doc) - const picked = trendCards(cards, { limit: 3 }) - // In this fixture only two metrics have two days or more; heart_rate and weight_body_mass - // carry a single day each, and a one-point chart is a dot nobody can read. - expect(picked.map(c => c.name)).toEqual(['step_count', 'resting_heart_rate']) - expect(trendCards(cards, { limit: 20 }).every(c => c.series.length >= 2)).toBe(true) - // A card with a single day is left out: a one-point chart is a dot. - expect(trendCards([{ name: 'x', series: [{ day: '2026-05-03', v: 1 }] }])).toEqual([]) - }) - - it('summarises a window for the caption under a chart', () => { - expect(seriesStats(card(doc, 'step_count'))).toMatchObject({ min: 5000, max: 12000, days: 3 }) - expect(seriesStats(card(doc, 'step_count')).avg).toBe(8000) - expect(seriesStats({ series: [] })).toBeNull() + it('keeps the newest reading\'s timestamp, which is what makes a card checkable', () => { expect(card(doc, 'step_count').lastTs).toBeTruthy() }) }) diff --git a/frontend/src/views/Health.jsx b/frontend/src/views/Health.jsx index 7471a6b..8523f3a 100644 --- a/frontend/src/views/Health.jsx +++ b/frontend/src/views/Health.jsx @@ -26,7 +26,7 @@ import LineChart from '../components/LineChart.jsx' import { todayISO } from '../lib/format.js' import { groupedCards, metricCards, trendOf, chartPoints, workoutRows, hasVitals, - fmtValue, unitLabel, agoLabel, ingestUrl, detailRows, dayLabel, trendCards, seriesStats, + fmtValue, unitLabel, agoLabel, ingestUrl, detailRows, dayLabel, hourRows, hourChartPoints, historyRows } from '../lib/vitals-view.js' @@ -78,39 +78,14 @@ function MetricCard({ card, onOpen }) { } -/** - * The charts. Every card in the grid carries a sparkline, which is enough to see a shape and not - * enough to read one — so the first few metrics in the catalogue's own order (steps, heart rate, - * sleep…, the ones people open this screen for) get a panel: axes, the window's own min/max/avg, - * and the card's colour, so a panel and its tile are recognisably the same thing. - */ -function TrendSection({ cards, windowLabel, onOpen }) { - const picked = cards - if (!picked.length) return null - return <> -

{t('Trends')} · {windowLabel}

-
- {picked.map(c => { - const st = seriesStats(c) - return - })} -
- -} +/* There used to be a "Trends" section here: the first four metrics in catalogue order (steps, + active energy, exercise time, stand hours) drawn as full-width panels with a big chart and the + window's own min/avg/high, with those four taken out of the grid below so nothing was shown + twice. It read as a different screen stapled to the top of this one — four huge cards, one per + row, above a tidy grid of small ones, and the four it happened to pick were the four most people + look at, so the grid looked like it was missing its own headline metrics. Every metric is now the + same card, two to a row; the shape of a week is the sparkline on it, and the chart worth reading + is one tap away, where it also has the hours and the day-by-day numbers around it. */ /* ---------- the two sheets ---------- */ @@ -373,15 +348,11 @@ export default function Health() { const fresh = all.filter(c => c.day === todayISO_) const cards = days === 1 && fresh.length ? fresh : all const fellBack = days === 1 && !fresh.length && all.length > 0 - /* A metric appears exactly once. The panels above are drawn from the same set as the grid, and - the ones they cover are taken out of it — before this, steps (say) was a chart panel and a - tile, which read as the screen showing everything twice. */ - const featured = trendCards(cards, { limit: 4 }) - const featuredNames = new Set(featured.map(c => c.name)) - const groups = groupedCards(cards.filter(c => !featuredNames.has(c.name))) + // One grid, every metric, one card each: catalogue order inside its group, and no card drawn + // twice in two different sizes (see the note above the sheets). + const groups = groupedCards(cards) const workouts = workoutRows(data, { limit: 20 }) const last = data?.last?.ts - const windowLabel = chartDays >= 365 ? t('the last year') : t('the last {0} days', chartDays) const ranges = RANGES.map(r => ({ value: r.value, label: r.key ? t(r.key) : r.label })) return <> @@ -417,8 +388,6 @@ export default function Health() { {t('Nothing has come in today yet — this is the latest reading of each metric.')} } - - {groups.map(g =>

{g.label}

{/* Two per row (`vh-tiles`), on a phone and on a wide screen alike: every other grid in diff --git a/frontend/src/views/Health.render.test.jsx b/frontend/src/views/Health.render.test.jsx index acece5a..f6fb3d8 100644 --- a/frontend/src/views/Health.render.test.jsx +++ b/frontend/src/views/Health.render.test.jsx @@ -67,29 +67,25 @@ const mount = async () => { await act(async () => {}) // let the fetch's promise settle } const text = () => host.textContent -/* Everything on the screen that is a metric: the chart panels at the top (`.vh-tchart`) and the - tiles in the grid (`.vh-card`), in the order they are painted. The screen is supposed to show - each metric exactly once across the two — it did not, which is why `seenOnce` exists below. */ -const entries = () => [...host.querySelectorAll('.vh-card, .vh-tchart')] +/* Every metric on the screen is one card in one grid, in the order it is painted. `seenOnce` + guards that: the screen used to draw its first four metrics twice — a full-width panel on top + and a tile below — which read as a bug because it was one, and the panels are gone now for a + different reason (four huge cards above a tidy grid read as two screens stapled together). */ const cards = () => [...host.querySelectorAll('.vh-card')] -const entryText = el => el.textContent -const seenOnce = () => { - const labels = entries().map(e => e.querySelector('.l, .vh-tchart-t').textContent) - return labels.filter((l, i) => labels.indexOf(l) !== i) -} +const labels = () => cards().map(c => c.querySelector('.l').textContent) +const seenOnce = () => labels().filter((l, i) => labels().indexOf(l) !== i) describe('Salud', () => { it('draws one card per metric, grouped, with the number the catalogue says to show', async () => { api.mockResolvedValue(VITALS) await mount() - const shown = entries().map(e => e.querySelector('.l, .vh-tchart-t').textContent) - expect(shown.sort()).toEqual(['Heart rate', 'Sleep', 'Some metric from the future', 'Steps', 'Walking steadiness']) - // The one that was reported: every metric once, never a chart panel AND its tile. + expect(labels().sort()).toEqual(['Heart rate', 'Sleep', 'Some metric from the future', 'Steps', 'Walking steadiness']) + // Every metric once, never a big card AND a small one. expect(seenOnce()).toEqual([]) // Steps show the day's total, heart rate the day's average, sleep hours asleep. The unknown // metric falls back to the field with the most samples (its average), rather than a dash. - const byLabel = Object.fromEntries(entries().map(e => [e.querySelector('.l, .vh-tchart-t').textContent, entryText(e)])) + const byLabel = Object.fromEntries(cards().map(e => [e.querySelector('.l').textContent, e.textContent])) expect(byLabel['Steps']).toContain('12,481') expect(byLabel['Heart rate']).toContain('69') expect(byLabel['Heart rate']).toContain('bpm') @@ -97,14 +93,15 @@ describe('Salud', () => { expect(byLabel['Walking steadiness']).toContain('91') expect(byLabel['Some metric from the future']).toContain('120') - // Group headings, the range control, and the read-only workout list. Activity is absent on - // purpose: in this fixture its only metric is Steps, which the panels took, and a heading with - // nothing under it is worse than no heading. - expect(text()).not.toContain('Activity') + // Group headings, the range control, and the read-only workout list. Activity is here now: + // Steps is in the grid like everything else (it used to be a panel, which took it out). + expect(text()).toContain('Activity') expect(text()).toContain('Heart') expect(text()).toContain('Vitals') expect(text()).toContain('Other') - expect(text()).toContain('Trends') + // ...and there is no second, bigger rendering of the same metrics above the grid. + expect(text()).not.toContain('Trends') + expect(host.querySelectorAll('.vh-tchart').length).toBe(0) expect(text()).toContain('Workouts from your iPhone') expect(text()).toContain('Functional Strength Training') expect(text()).toContain('50 min') @@ -123,7 +120,7 @@ describe('Salud', () => { await mount() const grids = [...host.querySelectorAll('.tiles.vh-tiles')] expect(grids.length).toBeGreaterThan(1) // one per group that has cards - expect(grids.reduce((n, g) => n + g.querySelectorAll('.vh-card').length, 0)).toBe(4) + expect(grids.reduce((n, g) => n + g.querySelectorAll('.vh-card').length, 0)).toBe(5) // ...and every grid on the screen is one of them: a group that lost the class would silently // go back to four columns at ≥1000px. expect([...host.querySelectorAll('.tiles')]).toEqual(grids) @@ -136,9 +133,9 @@ describe('Salud', () => { api.mockResolvedValue(VITALS) await mount() // Panels and tiles carry the same property, so the colours come out in the order they paint. - expect(entries().map(e => e.style.getPropertyValue('--tint'))) + expect(cards().map(e => e.style.getPropertyValue('--tint'))) .toEqual(['var(--orange)', 'var(--red)', 'var(--indigo)', 'var(--green)', 'var(--grey)']) - expect(entries().every(e => e.getAttribute('style').includes('--tint'))).toBe(true) + expect(cards().every(e => e.getAttribute('style').includes('--tint'))).toBe(true) }) it('offers the setup steps instead of a blank screen when nothing has arrived', async () => { @@ -217,7 +214,7 @@ describe('the detail sheet', () => { // outlives the screen's root), so reading document.body would read somebody else's day. const sheetEl = () => [...document.querySelectorAll('.sheet')].pop() const sheet = () => sheetEl()?.textContent || '' - const openSteps = () => click(entries().find(e => (e.querySelector('.l, .vh-tchart-t') || {}).textContent === 'Steps')) + const openSteps = () => click(cards().find(e => e.querySelector('.l').textContent === 'Steps')) const withHours = () => ({ ...VITALS,