fitness: use time-scale x-axis for weight chart to handle date gaps
All checks were successful
CI / update (push) Successful in 2m23s
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:
@@ -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!);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user