From 06c51bb715252dbfb2904295bb5b20dd31175f37 Mon Sep 17 00:00:00 2001 From: Alexander Heldt Date: Sun, 21 Jun 2026 17:51:33 +0000 Subject: [PATCH] Make y-axis of sleep graph more granular --- src/app.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/app.js b/src/app.js index fbe7d4c..2e0502f 100644 --- a/src/app.js +++ b/src/app.js @@ -684,6 +684,14 @@ return { yMax: m, steps: 5 }; } + // Sleep-specific axis: always 2-hour granularity, capped at 24h/day, + // for a more readable picture of typical 10–18 h puppy sleep. + function niceAxisSleepHours(rawMax) { + if (!(rawMax > 0)) return { yMax: 2, steps: 2 }; + const m = Math.min(24, Math.max(2, Math.ceil(rawMax / 2) * 2)); + return { yMax: m, steps: m / 2 }; + } + function escapeText(s) { return String(s).replace(/[&<>"']/g, c => ( { "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }[c] @@ -710,7 +718,7 @@ const innerH = H - MT - MB; const rawMax = Math.max(...days.map(d => d.sleepHours)); - const { yMax, steps: ySteps } = niceAxis(rawMax); + const { yMax, steps: ySteps } = niceAxisSleepHours(rawMax); const gap = 6; const barW = (innerW - (days.length - 1) * gap) / days.length;