Put the day's food breakdown inside the Meals card

The total sat in the Meals card and the per-kind split sat in a row beneath the
whole stats grid, so the two halves of the same figure were in different
places. The split now goes under the total it adds up to.

I argued against this when the row went in, on the grounds that a 90px tile
cannot hold a breakdown. That was true of the shape I had in mind — "Dry 260 g
· Fresh 100 g" inline is about 110px — and not of the one that belongs there:
stacked, a line per kind, it is about 60px.

A single kind gets no line of its own. The total is already that kind's figure,
so the name joins it — "540 g · Dry" — rather than repeating the number
underneath. Same rule the chart's day readout uses, and for the same reason.

A day with no kinds on its meals leaves the tile exactly as it was, which is
the overview anyone not using kinds keeps.

The changelog entry for this has shipped and said the breakdown appears "under
the stat tiles". It does not any more, so it is corrected in place: leaving a
description that is now wrong would be worse than editing an entry some readers
have already seen.
This commit is contained in:
Alexander Heldt committed 2026-09-22 15:10:51 +00:00
1 parent cd13efdbed
commit 41827664de
5 files changed
+75 -41

No files matched your search

+28 -13
View File
@@ -447,15 +447,16 @@
return new Map(loadExercises().map(x => [x.id, x.name]));
}
// The day's food, split the way the chart splits the window. The Meals tile
// keeps the total — that is the headline figure, and the breakdown will not
// fit in a 90px tile — so this sits under the grid instead.
// The day's food per kind, inside the Meals tile under the total it adds up
// to — the food figures belong together, and having the total in the tile
// while the split sat in a row of its own put them in two places.
//
// Only shown when a meal that day actually carries a kind: an account not
// using kinds should see the overview it has always seen, and a day whose
// meals all predate kinds is exactly that case.
function renderDayFoodKinds(dayEvents) {
const el = document.getElementById("stat-food-kinds");
// gramsEl is the tile's total line, which this may append a name to: with a
// single kind the total *is* that kind's figure, so "540 g · Dry" says it
// once instead of listing it again below. Same rule as the chart's day
// readout, for the same reason.
function renderDayFoodKinds(dayEvents, gramsEl, gramsTotal) {
const el = document.getElementById("stat-meals-kinds");
if (!el) return;
const names = foodKindNames();
const order = liveFoodKinds().map(k => k.id);
@@ -467,19 +468,33 @@
if (id !== NO_KIND) anyKind = true;
totals.set(id, (totals.get(id) || 0) + e.grams);
}
if (!anyKind) { el.hidden = true; return; }
el.hidden = true;
el.textContent = "";
// No kinds on this day's meals: the tile keeps the plain total it always
// had, which is the whole overview for anyone not using kinds.
if (!anyKind) return;
// Same order as the chart's layers, with "No kind" last, so the two read
// as the same breakdown rather than two arbitrary lists.
const nameOf = (id) => (id === NO_KIND ? "No kind" : (names.get(id) || "Deleted kind"));
const ids = [...totals.keys()].sort((a, b) => {
if (a === NO_KIND) return 1;
if (b === NO_KIND) return -1;
const ia = order.indexOf(a), ib = order.indexOf(b);
return (ia === -1 ? Infinity : ia) - (ib === -1 ? Infinity : ib);
});
el.textContent = ids
.map(id => `${id === NO_KIND ? "No kind" : (names.get(id) || "Deleted kind")} ${Math.round(totals.get(id))} g`)
.join(" · ");
if (ids.length === 1) {
gramsEl.textContent = `${Math.round(gramsTotal)} g · ${nameOf(ids[0])}`;
return;
}
// Several: the tile's total stays as it is and each kind gets a line under
// it, so the parts and the sum they make are read together.
for (const id of ids) {
const line = document.createElement("div");
line.textContent = `${nameOf(id)} ${Math.round(totals.get(id))} g`;
el.appendChild(line);
}
el.hidden = false;
}
@@ -934,7 +949,7 @@
const gramsEl = document.getElementById("stat-meals-grams");
gramsEl.textContent = gramsTotal > 0 ? `${Math.round(gramsTotal)} g` : "";
gramsEl.hidden = !(gramsTotal > 0);
renderDayFoodKinds(dayEvents);
renderDayFoodKinds(dayEvents, gramsEl, gramsTotal);
// Walk time is a duration, not a count, so the tile leads with it and puts
// "N walks" underneath — the day's exercise at a glance.
document.getElementById("stat-walk").textContent = formatDuration(walkMsInRange(events, from, to));