Profil: zakladki bez wartosci, strony mierzone jako dwa niezalezne wykresy
This commit is contained in:
@@ -18,8 +18,6 @@ import {
|
||||
import {
|
||||
Area,
|
||||
AreaChart,
|
||||
LineChart,
|
||||
Line,
|
||||
XAxis,
|
||||
YAxis,
|
||||
Tooltip,
|
||||
@@ -214,37 +212,92 @@ function dayKey(iso: string): string {
|
||||
}
|
||||
|
||||
/**
|
||||
* Dane wykresu: wiersze po dniach kalendarzowych — obie strony z tego samego
|
||||
* dnia wpasowują się w tę samą kategorię osi (linie się zazębiają), a ten sam
|
||||
* dzień mierzony dwa razy daje jeden punkt (ostatni wartość).
|
||||
* Dane wykresu: wiersze po dniach kalendarzowych — ten sam dzień mierzony
|
||||
* dwa razy (lub z obu stron) daje jeden punkt z osią X (ostatnia wartość dnia).
|
||||
*/
|
||||
function chartData(points: GroupPoint[]) {
|
||||
interface DayRow {
|
||||
day: string;
|
||||
date: string;
|
||||
value: number;
|
||||
sides: Partial<Record<Side, number>>;
|
||||
}
|
||||
const rows = new Map<string, DayRow>();
|
||||
const rows = new Map<string, { day: string; date: string; value: number }>();
|
||||
for (const p of points) {
|
||||
const day = dayKey(p.date);
|
||||
const row = rows.get(day) ?? { day, date: p.date, value: p.value, sides: {} };
|
||||
const row = rows.get(day) ?? { day, date: p.date, value: p.value };
|
||||
row.date = p.date;
|
||||
row.value = p.value;
|
||||
if (p.side) row.sides[p.side] = p.value;
|
||||
rows.set(day, row);
|
||||
}
|
||||
return [...rows.values()].map((r) => ({
|
||||
day: r.day,
|
||||
date: r.date,
|
||||
value: r.value,
|
||||
lewy: r.sides.left ?? null,
|
||||
prawy: r.sides.right ?? null,
|
||||
}));
|
||||
return [...rows.values()];
|
||||
}
|
||||
|
||||
const SIDE_STROKE: Record<Side, string> = { left: 'var(--info)', right: 'var(--accent)' };
|
||||
|
||||
/* Pojedyncza seria: obszar z gradientem, oś X po dniach (pomiary z dnia w jednym punkcie). */
|
||||
function PartAreaChart({
|
||||
name,
|
||||
points,
|
||||
stroke,
|
||||
unit,
|
||||
withYear,
|
||||
height,
|
||||
}: {
|
||||
name: string;
|
||||
points: GroupPoint[];
|
||||
stroke: string;
|
||||
unit: 'kg' | 'cm';
|
||||
withYear: boolean;
|
||||
height: number;
|
||||
}) {
|
||||
const rows = chartData(points);
|
||||
const labelAt = (v: string | number) => {
|
||||
const row = rows.find((r) => r.day === String(v));
|
||||
return row ? axisDateLabel(row.date, withYear) : '';
|
||||
};
|
||||
const areaId = `bp-area-${encodeURIComponent(name)}`;
|
||||
return (
|
||||
<ResponsiveContainer width="100%" height={height}>
|
||||
<AreaChart data={rows} margin={CHART_MARGIN}>
|
||||
<defs>
|
||||
<linearGradient id={areaId} x1="0" y1="0" x2="0" y2="1">
|
||||
<stop offset="0%" stopColor={stroke} stopOpacity={0.25} />
|
||||
<stop offset="100%" stopColor={stroke} stopOpacity={0} />
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<CartesianGrid stroke="var(--border)" vertical={false} />
|
||||
<XAxis
|
||||
dataKey="day"
|
||||
tickFormatter={labelAt}
|
||||
tickLine={false}
|
||||
axisLine={false}
|
||||
tickMargin={10}
|
||||
minTickGap={32}
|
||||
tick={AXIS_TICK}
|
||||
/>
|
||||
<YAxis
|
||||
width={44}
|
||||
tickLine={false}
|
||||
axisLine={false}
|
||||
tickMargin={8}
|
||||
domain={['auto', 'auto']}
|
||||
tick={AXIS_TICK}
|
||||
/>
|
||||
<Tooltip
|
||||
contentStyle={TOOLTIP_STYLE}
|
||||
formatter={tooltipUnit(unit)}
|
||||
labelFormatter={labelAt}
|
||||
/>
|
||||
<Area
|
||||
type="monotone"
|
||||
dataKey="value"
|
||||
name={name}
|
||||
stroke={stroke}
|
||||
strokeWidth={2}
|
||||
fill={`url(#${areaId})`}
|
||||
dot={lineDot(stroke)}
|
||||
activeDot={lineActiveDot(stroke)}
|
||||
/>
|
||||
</AreaChart>
|
||||
</ResponsiveContainer>
|
||||
);
|
||||
}
|
||||
|
||||
/* Panel wybranej części: nagłówek (nazwa + ostatni pomiar) + wykres pełnej historii + lista pomiarów. */
|
||||
function MeasurementPanel({
|
||||
group,
|
||||
@@ -266,13 +319,32 @@ function MeasurementPanel({
|
||||
new Date(group.points[group.points.length - 1].date).getTime() -
|
||||
new Date(group.points[0].date).getTime() >
|
||||
300 * 86_400_000;
|
||||
const data = chartData(group.points);
|
||||
// wiersze po dniach → etykiety osi i tooltip tłumaczone z reprezentacyjnej daty dnia
|
||||
const labelAt = (v: string | number) => {
|
||||
const row = data.find((r) => r.day === String(v));
|
||||
return row ? axisDateLabel(row.date, withYear) : '';
|
||||
};
|
||||
const chartReady = group.points.length >= 2;
|
||||
// strony osobno (lewa zawsze pierwsza) — dwa niezależne wykresy jeden pod drugim
|
||||
const seriesList: {
|
||||
key: string;
|
||||
caption: string;
|
||||
name: string;
|
||||
stroke: string;
|
||||
points: GroupPoint[];
|
||||
}[] = sided
|
||||
? (['left', 'right'] as Side[])
|
||||
.filter((s) => group.sidesPresent.includes(s))
|
||||
.map((s) => ({
|
||||
key: s,
|
||||
caption: sideLabelsFor(group.part)[s],
|
||||
name: sideLabelsFor(group.part)[s].toLowerCase(),
|
||||
stroke: SIDE_STROKE[s],
|
||||
points: group.points.filter((p) => p.side === s),
|
||||
}))
|
||||
: [
|
||||
{
|
||||
key: 'all',
|
||||
caption: '',
|
||||
name: group.part,
|
||||
stroke: unitStroke(group.unit),
|
||||
points: group.points,
|
||||
},
|
||||
];
|
||||
// osobna strona: przy >1 strony wynik per strona, poza tym zmiana od pierwszego pomiaru
|
||||
const deltas = sideDeltas(group);
|
||||
const prog = progressOf(group);
|
||||
@@ -316,113 +388,31 @@ function MeasurementPanel({
|
||||
sub={sub}
|
||||
/>
|
||||
|
||||
{chartReady ? (
|
||||
<ResponsiveContainer width="100%" height={220}>
|
||||
{sided ? (
|
||||
<LineChart data={data} margin={CHART_MARGIN}>
|
||||
<CartesianGrid stroke="var(--border)" vertical={false} />
|
||||
<XAxis
|
||||
dataKey="day"
|
||||
tickFormatter={labelAt}
|
||||
tickLine={false}
|
||||
axisLine={false}
|
||||
tickMargin={10}
|
||||
minTickGap={32}
|
||||
tick={AXIS_TICK}
|
||||
/>
|
||||
<YAxis
|
||||
width={44}
|
||||
tickLine={false}
|
||||
axisLine={false}
|
||||
tickMargin={8}
|
||||
domain={['auto', 'auto']}
|
||||
tick={AXIS_TICK}
|
||||
/>
|
||||
<Tooltip
|
||||
contentStyle={TOOLTIP_STYLE}
|
||||
formatter={tooltipUnit(group.unit)}
|
||||
labelFormatter={labelAt}
|
||||
/>
|
||||
{group.sidesPresent.map((side) => (
|
||||
<Line
|
||||
key={side}
|
||||
type="monotone"
|
||||
dataKey={side === 'left' ? 'lewy' : 'prawy'}
|
||||
name={SIDE_LABELS[side]}
|
||||
stroke={SIDE_STROKE[side]}
|
||||
strokeWidth={2}
|
||||
dot={lineDot(SIDE_STROKE[side])}
|
||||
activeDot={lineActiveDot(SIDE_STROKE[side])}
|
||||
connectNulls
|
||||
/>
|
||||
))}
|
||||
</LineChart>
|
||||
) : (
|
||||
(() => {
|
||||
const stroke = unitStroke(group.unit);
|
||||
const areaId = `bp-area-${encodeURIComponent(group.part)}`;
|
||||
return (
|
||||
<AreaChart data={data} margin={CHART_MARGIN}>
|
||||
<defs>
|
||||
<linearGradient id={areaId} x1="0" y1="0" x2="0" y2="1">
|
||||
<stop offset="0%" stopColor={stroke} stopOpacity={0.25} />
|
||||
<stop offset="100%" stopColor={stroke} stopOpacity={0} />
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<CartesianGrid stroke="var(--border)" vertical={false} />
|
||||
<XAxis
|
||||
dataKey="day"
|
||||
tickFormatter={labelAt}
|
||||
tickLine={false}
|
||||
axisLine={false}
|
||||
tickMargin={10}
|
||||
minTickGap={32}
|
||||
tick={AXIS_TICK}
|
||||
/>
|
||||
<YAxis
|
||||
width={44}
|
||||
tickLine={false}
|
||||
axisLine={false}
|
||||
tickMargin={8}
|
||||
domain={['auto', 'auto']}
|
||||
tick={AXIS_TICK}
|
||||
/>
|
||||
<Tooltip
|
||||
contentStyle={TOOLTIP_STYLE}
|
||||
formatter={tooltipUnit(group.unit)}
|
||||
labelFormatter={labelAt}
|
||||
/>
|
||||
<Area
|
||||
type="monotone"
|
||||
dataKey="value"
|
||||
name={group.part}
|
||||
stroke={stroke}
|
||||
strokeWidth={2}
|
||||
fill={`url(#${areaId})`}
|
||||
dot={lineDot(stroke)}
|
||||
activeDot={lineActiveDot(stroke)}
|
||||
/>
|
||||
</AreaChart>
|
||||
);
|
||||
})()
|
||||
)}
|
||||
</ResponsiveContainer>
|
||||
) : (
|
||||
<p className="text-dim">Za mało danych na wykres (min. 2 pomiary).</p>
|
||||
)}
|
||||
{sided && (
|
||||
<div className="mt-2 flex flex-wrap gap-4 text-[0.875rem] text-dim">
|
||||
{group.sidesPresent.map((side) => (
|
||||
<span key={side} className="flex items-center gap-1.5">
|
||||
{seriesList.map((s, i) => (
|
||||
<div key={s.key} className={i > 0 ? 'mt-5' : undefined}>
|
||||
{sided && (
|
||||
<div className="mb-1 flex items-center gap-1.5 text-[0.875rem] text-dim">
|
||||
<span
|
||||
className="inline-block h-0.5 w-3 rounded-md"
|
||||
style={{ background: SIDE_STROKE[side] }}
|
||||
style={{ background: s.stroke }}
|
||||
/>
|
||||
{SIDE_LABELS[side]}
|
||||
</span>
|
||||
))}
|
||||
{s.caption}
|
||||
</div>
|
||||
)}
|
||||
{s.points.length >= 2 ? (
|
||||
<PartAreaChart
|
||||
name={s.name}
|
||||
points={s.points}
|
||||
stroke={s.stroke}
|
||||
unit={group.unit}
|
||||
withYear={withYear}
|
||||
height={sided ? 150 : 220}
|
||||
/>
|
||||
) : (
|
||||
<p className="text-dim">Za mało danych na wykres (min. 2 pomiary).</p>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
))}
|
||||
|
||||
{/* lista: najnowsze 3 + „Pokaż więcej" (kolejne 3); pełna historia w wykresie */}
|
||||
<div>
|
||||
@@ -775,20 +765,9 @@ export default function ProfileBodyParameters() {
|
||||
/>
|
||||
) : (
|
||||
<>
|
||||
{/* zakładki części: skrót + najnowsza wartość; strzałki, gdy się nie mieszczą */}
|
||||
{/* zakładki części: skrót nazwy; szczegóły (wartości, postęp) w panelu poniżej */}
|
||||
<Tabs
|
||||
tabs={groups.map((g) => {
|
||||
const latest = g.points[g.points.length - 1];
|
||||
return {
|
||||
id: g.part,
|
||||
label: (
|
||||
<span className="flex items-baseline gap-1.5">
|
||||
{shortPartName(g.part)}
|
||||
<span className="tabular-nums opacity-70">{fmtVal(latest.value)}</span>
|
||||
</span>
|
||||
),
|
||||
};
|
||||
})}
|
||||
tabs={groups.map((g) => ({ id: g.part, label: shortPartName(g.part) }))}
|
||||
active={active.part}
|
||||
onChange={(id) => setSelected(id)}
|
||||
/>
|
||||
|
||||
@@ -124,9 +124,9 @@ async function loginToProfile(user: userEvent.User) {
|
||||
).toBeInTheDocument();
|
||||
}
|
||||
|
||||
/** Klik w zakładkę części ciała (skrót nazwy + najnowsza wartość). */
|
||||
/** Klik w zakładkę części ciała (sama nazwa — wartości są w panelu). */
|
||||
function selectPart(part: string) {
|
||||
return screen.getByRole('button', { name: new RegExp(`^${part} `) });
|
||||
return screen.getByRole('button', { name: new RegExp(`^${part}$`) });
|
||||
}
|
||||
|
||||
function renderApp() {
|
||||
@@ -223,12 +223,12 @@ describe('Profile — body parameter removal', () => {
|
||||
expect(screen.getAllByText('80 cm').length).toBe(2); // nagłówek panelu + wiersz
|
||||
});
|
||||
|
||||
it('rysuje wykres przy pomiarach z jednego dnia i asymetrii stron', async () => {
|
||||
it('rozbija strony na osobne wykresy (lewy pierwszy), bez podwójnych dat na osi', async () => {
|
||||
mockApi([
|
||||
// dwa prawe i jedno lewe z TEJ SAMEJ daty — dawniej oś X scalała się
|
||||
// w jedną kategorię i wykres w ogóle się nie rysował
|
||||
// dwa prawe i jedno lewe z TEJ SAMEJ daty — strony rysowane osobno,
|
||||
// dni łączone w pojedyncze kategorie osi (bez dublujących się etykiet)
|
||||
{ id: 'c-1', name: 'Udo prawy', value: 55, date: '2026-08-10T08:00:00.000Z' },
|
||||
{ id: 'c-2', name: 'Udo prawy', value: 56, date: '2026-08-10T19:00:00.000Z' },
|
||||
{ id: 'c-2', name: 'Udo prawy', value: 56, date: '2026-08-12T19:00:00.000Z' },
|
||||
{ id: 'c-3', name: 'Udo lewy', value: 54, date: '2026-08-10T12:00:00.000Z' },
|
||||
]);
|
||||
const user = userEvent.setup();
|
||||
@@ -238,7 +238,12 @@ describe('Profile — body parameter removal', () => {
|
||||
await user.click(selectPart('Udo'));
|
||||
// nagłówek panelu (ostatni 56) + wiersz listy
|
||||
expect((await screen.findAllByText('56 cm')).length).toBeGreaterThanOrEqual(2);
|
||||
expect(screen.queryByText(/Za mało danych na wykres/)).not.toBeInTheDocument();
|
||||
// dwa podpisyane wykresy: lewy zawsze przed prawym
|
||||
const lewy = screen.getByText('Lewe');
|
||||
const prawy = screen.getByText('Prawe');
|
||||
expect(lewy.compareDocumentPosition(prawy) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
|
||||
// strona z jednym pomiarem uczciwie sygnalizuje za mało danych
|
||||
expect(screen.getByText(/Za mało danych na wykres/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('opens the add-measurement modal from the context menu', async () => {
|
||||
|
||||
@@ -102,7 +102,7 @@ test('mobile: parametry ciała — zakładki części, postęp wagi i dodanie po
|
||||
await expect(page.getByRole('heading', { name: 'Parametry ciała', level: 1 })).toBeVisible();
|
||||
|
||||
// zakładka „Waga” wybrana domyślnie: panel z ostatnim pomiarem + postęp (spadek)
|
||||
await expect(page.getByRole('button', { name: /^Waga 81,8/ })).toBeVisible();
|
||||
await expect(page.getByRole('button', { name: 'Waga', exact: true })).toBeVisible();
|
||||
await expect(page.getByText('−0,7 kg od pierwszego')).toBeVisible();
|
||||
await expect(page.getByText('81.8 kg').first()).toBeVisible();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user