fix(diagrams): cigarettes per day (last 30 days) chart is broken #
Area: Data & Diagrams · Cigarettes per day · pages/diagrams.vue
Type: bug
Priority: p0
Summary #
The Cigarettes per day section on the data & diagrams page (/diagrams) is broken (flat/empty bars, wrong heights, or JS error on empty data). Fix rendering so 30-day bars are proportionally visible.
Current behavior #
pages/diagrams.vue:8-22:
const cigsPerDay = computed(() => heatData.value?.counts.map(Number) || [])
const last30 = computed(() => cigsPerDay.value.slice(-30))
const maxCigsPerDay = computed(() => {
if (!last30.value?.length) return 1
return Math.max(...last30.value.map(c => Math.max(1, c)))
})
Template pages/diagrams.vue:93-110:
<div class="flex items-end gap-[2px] h-40">
<div v-for="(count,i) in last30" class="flex flex-col items-center flex-1">
<div class="chart-bar" :style="{ height: Math.max(2, (count/maxCigsPerDay)*100)+'%' }"></div>
</div>
</div>
Likely causes:
maxCigsPerDayis forced to≥1even when all counts are0→ every bar stuck at2%min, chart looks flat/broken.heatDataisnullon first load →last30empty → no empty-state, just empty flex row.flex-1bars inside shrinking container may have no width if parent has no min-width.- No graceful empty state (should show
t('diagrams.no_data')).
Also note server/utils/stats/heatmap.ts:buildHeatmap returns counts: number[84] — last30 correctly slices but chart doesn't handle the all-zero case distinct from loading.
Expected behavior #
- Bars proportionally fill
h-40withitems-end,gap-[2px]working on mobile/desktop. - Zero-data case: show
t('diagrams.no_data')(already has<p v-else class="empty-state">) — ensurev-if="last30?.length"correctly branches (checklast30is always an array, empty array is truthy — may needlast30.length > 0 && max>0). - When data exists but max is
0(new user, 0 cigs in last 30d), either show empty-state or show flat zero-height bars (not 2% fake height). Prefer: ifmax===0or all zeros → show empty-state. - If data exists,
maxCigsPerDay = Math.max(...last30)(withoutMath.max(1,c)per element) and clamp denominator to≥1once. Useheight: count===0 ? '2px' : (count/max)*100+'%'or similar so zeros are visible but distinguishable. - Keep
role="img"+aria-labelper bar andsr-onlytable for a11y. - No console errors on initial load (
heatData==null).
Files to touch #
pages/diagrams.vue:8-22—maxCigsPerDay+ empty handlingpages/diagrams.vue:93-110— bar height/style,v-ifconditionassets/css/marathon-components.css:.chart-bar— no change expected (stillbg-primary)
Acceptance criteria #
How to test #
- New user (0 cigs) → open
/diagrams→ should see empty-state, not flat bars. - Seed 30 days with varied counts (e.g. via
scripts/screenshot-seed.tsor logging cigs across days) → verify bar heights scale. - Check devtools console → no errors on hard reload.