feat(fitness/stats): 4 cm minimum y-axis range on body-part history charts

Body-measurement variation of <4 cm used to stretch the full chart
height, making normal weekly noise look dramatic. Now the y-axis
enforces a 4 cm floor centered on the data's midpoint; wider swings
render at their actual range as before.

- FitnessChart: new optional `yMin` / `yMax` props mapped to Chart.js
  `suggestedMin` / `suggestedMax` — soft bounds, so data that exceeds
  them still widens the axis.
- `/fitness/stats/history/[part]`: computes min/max across available
  values (both sides if paired), enforces the 4 cm floor, passes to
  FitnessChart. Tick distance stays on Chart.js auto — small ranges
  get 0.5 cm ticks, wider ones scale up naturally.
This commit is contained in:
2026-04-23 14:21:47 +02:00
parent 9a15779a44
commit 5638913b1d
4 changed files with 27 additions and 5 deletions
@@ -11,10 +11,12 @@
* height?: string,
* yUnit?: string,
* goalLine?: number,
* tooltipFormatter?: (value: number, datasetIndex: number, dataIndex: number, label: string) => string
* tooltipFormatter?: (value: number, datasetIndex: number, dataIndex: number, label: string) => string,
* yMin?: number,
* yMax?: number
* }}
*/
let { type = 'line', data, title = '', height = '250px', yUnit = '', goalLine = undefined, tooltipFormatter = undefined } = $props();
let { type = 'line', data, title = '', height = '250px', yUnit = '', goalLine = undefined, tooltipFormatter = undefined, yMin = undefined, yMax = undefined } = $props();
/** @type {HTMLCanvasElement | undefined} */
let canvas = $state(undefined);
@@ -125,6 +127,8 @@
},
y: {
beginAtZero: type === 'bar',
suggestedMin: yMin,
suggestedMax: yMax,
grid: { color: gridColor },
border: { display: false },
ticks: {