diff --git a/checks/food-trend.mjs b/checks/food-trend.mjs index 5e9ba70..d07ef20 100644 --- a/checks/food-trend.mjs +++ b/checks/food-trend.mjs @@ -315,6 +315,33 @@ suite("what the sentence is allowed to say"); "a day marked not counted says that instead of reading as empty"); } + + suite("a day holding only one kind"); + { + // The chart is split — other days have several kinds — but this day's food + // is all one. The total is that one figure, so saying it twice is noise. + kinds = [{ id: "d", name: "Dry", colorIndex: 0 }, { id: "f", name: "Fresh", colorIndex: 1 }]; + const days = [day(18, { "": 300 }), day(19, { d: 210, f: 90 }), day(20, { d: 300 })]; + + selected = "2026-09-18"; + const unlabelled = read(days).textContent; + eq(unlabelled, "Fri, Sep 18 — 300 g.", + "a day of unlabelled food gives the bare total, on a split chart too"); + ok(!/No kind/.test(unlabelled), + "…without the 'No kind' label, which has nothing to distinguish it from"); + ok(!/in total/.test(unlabelled), "…and without saying the number twice"); + + selected = "2026-09-20"; + const oneKind = read(days).textContent; + eq(oneKind, "Sun, Sep 20 — Dry 300 g.", + "a day of one named kind keeps the name, which does say something"); + ok(!/in total/.test(oneKind), "…but still does not repeat the figure"); + + selected = "2026-09-19"; + ok(/in total/.test(read(days).textContent), + "two kinds on a day still get the total beside them"); + } + suite("an unsplit chart gets the day total too"); { // No kinds defined: there is still no hover on a phone, so the figure was diff --git a/src/app.js b/src/app.js index 2a1baf6..094d4e8 100644 --- a/src/app.js +++ b/src/app.js @@ -2131,21 +2131,27 @@ } // Series order, so this reads as the stack above it read bottom to top. const parts = series - .map(s => ({ name: s.name, g: s.of(day) })) - .filter(p => p.g > 0) - .map(p => `${p.name} ${Math.round(p.g)} g`); + .map(s => ({ id: s.id, name: s.name, g: s.of(day) })) + .filter(p => p.g > 0); const total = `${Math.round(day.grams)} g`; + const label = (p) => `${p.name} ${Math.round(p.g)} g`; + // What matters is how many kinds *this day* holds, not how many the window + // does. A chart split across other days can still land on a day whose food + // is all one kind, and there the total is that kind's own figure. if (parts.length === 0) { el.textContent = `${date} — no food logged.`; - } else if (series.length <= 1) { - // Unsplit: the one part *is* the total, and naming it twice — "No kind - // 340 g · 340 g in total" — would be daft. - el.textContent = `${date} — ${total}.`; + } else if (parts.length === 1) { + // One part is the whole day, so repeating it as a total says the same + // number twice. And "No kind" as the sole label says nothing at all — + // there is nothing for it to distinguish the food from. + el.textContent = parts[0].id === NO_KIND + ? `${date} — ${total}.` + : `${date} — ${label(parts[0])}.`; } else { - // The total is worth repeating beside the parts: it is what the bar's - // height shows, and it saves adding them up. - el.textContent = `${date} — ${parts.join(" · ")} · ${total} in total.`; + // Several kinds: the total earns its place beside them, being what the + // bar's height shows and what you would otherwise add up yourself. + el.textContent = `${date} — ${parts.map(label).join(" · ")} · ${total} in total.`; } }