diff --git a/src/app.js b/src/app.js index 3a2e69a..a1964f1 100644 --- a/src/app.js +++ b/src/app.js @@ -2068,9 +2068,64 @@ } }); + // The same fit the food chart draws, for "is he sleeping less as he + // grows?". A day with no sleep at all is left out as well as today and the + // marked ones: a puppy never sleeps 0h, so it is a day nobody logged, and + // fitting it as a real zero would drag the line through the floor. + const trend = dailyTrend(days, d => d.sleepHours > 0 ? d.sleepHours : null); + if (trend) { + const cx = (i) => ML + i * (barW + gap) + barW / 2; + const cy = (h) => MT + innerH * (1 - Math.min(Math.max(h, 0), yMax) / yMax); + parts.push( + `` + ); + } + renderSleepTrendNote(days, trend); + setChartSVG(svg, parts); } + // The food trend's rules in hours: figures rounded to the half hour (the + // fitted ends are the line's guess, not a reading), and no direction claimed + // unless the move outruns the day-to-day scatter and is worth acting on. + function sleepTrendSentence(trend, windowDays) { + const window = `the last ${windowDays} days`; + if (!trend) { + return `Not enough complete days in ${window} to draw a trend — it needs four, and today doesn't count until it's over.`; + } + const half = (v) => Math.round(Math.max(0, v) * 2) / 2; + const hours = (v) => `${half(v)}h`; + const slight = Math.abs(trend.change) < 0.25 || Math.abs(trend.change) < trend.mean * 0.05; + if (!trend.clear || slight) { + return `Over ${window}, daily sleep is roughly steady, averaging about ${hours(trend.mean)} a day` + + ` — day-to-day variation is larger than any trend.`; + } + // From the rounded ends, so the two figures on screen subtract to the one quoted. + const from = half(trend.at(trend.first)); + const to = half(trend.at(trend.last)); + if (from === to) { + return `Over ${window}, daily sleep is roughly steady at about ${hours(from)} a day.`; + } + return `Over ${window}, daily sleep is ${to > from ? "up" : "down"} about ${hours(Math.abs(to - from))}` + + ` — from roughly ${hours(from)} a day to ${hours(to)}.`; + } + + function renderSleepTrendNote(days, trend) { + const note = document.getElementById("sleep-note"); + if (!note) return; + const lines = [sleepTrendSentence(trend, chartDays())]; + // Days before logging began (or a gap in it) read as empty bars; say they + // were skipped so the line isn't taken to have ignored real data. + const blank = days.filter((d, i) => i < days.length - 1 && !d.excluded && !(d.sleepHours > 0)).length; + if (blank > 0) { + lines.push(`${blank} ${blank === 1 ? "day" : "days"} with no sleep logged ${blank === 1 ? "is" : "are"} left out.`); + } + note.textContent = lines.join(" "); + note.hidden = false; + } + function drawCountsChart(days) { const svg = document.getElementById("chart-counts"); const W = 320, H = 180; @@ -2150,14 +2205,16 @@ // up over the day — a moving line that reflects the clock rather than the // puppy. The line is drawn only across the days it was fitted on, so it never // implies it knows about the ones it skipped. - // valueOf picks which figure to fit: the day total by default, or one - // kind's share of it when the bars are split. - function foodTrend(days, valueOf = (d) => d.grams) { + // valueOf picks which figure to fit: one food kind's grams, or the day's + // sleep hours. It may return null to leave a day out of the fit altogether. + function dailyTrend(days, valueOf) { const pts = []; days.forEach((d, i) => { if (d.excluded) return; - if (i === days.length - 1) return; // today, still being eaten - pts.push({ x: i, y: valueOf(d) }); + if (i === days.length - 1) return; // today, still in progress + const y = valueOf(d); + if (y == null) return; + pts.push({ x: i, y }); }); // Two points always fit a line perfectly and say nothing; four is the least // that can show a direction rather than a coincidence. @@ -2340,7 +2397,7 @@ of: (d) => d.gramsByKind?.[NO_KIND] || 0, }); } - for (const s of out) s.trend = foodTrend(days, s.of); + for (const s of out) s.trend = dailyTrend(days, s.of); return out; } @@ -2452,7 +2509,7 @@ // One sentence per kind would grow with the list and bury the answer, so // only kinds with something to report get a sentence of their own and the - // rest are folded into a clause. Both rules are foodTrend's, not new ones: + // rest are folded into a clause. Both rules are dailyTrend's, not new ones: // a kind with too few days has no fit, and one whose move is under its own // scatter is not claimed. function foodSeriesSentences(series, windowDays) { diff --git a/src/changelog.json b/src/changelog.json index 72ced14..320ca68 100644 --- a/src/changelog.json +++ b/src/changelog.json @@ -1,4 +1,5 @@ [ + { "date": "2026-09-29", "text": "The Sleep chart on the Sleep tab has a trend line through it, like the Food (grams) chart, so you can see whether he is sleeping less as he grows — the day-to-day bars vary enough to hide a steady change. A line under the chart puts it in figures: “daily sleep is down about 1.5h — from roughly 17h a day to 15.5h”, or, when the days scatter more than they move, that it is roughly steady and what the average is. Today is left out until it's over, as are days marked “not counted” and days with no sleep logged at all, which the sentence mentions so an empty bar isn't mistaken for a night without sleep. It follows the 7 / 14 / 30 day picker like the rest of the charts" }, { "date": "2026-09-29", "text": "The Timing panel no longer counts the night. The gap from each day's last pee, poo or meal to the next morning's first was being measured like any other, so every window held several eight-hour-plus “gaps” that were really just bedtime — the longest figure was a sleep figure and the typical gap was pulled up with it. Only gaps within a single day are measured now, so the bars show how often he needs to go out while he's up and about. The “since the last one” marker is unchanged, so first thing in the morning it still reads as overdue — which, before the first trip out, it is" }, { "date": "2026-09-26", "text": "Tapping the tab you are already on scrolls back to the top of the page, the way it does in most phone apps — handy after scrolling a long way down Habits or the history. Switching to a different tab still leaves you where you were, as before" }, { "date": "2026-09-24", "text": "Kinds of food are now created in one place only — Settings → Food kinds. The Ate dialog no longer has a box for inventing one on the spot; it still lets you pick from the kinds you have, exactly as before. Making them mid-meal put a bit of list-keeping in the middle of logging, where the thing you actually came to do is record that the dog ate, and a kind typed in a hurry is easy to get slightly wrong — nothing stops two near-identical kinds existing, and clearing one up afterwards means relabelling every meal logged under it first" }, diff --git a/src/index.html b/src/index.html index d04b1a5..95526ed 100644 --- a/src/index.html +++ b/src/index.html @@ -301,7 +301,9 @@

Sleep (last 7 days)

Hours per day
- + + +
diff --git a/src/style.css b/src/style.css index b29e23e..8c7fa59 100644 --- a/src/style.css +++ b/src/style.css @@ -1369,6 +1369,15 @@ input.switch:checked::after { transform: translateX(18px); } stroke-linecap: round; fill: none; } +/* The sleep bars are --sleep, so the fit through them takes the ink shade — + darker in light mode, lighter in dark — to stay visible where it crosses one. */ +.chart-svg .sleep-trend { + stroke: var(--sleep-ink); + stroke-width: 2; + stroke-dasharray: 5 3; + stroke-linecap: round; + fill: none; +} .legend .sw.food-sw { background: var(--food-color, var(--muted)); } .kind-field { margin-bottom: 10px; }