Make y-axis of sleep graph more granular
This commit is contained in:
+9
-1
@@ -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 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) {
|
function escapeText(s) {
|
||||||
return String(s).replace(/[&<>"']/g, c => (
|
return String(s).replace(/[&<>"']/g, c => (
|
||||||
{ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }[c]
|
{ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }[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;
|
||||||
|
|||||||
Reference in New Issue
Block a user