From 2869a208f15fd336d4ff4f203d943652a10c1c03 Mon Sep 17 00:00:00 2001 From: bashynx Date: Mon, 26 Oct 2026 14:24:00 +0200 Subject: [PATCH] Food: week strip shows protein / carbs / fat; over-target days in red Each day's bar is stacked by the share of the energy from protein, carbs and fat (as in the History chart); hovering shows the calories and grams. A day more than 5 % over its target shows its calories in bold red. Dashboard and app. Co-Authored-By: Claude Opus 5.5 --- app/CHANGELOG.md | 2 ++ app/lib/health/food_page.dart | 22 +++++++++++++++--- dashboard/plugins/food/static/food.css | 6 +++-- .../plugins/food/templates/food/day.html | 4 ++-- dashboard/plugins/food/views.py | 23 +++++++++++++++---- 5 files changed, 46 insertions(+), 11 deletions(-) diff --git a/app/CHANGELOG.md b/app/CHANGELOG.md index 69b3ebe..667d486 100644 --- a/app/CHANGELOG.md +++ b/app/CHANGELOG.md @@ -19,6 +19,8 @@ What changed in each published build of the app. `tool/publish.sh` shows the ent search box, finds that food first. - Food: a barcode nothing is found for offers "New food with barcode …", which opens the editor with the barcode filled in. The dashboard does the same. +- Food: the week strip's day pills show the day's protein / carbs / fat in their colours (by their share of the + energy), and a day over its target has its calories in red. The dashboard does the same. ## 1.1.3 — 2026-10-26 diff --git a/app/lib/health/food_page.dart b/app/lib/health/food_page.dart index cc51bf4..50ecdd5 100644 --- a/app/lib/health/food_page.dart +++ b/app/lib/health/food_page.dart @@ -122,6 +122,7 @@ class _FoodPageState extends State { Widget _week(double target) { final mon = plus(d, -(d.weekday - 1)); final k = kcalByDay(widget.sync.store, dayIso(mon), dayIso(plus(mon, 6))); + final m = dayTotals(widget.sync.store, dayIso(mon), dayIso(plus(mon, 6))); return Row(children: [ for (var i = 0; i < 7; i++) () { @@ -140,12 +141,13 @@ class _FoodPageState extends State { const SizedBox(height: 3), Container( width: 12, height: 32, alignment: Alignment.bottomCenter, + clipBehavior: Clip.antiAlias, decoration: BoxDecoration(color: card2, borderRadius: BorderRadius.circular(3)), - child: FractionallySizedBox(heightFactor: h / 1.15, - child: Container(decoration: BoxDecoration(color: over ? bad : good, borderRadius: BorderRadius.circular(3)))), + child: FractionallySizedBox(heightFactor: h / 1.15, child: _macroFill(m[dayIso(x)], kc)), ), const SizedBox(height: 2), - Text(kc == null ? '' : '${kc.round()}', style: const TextStyle(fontSize: 10.5, color: muted)), + Text(kc == null ? '' : '${kc.round()}', + style: TextStyle(fontSize: 10.5, color: over ? bad : muted, fontWeight: over ? FontWeight.bold : null)), ]), ), ), @@ -154,6 +156,20 @@ class _FoodPageState extends State { ]); } + /// A week pill's fill, bottom up: protein / carbs / fat by their share of the energy, the rest grey + /// (views._macro_segs — as the History chart stacks them). + Widget _macroFill(Map? t, double? kcal) { + if (t == null || kcal == null || kcal <= 0) return const SizedBox(); + final e = {for (final k in macros) k: (t[k] ?? 0) * kcalPerG[k]!}; + final total = max(kcal, e.values.fold(0, (a, b) => a + b)); + final rest = total - e.values.fold(0, (a, b) => a + b); + return Column(children: [ + if (rest / total > 0.005) Expanded(flex: (rest / total * 1000).round(), child: Container(color: muted.withValues(alpha: 0.5))), + for (final k in macros.reversed) + if (e[k]! > 0) Expanded(flex: (e[k]! / total * 1000).round(), child: Container(color: macroColors[k])), + ]); + } + Widget _meal(String m, List es) { final t = totals(es); // a long-pressed food can be dropped on another meal's card (db.move: only the meal changes) diff --git a/dashboard/plugins/food/static/food.css b/dashboard/plugins/food/static/food.css index 51f7089..d4b4750 100644 --- a/dashboard/plugins/food/static/food.css +++ b/dashboard/plugins/food/static/food.css @@ -75,8 +75,10 @@ a.fd-wd:hover { background: #1d222d; } .fd-wd.future { opacity: .4; } .fd-wn { font-size: 13px; color: var(--muted); white-space: nowrap; } .fd-wb { position: relative; width: 14px; height: 40px; border-radius: 4px; background: #1b1f29; overflow: hidden; } -.fd-wb s { position: absolute; left: 0; right: 0; bottom: 0; max-height: 100%; background: var(--good); opacity: .85; } -.fd-wd.over .fd-wb s { background: var(--bad); } +.fd-wb s { position: absolute; left: 0; right: 0; bottom: 0; max-height: 100%; display: flex; flex-direction: column-reverse; opacity: .85; } +.fd-wb i { display: block; flex: none; } /* protein / carbs / fat by their share of the energy, bottom up (views._macro_segs) */ +.fd-wb i.protein { background: var(--pr); } .fd-wb i.carbs { background: var(--cb); } .fd-wb i.fat { background: var(--ft); } .fd-wb i.rest { background: var(--rest); } +.fd-wd.over .fd-wk { color: var(--bad); font-weight: 700; } .fd-wd.sel .fd-wb s { opacity: 1; } .fd-wk { font-size: 12px; color: var(--muted); min-height: 1.2em; } .fd-wsum { display: flex; flex-direction: column; justify-content: center; align-items: flex-end; text-align: right; padding-right: 6px; color: var(--muted); font-size: 13px; } diff --git a/dashboard/plugins/food/templates/food/day.html b/dashboard/plugins/food/templates/food/day.html index 3aa4c9c..70db747 100644 --- a/dashboard/plugins/food/templates/food/day.html +++ b/dashboard/plugins/food/templates/food/day.html @@ -19,9 +19,9 @@