mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-18 08:02:12 +00:00
fix(timeline): names that fit, links to each value's page, a calmer selection bar
Labels are placed without collisions: a name keeps a full gap before the
next mark on its line, is cut with an ellipsis when only part of it fits,
and is left out when not even a few characters do. A name above an open
bar ends before the bar's arrow head. All names are drawn after the today
and selection lines, on a halo of the card colour, so a line passes
behind a name instead of through it.
A value line's name wraps onto a second line instead of reading "Blood
pressure sy…", in every bundle, and it leads to the metric's page, as do
the value tiles in the day view. Both read one map from a kind of value
to its page (metricPageHref); a kind without a page stays plain text. The
links carry a 44 px target, a hover and a focus ring.
A life event's category is no longer run on after its title ("Parental
leave Family"): the chart names the event alone, the selection bar shows
the category as a small chip inside the entry, and the phone chronicle
puts it on the muted line below.
The selection bar shows each mean as name and value; the readings behind
it ("mean of 19 readings") are a hover title and a screen-reader detail.
The lone "Open <date>" link at its end is gone; a day opens from its
chips, Enter on the chart or a double click.
In the day view an event's time keeps to one line in every locale.
This commit is contained in:
1 parent
cd72317356
commit
df67e285de
12 files changed
+538
-82
No files matched your search
@@ -19,7 +19,12 @@ import { ReadinessInventory, VerdictMeter } from "../readiness-inventory";
|
||||
import { SelectionBar, bucketTitle } from "../selection-bar";
|
||||
import { assignSeriesColors } from "../series-colors";
|
||||
import type { SeriesValueFormat } from "../series-format";
|
||||
import { MeanPartsLine, SeriesLines, TimelineChart } from "../timeline-chart";
|
||||
import {
|
||||
MeanPartsLine,
|
||||
SeriesLines,
|
||||
SeriesNameLinks,
|
||||
TimelineChart,
|
||||
} from "../timeline-chart";
|
||||
import { TimelineChronicle } from "../timeline-chronicle";
|
||||
import { layoutTimeline } from "../timeline-geometry";
|
||||
import { useSeriesValueFormat } from "../use-series-value-format";
|
||||
@@ -311,7 +316,7 @@ const bar = (selected: string, timeline = fullTimeline(), showHint = false) =>
|
||||
);
|
||||
|
||||
describe("selection bar", () => {
|
||||
it("lists the month's entries and offers the selected day", () => {
|
||||
it("lists the month's entries, and no separate link to open the day", () => {
|
||||
const html = bar("2026-01-03");
|
||||
expect(html).toContain("Januar 2026");
|
||||
expect(html).toContain("Erkältung, 31. Dez. bis 8. Jan.");
|
||||
@@ -320,8 +325,10 @@ describe("selection bar", () => {
|
||||
expect(html).toContain("Vitamin D (Winter), 1. Nov. bis 31. März");
|
||||
expect(html).not.toContain("laufend");
|
||||
expect(html).not.toContain("Bluthochdruck");
|
||||
expect(html).toContain("3. Jan. öffnen");
|
||||
expect(html).toContain('data-date="2026-01-03"');
|
||||
// The day opens from its chips and the chart; the lone "Open 3 Jan."
|
||||
// link at the end of the bar is gone.
|
||||
expect(html).not.toContain("3. Jan. öffnen");
|
||||
expect(html).not.toContain('data-slot="timeline-open-day"');
|
||||
});
|
||||
|
||||
it("names a pause as a pause", () => {
|
||||
@@ -329,12 +336,25 @@ describe("selection bar", () => {
|
||||
expect(html).toContain("Ramipril pausiert, 1. Juni bis 11. Juni");
|
||||
});
|
||||
|
||||
it("names the bucket's means with the readings behind each", () => {
|
||||
expect(text(bar("2026-01-03"))).toContain(
|
||||
"Ø Blutdruck 129/82 mmHg (Schnitt aus 4 Messungen), Gewicht 82,6 kg (Schnitt aus 3 Messungen)",
|
||||
it("names the bucket's means, the readings behind each as a hover and for a screen reader", () => {
|
||||
const html = bar("2026-01-03");
|
||||
// What the line shows: the name and the value, nothing more.
|
||||
const visible = text(
|
||||
html.replace(
|
||||
/<span[^>]*data-slot="timeline-mean-detail"[^>]*>[^<]*<\/span>/g,
|
||||
"",
|
||||
),
|
||||
);
|
||||
expect(visible).toContain("Ø Blutdruck 129/82 mmHg, Gewicht 82,6 kg");
|
||||
expect(visible).not.toContain("Schnitt aus");
|
||||
// The readings: a title on the value, and the same words read aloud.
|
||||
expect(html).toContain('title="Schnitt aus 4 Messungen"');
|
||||
expect(html).toContain('title="Schnitt aus 3 Messungen"');
|
||||
expect(text(html)).toContain(
|
||||
"Ø Blutdruck 129/82 mmHg, Schnitt aus 4 Messungen, Gewicht 82,6 kg, Schnitt aus 3 Messungen",
|
||||
);
|
||||
expect(text(bar("2026-07-15"))).toContain(
|
||||
"Ø Blutdruck sys. 131 mmHg (1 Messung), Blutdruck dia. kein Wert, Gewicht kein Wert",
|
||||
"Ø Blutdruck sys. 131 mmHg, 1 Messung, Blutdruck dia. kein Wert, Gewicht kein Wert",
|
||||
);
|
||||
});
|
||||
|
||||
@@ -437,7 +457,7 @@ describe("selection bar head and hint", () => {
|
||||
],
|
||||
};
|
||||
const html = text(bar("2026-01-03", timeline));
|
||||
expect(html).toContain("9 Std. 16 Min. (Schnitt aus 31 Messungen)");
|
||||
expect(html).toContain("9 Std. 16 Min., Schnitt aus 31 Messungen");
|
||||
expect(html).not.toContain("556");
|
||||
});
|
||||
});
|
||||
@@ -552,3 +572,32 @@ describe("life events in the capture picker", () => {
|
||||
).not.toContain("lifeEvent");
|
||||
});
|
||||
});
|
||||
|
||||
describe("value-line names", () => {
|
||||
it("lead to their metric's page, with a 44 px target, and none for a kind without one", () => {
|
||||
const tl = fullTimeline();
|
||||
const layout = layoutTimeline({
|
||||
width: 1200,
|
||||
window: { from: "2025-10-01", to: "2026-10-31" },
|
||||
lanes: tl.lanes,
|
||||
series: [...tl.series, { key: "NOT_A_TYPE", unit: null, points: [] }],
|
||||
bucket: tl.bucket,
|
||||
words: wordsIn("de"),
|
||||
startMissing: "?",
|
||||
today: TODAY,
|
||||
});
|
||||
const html = render(
|
||||
<SeriesNameLinks layout={layout} seriesLabel={(k) => `name ${k}`} />,
|
||||
);
|
||||
expect(html).toMatch(
|
||||
/data-slot="timeline-series-link"[^>]*data-series="WEIGHT"|href="\/insights\/weight"[^>]*data-slot="timeline-series-link"/,
|
||||
);
|
||||
expect(html).toContain('href="/insights/weight"');
|
||||
expect(html).toContain('href="/insights/blood-pressure"');
|
||||
expect(html).toContain('aria-label="name WEIGHT"');
|
||||
expect(html).not.toContain('data-series="NOT_A_TYPE"');
|
||||
for (const height of html.match(/height:(\d+)px/g) ?? []) {
|
||||
expect(Number(height.replace(/\D/g, ""))).toBeGreaterThanOrEqual(44);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -7,6 +7,10 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
LineOccupancy,
|
||||
NEIGHBOUR_GAP,
|
||||
placeText,
|
||||
seriesNameLines,
|
||||
createScale,
|
||||
dateAtPointer,
|
||||
estimateTextWidth,
|
||||
@@ -408,7 +412,10 @@ describe("layoutLane", () => {
|
||||
]);
|
||||
for (const label of layout.labels) {
|
||||
const point = layout.points.find((p) => p.item.id === label.itemId)!;
|
||||
expect(label.x).toBeGreaterThan(point.x + 7);
|
||||
// Right of the glyph, or left of it when the next mark is too near.
|
||||
const right = label.x > point.x + 7;
|
||||
const left = label.x + estimateTextWidth(label.text) < point.x - 7;
|
||||
expect(right || left).toBe(true);
|
||||
expect(label.strong).toBe(true);
|
||||
}
|
||||
});
|
||||
@@ -736,3 +743,108 @@ describe("interaction", () => {
|
||||
).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("label room (v1.42 final)", () => {
|
||||
it("puts a long value-line name on two lines instead of cutting it", () => {
|
||||
const width = 164 - 12 - 16;
|
||||
expect(seriesNameLines("Gewicht", width, 13)).toEqual(["Gewicht"]);
|
||||
const lines = seriesNameLines("Blood pressure sys.", width, 13);
|
||||
expect(lines).toEqual(["Blood pressure", "sys."]);
|
||||
for (const line of lines) {
|
||||
expect(estimateTextWidth(line, 13)).toBeLessThanOrEqual(width);
|
||||
}
|
||||
// Two lines are the most; the second is cut when even two do not hold it.
|
||||
const long = seriesNameLines(
|
||||
"Walking heart rate average over the whole day",
|
||||
width,
|
||||
13,
|
||||
);
|
||||
expect(long).toHaveLength(2);
|
||||
expect(long[1].endsWith("…")).toBe(true);
|
||||
});
|
||||
|
||||
it("keeps a gap before the next mark, cuts a name short, or leaves it out", () => {
|
||||
const occ = new LineOccupancy();
|
||||
occ.add("0:on", 200, 210);
|
||||
// Whole: ends a full gap before the mark at 200.
|
||||
expect(placeText(occ, "0:on", 100, "abcd", 1000)).toBe("abcd");
|
||||
const occ2 = new LineOccupancy();
|
||||
occ2.add("0:on", 200, 210);
|
||||
const cut = placeText(occ2, "0:on", 100, "a long label that runs on", 1000);
|
||||
expect(cut?.endsWith("…")).toBe(true);
|
||||
expect(100 + estimateTextWidth(cut!)).toBeLessThanOrEqual(
|
||||
200 - NEIGHBOUR_GAP,
|
||||
);
|
||||
// No room for even a few characters: no label at all.
|
||||
const occ3 = new LineOccupancy();
|
||||
occ3.add("0:on", 120, 130);
|
||||
expect(placeText(occ3, "0:on", 100, "a long label", 1000)).toBeNull();
|
||||
});
|
||||
|
||||
it("keeps a medication's name above its bar clear of the bar's arrow", () => {
|
||||
const window = { from: "2026-07-11", to: "2026-10-09" };
|
||||
const scale = createScale(window, 164, 700);
|
||||
const lane = layoutLane(
|
||||
{
|
||||
lane: {
|
||||
key: "medications",
|
||||
items: [
|
||||
item({
|
||||
id: "mg",
|
||||
group: "mg",
|
||||
kind: "medication",
|
||||
// Started late in the window: a short bar near today.
|
||||
start: "2026-09-20",
|
||||
open: true,
|
||||
startKnown: false,
|
||||
label: "Magnesium",
|
||||
sub: "400mg",
|
||||
}),
|
||||
],
|
||||
},
|
||||
top: 0,
|
||||
},
|
||||
window,
|
||||
scale,
|
||||
{ words: WORDS, startMissing: "Startdatum fehlt", today: "2026-10-09" },
|
||||
);
|
||||
const bar = lane.spans[0];
|
||||
expect(lane.labels.length).toBeGreaterThan(0);
|
||||
for (const label of lane.labels) {
|
||||
const right = label.x + estimateTextWidth(label.text);
|
||||
// Above the bar it ends before the arrow head; beside it, it starts
|
||||
// after it.
|
||||
if (label.y < bar.y) expect(right).toBeLessThanOrEqual(bar.xEnd - 2);
|
||||
else expect(label.x >= bar.xEnd + 7 || right <= bar.xStart).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
it("never lets two names of one lane line overlap or crowd each other", () => {
|
||||
for (const width of [390, 700, 1100, 1600]) {
|
||||
const layout = layoutAt(width);
|
||||
for (const lane of layout.lanes) {
|
||||
const byLine = new Map<number, ReturnType<typeof boxes>>();
|
||||
for (const box of boxes(lane)) {
|
||||
const list = byLine.get(box.y) ?? [];
|
||||
list.push(box);
|
||||
byLine.set(box.y, list);
|
||||
}
|
||||
for (const list of byLine.values()) {
|
||||
list.sort((p, q) => p.a - q.a);
|
||||
for (let i = 1; i < list.length; i++) {
|
||||
expect(list[i].a).toBeGreaterThanOrEqual(list[i - 1].b);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it("names a life event without its category glued on", () => {
|
||||
const life = fullTimeline().lanes.find((l) => l.key === "life")!;
|
||||
for (const entry of life.items) {
|
||||
const words = WORDS(entry);
|
||||
expect(words.sub).toBeNull();
|
||||
expect(itemLine(entry, WORDS, "")).toBe(entry.label);
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user