Judge the day readout by the day's kinds, not the window's

A day whose food was all unlabelled read "Fri, Sep 18 — No kind 300 g · 300 g
in total": the number twice, under a label with nothing to distinguish it from.

The guard was on the wrong quantity. It asked whether the *chart* was split,
when what decides this is how many kinds *that day* holds — and a chart split
across other days can still land on a day of one kind. Keying off the day's own
parts fixes the reported case and a second one nobody had hit yet, where a day
of a single named kind read "Dry 300 g · 300 g in total".

So: several kinds keep the total beside them, being what the bar's height shows
and what you would otherwise add up. One kind does not, because it already is
the total. And "No kind" alone drops its label, which was only ever there to
tell it apart from something else.

The new assertions were checked against the old guard, where five of them fail.
The original ones passed throughout, which is the point — they only ever
exercised a chart with one series, and this bug lives on the other axis.
This commit is contained in:
Alexander Heldt committed 2026-09-22 15:05:02 +00:00
1 parent 8c9ea45410
commit cd13efdbed
2 files changed
+43 -10

No files matched your search

+16 -10
View File
@@ -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.`;
}
}