Profil: wykres obwodow - obie strony z tego samego dnia w jednej kategorii osi
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { useMemo, useRef, useState, type ReactNode } from 'react';
|
||||
import { useMemo, useRef, useState, type ReactNode } from 'react';
|
||||
import {
|
||||
Plus,
|
||||
Ruler,
|
||||
@@ -207,17 +207,39 @@ function axisDateLabel(iso: string, withYear: boolean): string {
|
||||
});
|
||||
}
|
||||
|
||||
/** Klucz dnia kalendarzowego (lokalnego) — jeden dzień to jedna kategoria osi X. */
|
||||
function dayKey(iso: string): string {
|
||||
const d = new Date(iso);
|
||||
return `${d.getFullYear()}-${d.getMonth()}-${d.getDate()}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dane wykresu: kategorie osi = numery porządkowe pomiarów (unikalne i równe
|
||||
* odległości), więc dwa pomiary z tego samego dnia nie scalają się w jeden
|
||||
* punkt — wykres rysuje się zawsze, etykiety osi pokazują daty (tickFormatter).
|
||||
* 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ść).
|
||||
*/
|
||||
function chartData(points: GroupPoint[]) {
|
||||
return points.map((p, idx) => ({
|
||||
idx: String(idx),
|
||||
value: p.value,
|
||||
lewy: p.side === 'left' ? p.value : null,
|
||||
prawy: p.side === 'right' ? p.value : null,
|
||||
interface DayRow {
|
||||
day: string;
|
||||
date: string;
|
||||
value: number;
|
||||
sides: Partial<Record<Side, number>>;
|
||||
}
|
||||
const rows = new Map<string, DayRow>();
|
||||
for (const p of points) {
|
||||
const day = dayKey(p.date);
|
||||
const row = rows.get(day) ?? { day, date: p.date, value: p.value, sides: {} };
|
||||
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,
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -245,10 +267,10 @@ function MeasurementPanel({
|
||||
new Date(group.points[0].date).getTime() >
|
||||
300 * 86_400_000;
|
||||
const data = chartData(group.points);
|
||||
// kategorie osi = numery porządkowe → etykiety i tooltip tłumaczone na daty
|
||||
// wiersze po dniach → etykiety osi i tooltip tłumaczone z reprezentacyjnej daty dnia
|
||||
const labelAt = (v: string | number) => {
|
||||
const p = group.points[Number(v)];
|
||||
return p ? axisDateLabel(p.date, withYear) : '';
|
||||
const row = data.find((r) => r.day === String(v));
|
||||
return row ? axisDateLabel(row.date, withYear) : '';
|
||||
};
|
||||
const chartReady = group.points.length >= 2;
|
||||
// osobna strona: przy >1 strony wynik per strona, poza tym zmiana od pierwszego pomiaru
|
||||
@@ -300,7 +322,7 @@ function MeasurementPanel({
|
||||
<LineChart data={data} margin={CHART_MARGIN}>
|
||||
<CartesianGrid stroke="var(--border)" vertical={false} />
|
||||
<XAxis
|
||||
dataKey="idx"
|
||||
dataKey="day"
|
||||
tickFormatter={labelAt}
|
||||
tickLine={false}
|
||||
axisLine={false}
|
||||
@@ -349,7 +371,7 @@ function MeasurementPanel({
|
||||
</defs>
|
||||
<CartesianGrid stroke="var(--border)" vertical={false} />
|
||||
<XAxis
|
||||
dataKey="idx"
|
||||
dataKey="day"
|
||||
tickFormatter={labelAt}
|
||||
tickLine={false}
|
||||
axisLine={false}
|
||||
|
||||
Reference in New Issue
Block a user