mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-16 07:13:29 +00:00
feat(timeline): keep gaps in value lines, mark thin means, allow six lines
Every bucket with a reading gets its point; one with fewer than three readings is drawn hollow. A short gap (one quarter, two months, four weeks) is bridged with a dashed stroke between the two real points; a longer one leaves the line open. The selection bar and the value table for screen readers name each bucket's readings and say "no value" where there is none. The phone chronicle names each bucket once, at its newest month. The value menu takes up to six lines. The legend's causality line is gone with its keys in all seven bundles.
This commit is contained in:
1 parent
af982e3812
commit
fcc6f40410
21 files changed
+1011
-203
No files matched your search
@@ -16,6 +16,7 @@ import { I18nProvider } from "@/lib/i18n/context";
|
||||
import { ReadinessCard } from "../readiness-card";
|
||||
import { ReadinessInventory, VerdictMeter } from "../readiness-inventory";
|
||||
import { SelectionBar } from "../selection-bar";
|
||||
import { TimelineChart } from "../timeline-chart";
|
||||
import { TimelineChronicle } from "../timeline-chronicle";
|
||||
import { TODAY, fullTimeline, readiness } from "./timeline-fixture";
|
||||
|
||||
@@ -121,25 +122,109 @@ describe("chronicle", () => {
|
||||
);
|
||||
expect(html).toContain("129/82 mmHg · 82,6 kg");
|
||||
});
|
||||
|
||||
it("names a quarter once, at its newest month, with its span", () => {
|
||||
const timeline = {
|
||||
...fullTimeline(),
|
||||
bucket: "quarter" as const,
|
||||
series: [
|
||||
{
|
||||
key: "WEIGHT",
|
||||
unit: "kg",
|
||||
points: [{ t: "2026-01-01", mean: 82.6, count: 9 }],
|
||||
},
|
||||
],
|
||||
};
|
||||
const html = render(
|
||||
<TimelineChronicle
|
||||
timeline={timeline}
|
||||
today={TODAY}
|
||||
grouping="month"
|
||||
selected={null}
|
||||
onOpenDay={() => undefined}
|
||||
onEditLifeEvent={null}
|
||||
/>,
|
||||
);
|
||||
expect(html.match(/data-slot="timeline-chronicle-means"/g)).toHaveLength(1);
|
||||
expect(html).toContain("Jan bis März 2026: 82,6 kg");
|
||||
});
|
||||
});
|
||||
|
||||
const LABELS: Record<string, string> = {
|
||||
BLOOD_PRESSURE_SYS: "Blutdruck sys.",
|
||||
BLOOD_PRESSURE_DIA: "Blutdruck dia.",
|
||||
WEIGHT: "Gewicht",
|
||||
};
|
||||
const seriesLabel = (key: string) => LABELS[key] ?? key;
|
||||
|
||||
describe("selection bar", () => {
|
||||
it("lists the month's entries and offers the selected day", () => {
|
||||
const html = render(
|
||||
const bar = (selected: string) =>
|
||||
render(
|
||||
<SelectionBar
|
||||
timeline={fullTimeline()}
|
||||
selected="2026-01-03"
|
||||
selected={selected}
|
||||
today={TODAY}
|
||||
seriesLabel={seriesLabel}
|
||||
onOpenDay={() => undefined}
|
||||
/>,
|
||||
);
|
||||
|
||||
it("lists the month's entries and offers the selected day", () => {
|
||||
const html = bar("2026-01-03");
|
||||
expect(html).toContain("Januar 2026");
|
||||
expect(html).toContain("Erkältung · 31. Dez. bis 8. Jan.");
|
||||
expect(html).toContain("Vitamin D (Winter) · laufend");
|
||||
expect(html).not.toContain("Bluthochdruck");
|
||||
expect(html).toContain("3. Jan. öffnen");
|
||||
expect(html).toContain('data-date="2026-01-03"');
|
||||
expect(html).toContain("Ø 129/82 mmHg · 82,6 kg");
|
||||
});
|
||||
|
||||
it("names the bucket's means with the readings behind each", () => {
|
||||
expect(bar("2026-01-03")).toContain(
|
||||
"Ø Januar 2026: Blutdruck 129/82 mmHg (Schnitt aus 4 Messungen) · Gewicht 82,6 kg (Schnitt aus 3 Messungen)",
|
||||
);
|
||||
expect(bar("2026-07-15")).toContain(
|
||||
"Ø Juli 2026: Blutdruck sys. 131 mmHg (1 Messung) · Blutdruck dia. kein Wert · Gewicht kein Wert",
|
||||
);
|
||||
});
|
||||
|
||||
it("says a missing month has no value instead of interpolating one", () => {
|
||||
const html = bar("2026-02-10");
|
||||
expect(html).toContain(
|
||||
"Ø Februar 2026: Blutdruck sys. kein Wert · Blutdruck dia. kein Wert · Gewicht kein Wert",
|
||||
);
|
||||
// January's 129 and March's 133 would make 131 between them.
|
||||
expect(html).not.toMatch(/\d mmHg/);
|
||||
});
|
||||
});
|
||||
|
||||
describe("value table for a screen reader", () => {
|
||||
it("lists every month between the first and the last reading, gaps as gaps", () => {
|
||||
const html = render(
|
||||
<TimelineChart
|
||||
timeline={fullTimeline()}
|
||||
window={{ from: "2025-10-01", to: "2026-10-31" }}
|
||||
zoom="year"
|
||||
today={TODAY}
|
||||
selected={null}
|
||||
hiddenLanes={new Set()}
|
||||
seriesLabel={seriesLabel}
|
||||
onSelect={() => undefined}
|
||||
onOpenDay={() => undefined}
|
||||
/>,
|
||||
);
|
||||
const table = html.slice(html.indexOf('data-slot="timeline-series-table"'));
|
||||
// October 2025 to July 2026: ten months, newest first.
|
||||
expect(table.match(/data-bucket="/g)).toHaveLength(10);
|
||||
const row = (bucket: string) => {
|
||||
const start = table.indexOf(`data-bucket="${bucket}"`);
|
||||
return table.slice(start, table.indexOf("</tr>", start));
|
||||
};
|
||||
expect(row("2026-02-01")).toContain("Februar 2026");
|
||||
expect(row("2026-02-01").match(/kein Wert/g)).toHaveLength(3);
|
||||
expect(row("2026-01-01")).toContain("129 mmHg, Schnitt aus 4 Messungen");
|
||||
expect(row("2026-07-01")).toContain("131 mmHg, 1 Messung");
|
||||
expect(row("2026-05-01")).not.toMatch(/mmHg|kg/);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -235,31 +235,31 @@ export function fullTimeline(): TimelineResponse {
|
||||
},
|
||||
],
|
||||
standing: [],
|
||||
bucket: "month",
|
||||
series: [
|
||||
{
|
||||
key: "BLOOD_PRESSURE_SYS",
|
||||
unit: "mmHg",
|
||||
granularity: "month",
|
||||
points: [
|
||||
{ t: "2025-10-01", mean: 127 },
|
||||
{ t: "2025-11-01", mean: 128 },
|
||||
{ t: "2025-12-01", mean: 130 },
|
||||
{ t: "2026-01-01", mean: 129 },
|
||||
// Nothing for February to June.
|
||||
{ t: "2026-07-01", mean: 131 },
|
||||
{ t: "2025-10-01", mean: 127, count: 6 },
|
||||
{ t: "2025-11-01", mean: 128, count: 5 },
|
||||
{ t: "2025-12-01", mean: 130, count: 4 },
|
||||
{ t: "2026-01-01", mean: 129, count: 4 },
|
||||
// Nothing in February: one missing month, bridged.
|
||||
{ t: "2026-03-01", mean: 133, count: 2 },
|
||||
// Nothing from April to June: three missing months, broken.
|
||||
{ t: "2026-07-01", mean: 131, count: 1 },
|
||||
],
|
||||
},
|
||||
{
|
||||
key: "BLOOD_PRESSURE_DIA",
|
||||
unit: "mmHg",
|
||||
granularity: "month",
|
||||
points: [{ t: "2026-01-01", mean: 82 }],
|
||||
points: [{ t: "2026-01-01", mean: 82, count: 4 }],
|
||||
},
|
||||
{
|
||||
key: "WEIGHT",
|
||||
unit: "kg",
|
||||
granularity: "month",
|
||||
points: [{ t: "2026-01-01", mean: 82.6 }],
|
||||
points: [{ t: "2026-01-01", mean: 82.6, count: 3 }],
|
||||
},
|
||||
],
|
||||
notable: [{ date: "2026-01-04", kind: "extremeHigh" }],
|
||||
|
||||
@@ -40,6 +40,7 @@ function layoutAt(width: number): TimelineLayout {
|
||||
window: windowFor("all", TODAY, null, tl.range),
|
||||
lanes: tl.lanes,
|
||||
series: tl.series,
|
||||
bucket: tl.bucket,
|
||||
startMissing: "Startdatum fehlt",
|
||||
today: TODAY,
|
||||
});
|
||||
@@ -345,30 +346,136 @@ describe("layoutTimeline", () => {
|
||||
});
|
||||
|
||||
describe("layoutSeries", () => {
|
||||
it("breaks the line across missing months instead of bridging them", () => {
|
||||
const window = { from: "2025-10-01", to: "2026-10-31" };
|
||||
const scale = createScale(window, 164, 1200);
|
||||
const [bp] = layoutSeries(
|
||||
fullTimeline().series.slice(0, 1),
|
||||
0,
|
||||
window,
|
||||
scale,
|
||||
);
|
||||
expect(bp.path.match(/M/g)).toHaveLength(2);
|
||||
const window = { from: "2025-10-01", to: "2026-10-31" };
|
||||
const scale = createScale(window, 164, 1200);
|
||||
const [bp] = layoutSeries(
|
||||
fullTimeline().series.slice(0, 1),
|
||||
0,
|
||||
window,
|
||||
scale,
|
||||
"month",
|
||||
);
|
||||
|
||||
it("keeps every month with a reading as a point, and invents none", () => {
|
||||
expect(bp.points.map((p) => p.t)).toEqual([
|
||||
"2025-10-01",
|
||||
"2025-11-01",
|
||||
"2025-12-01",
|
||||
"2026-01-01",
|
||||
"2026-03-01",
|
||||
"2026-07-01",
|
||||
]);
|
||||
expect(bp.points.map((p) => p.mean)).toEqual([
|
||||
127, 128, 130, 129, 133, 131,
|
||||
]);
|
||||
expect(bp.latest).toBe(131);
|
||||
});
|
||||
|
||||
it("keeps an empty series as a row without a line", () => {
|
||||
const window = { from: "2019-01-01", to: "2019-12-31" };
|
||||
const scale = createScale(window, 164, 1200);
|
||||
const [bp] = layoutSeries(
|
||||
fullTimeline().series.slice(0, 1),
|
||||
it("draws the run solid, bridges one missing month dashed, and breaks at three", () => {
|
||||
const [oct, , , jan, mar, jul] = bp.points;
|
||||
const at = (p: { x: number; y: number }) =>
|
||||
`${p.x.toFixed(1)} ${p.y.toFixed(1)}`;
|
||||
// One solid run, October to January.
|
||||
expect(bp.path.match(/M/g)).toHaveLength(1);
|
||||
expect(bp.path.startsWith(`M${at(oct)}`)).toBe(true);
|
||||
expect(bp.path.endsWith(`L${at(jan)}`)).toBe(true);
|
||||
// February is missing: one dashed stroke from January to March, with no
|
||||
// vertex between them.
|
||||
expect(bp.bridges).toBe(`M${at(jan)}L${at(mar)}`);
|
||||
// April to June are missing: July joins nothing.
|
||||
expect(bp.path).not.toContain(at(jul));
|
||||
expect(bp.bridges).not.toContain(at(jul));
|
||||
});
|
||||
|
||||
it("draws a bucket of fewer than three readings hollow", () => {
|
||||
expect(bp.points.map((p) => [p.t, p.thin])).toEqual([
|
||||
["2025-10-01", false],
|
||||
["2025-11-01", false],
|
||||
["2025-12-01", false],
|
||||
["2026-01-01", false],
|
||||
["2026-03-01", true],
|
||||
["2026-07-01", true],
|
||||
]);
|
||||
});
|
||||
|
||||
it("bridges at most one missing quarter and four missing weeks", () => {
|
||||
const quarter = (points: Array<[string, number]>) =>
|
||||
layoutSeries(
|
||||
[
|
||||
{
|
||||
key: "WEIGHT",
|
||||
unit: "kg",
|
||||
points: points.map(([t, mean]) => ({ t, mean, count: 5 })),
|
||||
},
|
||||
],
|
||||
0,
|
||||
{ from: "2020-01-01", to: "2026-12-31" },
|
||||
createScale({ from: "2020-01-01", to: "2026-12-31" }, 164, 1200),
|
||||
"quarter",
|
||||
)[0];
|
||||
// Q1, then Q3: one missing quarter, bridged.
|
||||
expect(
|
||||
quarter([
|
||||
["2024-01-01", 80],
|
||||
["2024-07-01", 81],
|
||||
]).bridges,
|
||||
).not.toBe("");
|
||||
// Q1, then Q4: two missing quarters, broken; each point still drawn.
|
||||
const broken = quarter([
|
||||
["2024-01-01", 80],
|
||||
["2024-10-01", 81],
|
||||
]);
|
||||
expect(broken.bridges).toBe("");
|
||||
expect(broken.path).toBe("");
|
||||
expect(broken.points).toHaveLength(2);
|
||||
|
||||
const weeks = (second: string) =>
|
||||
layoutSeries(
|
||||
[
|
||||
{
|
||||
key: "WEIGHT",
|
||||
unit: "kg",
|
||||
points: [
|
||||
{ t: "2026-01-05", mean: 80, count: 3 },
|
||||
{ t: second, mean: 81, count: 3 },
|
||||
],
|
||||
},
|
||||
],
|
||||
0,
|
||||
{ from: "2026-01-01", to: "2026-03-31" },
|
||||
createScale({ from: "2026-01-01", to: "2026-03-31" }, 164, 1200),
|
||||
"week",
|
||||
)[0];
|
||||
// Mondays: four missing weeks bridged, five broken.
|
||||
expect(weeks("2026-02-09").bridges).not.toBe("");
|
||||
expect(weeks("2026-02-16").bridges).toBe("");
|
||||
});
|
||||
|
||||
it("keeps a lone point visible", () => {
|
||||
const [weight] = layoutSeries(
|
||||
fullTimeline().series.slice(2, 3),
|
||||
0,
|
||||
window,
|
||||
scale,
|
||||
"month",
|
||||
);
|
||||
expect(bp.path).toBe("");
|
||||
expect(bp.latest).toBeNull();
|
||||
expect(weight.path).toBe("");
|
||||
expect(weight.bridges).toBe("");
|
||||
expect(weight.points).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("keeps an empty series as a row without a line", () => {
|
||||
const early = { from: "2019-01-01", to: "2019-12-31" };
|
||||
const [empty] = layoutSeries(
|
||||
fullTimeline().series.slice(0, 1),
|
||||
0,
|
||||
early,
|
||||
createScale(early, 164, 1200),
|
||||
"month",
|
||||
);
|
||||
expect(empty.path).toBe("");
|
||||
expect(empty.points).toEqual([]);
|
||||
expect(empty.latest).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user