Make y-axis of sleep graph more granular

This commit is contained in:
Alexander Heldt
2026-06-21 17:51:33 +00:00
parent d61e88fa29
commit 06c51bb715
+9 -1
View File
@@ -684,6 +684,14 @@
return { yMax: m, steps: 5 }; return { yMax: m, steps: 5 };
} }
// Sleep-specific axis: always 2-hour granularity, capped at 24h/day,
// for a more readable picture of typical 1018 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) { function escapeText(s) {
return String(s).replace(/[&<>"']/g, c => ( return String(s).replace(/[&<>"']/g, c => (
{ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" }[c] { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" }[c]
@@ -710,7 +718,7 @@
const innerH = H - MT - MB; const innerH = H - MT - MB;
const rawMax = Math.max(...days.map(d => d.sleepHours)); 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 gap = 6;
const barW = (innerW - (days.length - 1) * gap) / days.length; const barW = (innerW - (days.length - 1) * gap) / days.length;