diff --git a/app/src/pages/profile/ProfileBodyParameters.tsx b/app/src/pages/profile/ProfileBodyParameters.tsx index 05604f4..8254c5c 100644 --- a/app/src/pages/profile/ProfileBodyParameters.tsx +++ b/app/src/pages/profile/ProfileBodyParameters.tsx @@ -1,4 +1,4 @@ -import { useMemo, useRef, useState } from 'react'; +import { useMemo, useRef, useState, type ReactNode } from 'react'; import { Plus, Ruler, Scale, Trash2, type LucideIcon } from 'lucide-react'; import { addCircumference, @@ -8,6 +8,8 @@ import { useBodyParameters, } from '../../api/queries'; import { + Area, + AreaChart, LineChart, Line, XAxis, @@ -51,6 +53,26 @@ const TOOLTIP_STYLE = { color: 'var(--text)', }; +/* Wykresy: oś bez linii i kresek, drobny dimowany tick — tło siatki tylko poziome. */ +const AXIS_TICK = { fill: 'var(--text-dim)', fontSize: 12 }; +const CHART_MARGIN = { top: 8, right: 8, left: 0, bottom: 0 }; + +/* Kolor linii wg jednostki: waga = accent, obwody = info. */ +const unitStroke = (unit: PartGroup['unit']) => (unit === 'kg' ? 'var(--accent)' : 'var(--info)'); +/* Tooltip: wartość z jednostką, nazwa serii bez zmian (formatter zwraca parę [wartość, nazwa]). */ +const tooltipUnit = + (unit: PartGroup['unit']) => + (value: ReactNode, name: ReactNode): [ReactNode, ReactNode] => [`${value} ${unit}`, name]; + +/* Punkty pomiarowe: pusty środek (karta pod spodem), ring w kolorze linii. */ +const lineDot = (stroke: string) => ({ r: 3, strokeWidth: 2, fill: 'var(--bg-card)', stroke }); +const lineActiveDot = (stroke: string) => ({ + r: 5, + strokeWidth: 2, + fill: 'var(--bg-card)', + stroke, +}); + interface CircGroup { part: string; series: CircumferenceSeries[]; @@ -130,11 +152,20 @@ function groupDelta(g: PartGroup): { text: string; className: string } | null { return { text: `${signed(d)} vs poprzedni`, className: deltaClass(d) }; } +/** Etykieta osi X: `17.10`; gdy historia przekracza rok — `17.10.26`. */ +function axisDateLabel(iso: string, withYear: boolean): string { + return new Date(iso).toLocaleDateString('pl-PL', { + day: '2-digit', + month: '2-digit', + ...(withYear ? { year: '2-digit' } : {}), + }); +} + /** * Wspólna oś dat dla serii: `[{ date, lewy, prawy }]` (brak pomiaru = null). * Jednostronna grupa → kolumna wg bieżącej strony (osie nazywane po stronie). */ -function sideSeriesData(points: GroupPoint[], sides: Side[]) { +function sideSeriesData(points: GroupPoint[], sides: Side[], withYear: boolean) { const col = (side: Side) => (side === 'left' ? 'lewy' : 'prawy'); const byDate = new Map>(); for (const p of points) { @@ -147,7 +178,7 @@ function sideSeriesData(points: GroupPoint[], sides: Side[]) { return [...byDate.entries()] .sort((a, b) => a[0].localeCompare(b[0])) .map(([date, row]) => ({ - date: new Date(date).toLocaleDateString('pl-PL', { day: '2-digit', month: '2-digit' }), + date: axisDateLabel(date, withYear), ...row, })); } @@ -213,11 +244,16 @@ function MeasurementPanel({ }) { const latest = group.points[group.points.length - 1]; const sided = group.sided && group.sidesPresent.length > 0; + // historia przekracza rok → oś X z rokiem (również przy przerwie >12 mies. w jednym roku) + const withYear = + new Date(group.points[group.points.length - 1].date).getTime() - + new Date(group.points[0].date).getTime() > + 300 * 86_400_000; const singleData = group.points.map((p) => ({ - date: new Date(p.date).toLocaleDateString('pl-PL', { day: '2-digit', month: '2-digit' }), + date: axisDateLabel(p.date, withYear), value: p.value, })); - const sidedData = sided ? sideSeriesData(group.points, group.sidesPresent) : []; + const sidedData = sided ? sideSeriesData(group.points, group.sidesPresent, withYear) : []; const chartReady = sided ? sidedData.length >= 2 : group.points.length >= 2; return ( @@ -245,11 +281,25 @@ function MeasurementPanel({ {chartReady ? ( {sided ? ( - - - - - + + + + + {group.sidesPresent.map((side) => ( ))} ) : ( - - - - - - - + (() => { + const stroke = unitStroke(group.unit); + const areaId = `bp-area-${encodeURIComponent(group.part)}`; + return ( + + + + + + + + + + + + + + ); + })() )} ) : (