Spell out the highlighted day under the food chart
A stacked bar cannot be read on a phone. There is nothing to hover, so the bar's title is unreachable, and the only way to get a day's figure was to estimate it against the axis — which a split bar makes harder, not easier. Tapping a bar now writes that day out beneath the chart: "Sun, Sep 20 — Dry 260 g · Fresh 100 g · 360 g in total", or just the total where no kinds are in play. The same problem exists without kinds, so it is not gated on them; the unsplit form says the number once rather than "No kind 340 g · 340 g in total". It reads off the day already selected rather than keeping a selection of its own. Tapping a bar selects that day on every chart in the app and this one already highlights it, so a second piece of "which day" state would only be something to keep in step and eventually fail to. It falls out of that choice that the arrows and the date picker move the readout too, which is the behaviour you would want anyway. Three cases say something rather than reading as blank: a day with no food, a day marked not counted, and a day outside the window — which has no bar, so no readout. The changelog entry for this sits on its own rather than inside the food-kinds one. It started life gated on kinds and is not any more, and "once you are using kinds" would have been the wrong condition to file it under.
This commit is contained in:
1 parent
3584758b86
commit
8c9ea45410
5 files changed
+131
No files matched your search
+41
@@ -2056,6 +2056,7 @@
|
||||
}
|
||||
|
||||
renderFoodLegend(series);
|
||||
renderFoodDayInfo(days, series);
|
||||
renderFoodTrendNote(days, series);
|
||||
|
||||
setChartSVG(svg, parts);
|
||||
@@ -2108,6 +2109,46 @@
|
||||
return out;
|
||||
}
|
||||
|
||||
// What the highlighted bar holds, in words. Tapping a bar selects that day
|
||||
// — the behaviour every chart already has — so this reads off the selection
|
||||
// rather than keeping a second one of its own, which would then have to be
|
||||
// kept in step with it.
|
||||
//
|
||||
// Shown whether or not the bars are split. A phone has nothing to hover, so
|
||||
// the bar's tooltip is unreachable and the day's figure was otherwise only
|
||||
// readable by eye off the axis — that is as true of one bar as of a stack.
|
||||
function renderFoodDayInfo(days, series) {
|
||||
const el = document.getElementById("grams-day-info");
|
||||
if (!el) return;
|
||||
const day = days.find(d => d.ymd === ymd(selectedDay()));
|
||||
if (!day) { el.hidden = true; return; } // not a day this window draws
|
||||
|
||||
const date = day.date.toLocaleDateString(undefined, { weekday: "short", month: "short", day: "numeric" });
|
||||
el.hidden = false;
|
||||
if (day.excluded) {
|
||||
el.textContent = `${date} — not counted.`;
|
||||
return;
|
||||
}
|
||||
// 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`);
|
||||
const total = `${Math.round(day.grams)} g`;
|
||||
|
||||
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 {
|
||||
// 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.`;
|
||||
}
|
||||
}
|
||||
|
||||
function renderFoodLegend(series) {
|
||||
const el = document.getElementById("grams-legend");
|
||||
if (!el) return;
|
||||
|
||||
Reference in new issue
Block a user