fitness: use time-scale x-axis for weight chart to handle date gaps
All checks were successful
CI / update (push) Successful in 2m23s

Weight chart now spaces data points proportionally to actual dates
instead of evenly. Days without a weight log no longer compress adjacent
points together. Uses Chart.js time scale with chartjs-adapter-date-fns.
This commit is contained in:
2026-03-30 08:59:59 +02:00
parent 5bed3f3781
commit 27a29b6f69
5 changed files with 48 additions and 7 deletions

View File

@@ -155,17 +155,19 @@ export const GET: RequestHandler = async ({ locals }) => {
// Build chart-ready weight data with SMA ± 1 std dev confidence band
const weightChart: {
labels: string[];
dates: string[];
data: number[];
sma: (number | null)[];
upper: (number | null)[];
lower: (number | null)[];
} = { labels: [], data: [], sma: [], upper: [], lower: [] };
} = { labels: [], dates: [], data: [], sma: [], upper: [], lower: [] };
const weights: number[] = [];
for (const m of weightMeasurements) {
const d = new Date(m.date);
weightChart.labels.push(
d.toLocaleDateString('en', { month: 'short', day: 'numeric' })
);
weightChart.dates.push(d.toISOString());
weightChart.data.push(m.weight!);
weights.push(m.weight!);
}