feat: enhance body_history_viz widget configuration and validation
- Added new configuration options for the `body_history_viz` widget, including visibility settings for various charts and KPIs. - Implemented default values for the widget's configuration to streamline user experience. - Enhanced validation logic to ensure proper handling of configuration inputs, including error handling for unknown keys and visibility requirements. - Updated tests to cover new configuration scenarios and validation rules for the `body_history_viz` widget. - Bumped application version to reflect these changes.
This commit is contained in:
1 parent
01c0d1745f
commit
20f195aca1
11 files changed
+400
-50
No files matched your search
@@ -1,16 +1,18 @@
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import BodyHistoryVizSection from '../history/BodyHistoryVizSection'
|
||||
import { useProfile } from '../../context/ProfileContext'
|
||||
import { BODY_CHART_DAYS_DEFAULT, normalizeBodyChartDays } from '../../widgetSystem/bodyChartDays'
|
||||
import { normalizeBodyChartDays } from '../../widgetSystem/bodyChartDays'
|
||||
import { normalizeBodyHistoryVizConfig } from '../../widgetSystem/bodyHistoryVizConfig'
|
||||
|
||||
/**
|
||||
* Verlauf → Körper als Dashboard-Widget: GET /charts/body-history-viz (Layer 2b), optional chart_days 7–90.
|
||||
* @param {{ refreshTick?: number, chartDays?: number }} props
|
||||
* Verlauf → Körper als Dashboard-Widget: GET /charts/body-history-viz (Layer 2b), Umfang über Layout-Config.
|
||||
* @param {{ refreshTick?: number, bodyHistoryVizConfig?: Record<string, unknown> }} props
|
||||
*/
|
||||
export default function BodyHistoryVizWidget({ refreshTick = 0, chartDays }) {
|
||||
export default function BodyHistoryVizWidget({ refreshTick = 0, bodyHistoryVizConfig }) {
|
||||
const nav = useNavigate()
|
||||
const { activeProfile } = useProfile()
|
||||
const days = chartDays != null ? normalizeBodyChartDays(chartDays) : BODY_CHART_DAYS_DEFAULT
|
||||
const cfg = normalizeBodyHistoryVizConfig(bodyHistoryVizConfig)
|
||||
const days = normalizeBodyChartDays(cfg.chart_days)
|
||||
|
||||
return (
|
||||
<div className="card section-gap" style={{ marginBottom: 16 }}>
|
||||
@@ -23,7 +25,13 @@ export default function BodyHistoryVizWidget({ refreshTick = 0, chartDays }) {
|
||||
Verlauf →
|
||||
</button>
|
||||
</div>
|
||||
<BodyHistoryVizSection key={`${refreshTick}-${days}`} profile={activeProfile} externalPeriod={days} embedded />
|
||||
<BodyHistoryVizSection
|
||||
key={`${refreshTick}-${days}`}
|
||||
profile={activeProfile}
|
||||
externalPeriod={days}
|
||||
embedded
|
||||
visibility={cfg}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -17,12 +17,25 @@ import 'dayjs/locale/de'
|
||||
import { api } from '../../utils/api'
|
||||
import { getStatusColor } from '../../utils/interpret'
|
||||
import KpiTilesOverview from '../KpiTilesOverview'
|
||||
import {
|
||||
BODY_HISTORY_VIZ_HISTORY_FULL,
|
||||
filterBodyHistoryKpiTiles,
|
||||
} from '../../widgetSystem/bodyHistoryVizConfig'
|
||||
import { EmptySection, NavToCaliper, NavToCircum, PeriodSelector, SectionHeader } from './historyPageChrome'
|
||||
|
||||
dayjs.locale('de')
|
||||
|
||||
const fmtDate = (d) => dayjs(d).format('DD.MM')
|
||||
|
||||
/** Recharts: in schmalen Flex-Spalten sonst Breite 0. */
|
||||
function ChartFrame({ heightPx, children }) {
|
||||
return (
|
||||
<div style={{ width: '100%', minWidth: 0, height: heightPx }} className="body-history-viz__chart-frame">
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function verdictShort(status) {
|
||||
if (status === 'good') return 'Gut'
|
||||
if (status === 'warn') return 'Hinweis'
|
||||
@@ -222,8 +235,15 @@ function BodyGoalsStrip({ grouped }) {
|
||||
* @param {number} [props.externalPeriod] — festes Fenster (Dashboard); sonst interner Zeitraum + PeriodSelector
|
||||
* @param {import('react').ReactNode} [props.footer] — z. B. KI-InsightBox im Verlauf
|
||||
* @param {boolean} [props.embedded] — true im Dashboard-Widget: keine große Section-Überschrift (Karte hat eigenen Titel)
|
||||
* @param {object} [props.visibility] — Sichtbarkeit (Dashboard-Config); fehlt → wie Verlauf (alles an, kpi_detail full)
|
||||
*/
|
||||
export default function BodyHistoryVizSection({ profile, externalPeriod, footer = null, embedded = false }) {
|
||||
export default function BodyHistoryVizSection({ profile, externalPeriod, footer = null, embedded = false, visibility }) {
|
||||
const display = visibility === undefined ? BODY_HISTORY_VIZ_HISTORY_FULL : visibility
|
||||
const chartHMain = embedded ? 176 : 200
|
||||
const chartHSecondary = embedded ? 152 : 170
|
||||
const chartHIndex = embedded ? 160 : 180
|
||||
const chartHFallback = embedded ? 140 : 150
|
||||
|
||||
const [internalPeriod, setInternalPeriod] = useState(90)
|
||||
const period = externalPeriod !== undefined ? externalPeriod : internalPeriod
|
||||
const showPeriodSelector = externalPeriod === undefined
|
||||
@@ -234,6 +254,10 @@ export default function BodyHistoryVizSection({ profile, externalPeriod, footer
|
||||
const [vizError, setVizError] = useState(null)
|
||||
|
||||
useEffect(() => {
|
||||
if (!display.show_goals_strip) {
|
||||
setGroupedGoals({})
|
||||
return undefined
|
||||
}
|
||||
let cancelled = false
|
||||
api.listGoalsGrouped()
|
||||
.then((g) => {
|
||||
@@ -245,7 +269,7 @@ export default function BodyHistoryVizSection({ profile, externalPeriod, footer
|
||||
return () => {
|
||||
cancelled = true
|
||||
}
|
||||
}, [])
|
||||
}, [display.show_goals_strip])
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false
|
||||
@@ -334,6 +358,7 @@ export default function BodyHistoryVizSection({ profile, externalPeriod, footer
|
||||
weightTrendKpi: w?.trend_kpi,
|
||||
goalW,
|
||||
})
|
||||
const kpiTilesShown = display.show_kpis ? filterBodyHistoryKpiTiles(kpiTiles, display.kpi_detail || 'full') : []
|
||||
|
||||
const hasAnyData =
|
||||
(w?.data_points > 0) ||
|
||||
@@ -378,23 +403,25 @@ export default function BodyHistoryVizSection({ profile, externalPeriod, footer
|
||||
)}
|
||||
{showPeriodSelector && <PeriodSelector value={period} onChange={setInternalPeriod} />}
|
||||
|
||||
<BodyGoalsStrip grouped={groupedGoals} />
|
||||
{display.show_goals_strip && <BodyGoalsStrip grouped={groupedGoals} />}
|
||||
|
||||
<p style={{ fontSize: 11, color: 'var(--text3)', lineHeight: 1.45, marginBottom: 10 }}>
|
||||
Daten und Kennzahlen aus dem Backend-Bundle (gleiche Quelle wie Platzhalter). Training: <strong>Verlauf → Fitness</strong>.
|
||||
</p>
|
||||
{display.show_intro_blurb && (
|
||||
<p style={{ fontSize: 11, color: 'var(--text3)', lineHeight: 1.45, marginBottom: 10 }}>
|
||||
Daten und Kennzahlen aus dem Backend-Bundle (gleiche Quelle wie Platzhalter). Training: <strong>Verlauf → Fitness</strong>.
|
||||
</p>
|
||||
)}
|
||||
|
||||
{viz?.meta?.layer_2a_alignment && (
|
||||
{display.show_layer_meta && viz?.meta?.layer_2a_alignment && (
|
||||
<div style={{ fontSize: 10, color: 'var(--text3)', marginBottom: 8, lineHeight: 1.4 }}>
|
||||
{viz.meta.layer_2a_alignment}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<KpiTilesOverview tiles={kpiTiles} />
|
||||
{kpiTilesShown.length > 0 && <KpiTilesOverview tiles={kpiTilesShown} />}
|
||||
|
||||
{vizLoading && <div style={{ fontSize: 11, color: 'var(--text3)', marginBottom: 8 }}>Aktualisiere…</div>}
|
||||
|
||||
{hasWeight && (
|
||||
{display.show_weight_chart && hasWeight && (
|
||||
<div className="card" style={{ marginBottom: 12 }}>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 8 }}>
|
||||
<div style={{ fontSize: 12, fontWeight: 600, color: 'var(--text3)' }}>
|
||||
@@ -404,7 +431,8 @@ export default function BodyHistoryVizSection({ profile, externalPeriod, footer
|
||||
Daten <ChevronRight size={10} />
|
||||
</button>
|
||||
</div>
|
||||
<ResponsiveContainer width="100%" height={200}>
|
||||
<ChartFrame heightPx={chartHMain}>
|
||||
<ResponsiveContainer width="100%" height="100%">
|
||||
<LineChart data={wCd} margin={{ top: 4, right: 8, bottom: 0, left: -20 }}>
|
||||
<CartesianGrid stroke="var(--border)" strokeDasharray="3 3" />
|
||||
<XAxis dataKey="date" tick={{ fontSize: 9, fill: 'var(--text3)' }} tickLine={false} interval={Math.max(0, Math.floor(wCd.length / 6) - 1)} />
|
||||
@@ -420,7 +448,8 @@ export default function BodyHistoryVizSection({ profile, externalPeriod, footer
|
||||
<Line type="monotone" dataKey="avg7" stroke="#378ADD" strokeWidth={2.5} dot={false} name="avg7" />
|
||||
<Line type="monotone" dataKey="avg14" stroke="#1D9E75" strokeWidth={2} dot={false} strokeDasharray="6 3" name="avg14" />
|
||||
</LineChart>
|
||||
</ResponsiveContainer>
|
||||
</ResponsiveContainer>
|
||||
</ChartFrame>
|
||||
<div style={{ display: 'flex', gap: 12, justifyContent: 'center', marginTop: 6, fontSize: 10, color: 'var(--text3)' }}>
|
||||
<span><span style={{ display: 'inline-block', width: 12, height: 2, background: '#378ADD88', verticalAlign: 'middle', marginRight: 3 }} />● Täglich</span>
|
||||
<span><span style={{ display: 'inline-block', width: 12, height: 2, background: '#378ADD', verticalAlign: 'middle', marginRight: 3 }} />Ø 7T</span>
|
||||
@@ -433,13 +462,14 @@ export default function BodyHistoryVizSection({ profile, externalPeriod, footer
|
||||
</div>
|
||||
)}
|
||||
|
||||
{bfCd.length >= 2 && (
|
||||
{display.show_body_fat_chart && bfCd.length >= 2 && (
|
||||
<div className="card" style={{ marginBottom: 12 }}>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 8 }}>
|
||||
<div style={{ fontSize: 12, fontWeight: 600, color: 'var(--text3)' }}>Körperfett (Caliper)</div>
|
||||
<NavToCaliper />
|
||||
</div>
|
||||
<ResponsiveContainer width="100%" height={170}>
|
||||
<ChartFrame heightPx={chartHSecondary}>
|
||||
<ResponsiveContainer width="100%" height="100%">
|
||||
<LineChart data={bfCd} margin={{ top: 4, right: 8, bottom: 0, left: -20 }}>
|
||||
<CartesianGrid stroke="var(--border)" strokeDasharray="3 3" />
|
||||
<XAxis dataKey="date" tick={{ fontSize: 9, fill: 'var(--text3)' }} tickLine={false} />
|
||||
@@ -448,12 +478,13 @@ export default function BodyHistoryVizSection({ profile, externalPeriod, footer
|
||||
{goalBf != null && <ReferenceLine y={goalBf} stroke="#D85A30" strokeDasharray="5 3" strokeWidth={1.5} label={{ value: `Ziel ${goalBf}%`, fontSize: 9, fill: '#D85A30', position: 'right' }} />}
|
||||
<Line type="monotone" dataKey="bf" stroke="#D85A30" strokeWidth={2.5} dot={{ r: 4, fill: '#D85A30' }} name="bf" />
|
||||
</LineChart>
|
||||
</ResponsiveContainer>
|
||||
</ResponsiveContainer>
|
||||
</ChartFrame>
|
||||
<div style={{ fontSize: 10, color: 'var(--text3)', marginTop: 6, lineHeight: 1.4 }}>Magermasse aus Gewicht und KF% — zweite Kurve entfällt.</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{propChartData.length >= 2 && (
|
||||
{display.show_proportion_chart && propChartData.length >= 2 && (
|
||||
<div className="card" style={{ marginBottom: 12 }}>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start', marginBottom: 8, gap: 8 }}>
|
||||
<div>
|
||||
@@ -469,7 +500,8 @@ export default function BodyHistoryVizSection({ profile, externalPeriod, footer
|
||||
</div>
|
||||
<NavToCircum />
|
||||
</div>
|
||||
<ResponsiveContainer width="100%" height={200}>
|
||||
<ChartFrame heightPx={chartHMain}>
|
||||
<ResponsiveContainer width="100%" height="100%">
|
||||
<ComposedChart data={propChartData} margin={{ top: 4, right: showBellyOnProp ? 4 : 8, bottom: 0, left: -20 }}>
|
||||
<CartesianGrid stroke="var(--border)" strokeDasharray="3 3" />
|
||||
<XAxis dataKey="date" tick={{ fontSize: 9, fill: 'var(--text3)' }} tickLine={false} />
|
||||
@@ -487,7 +519,8 @@ export default function BodyHistoryVizSection({ profile, externalPeriod, footer
|
||||
<Line yAxisId="taper" type="monotone" dataKey="vTaper_avg" stroke="#1D9E75" strokeWidth={1.5} strokeDasharray="5 4" dot={false} name="vTaper_avg" />
|
||||
{showBellyOnProp && <Line yAxisId="belly" type="monotone" dataKey="belly" stroke="#D4537E" strokeWidth={2} dot={{ r: 3 }} connectNulls name="belly" />}
|
||||
</ComposedChart>
|
||||
</ResponsiveContainer>
|
||||
</ResponsiveContainer>
|
||||
</ChartFrame>
|
||||
<div style={{ display: 'flex', gap: 12, justifyContent: 'center', marginTop: 6, fontSize: 10, color: 'var(--text3)', flexWrap: 'wrap' }}>
|
||||
<span><span style={{ display: 'inline-block', width: 12, height: 2, background: '#1D9E75', verticalAlign: 'middle', marginRight: 3 }} />Brust − Taille</span>
|
||||
<span><span style={{ display: 'inline-flex', alignItems: 'center', gap: 3 }}><svg width="14" height="4"><line x1="0" y1="2" x2="14" y2="2" stroke="#1D9E75" strokeWidth="2" strokeDasharray="5 4" /></svg></span>gleitender Mittelwert</span>
|
||||
@@ -496,7 +529,7 @@ export default function BodyHistoryVizSection({ profile, externalPeriod, footer
|
||||
</div>
|
||||
)}
|
||||
|
||||
{idxOk && (
|
||||
{display.show_circumference_index_chart && idxOk && (
|
||||
<div className="card" style={{ marginBottom: 12 }}>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 8 }}>
|
||||
<div>
|
||||
@@ -505,7 +538,8 @@ export default function BodyHistoryVizSection({ profile, externalPeriod, footer
|
||||
</div>
|
||||
<NavToCircum />
|
||||
</div>
|
||||
<ResponsiveContainer width="100%" height={180}>
|
||||
<ChartFrame heightPx={chartHIndex}>
|
||||
<ResponsiveContainer width="100%" height="100%">
|
||||
<LineChart data={idxSeries} margin={{ top: 4, right: 8, bottom: 0, left: -20 }}>
|
||||
<CartesianGrid stroke="var(--border)" strokeDasharray="3 3" />
|
||||
<XAxis dataKey="date" tick={{ fontSize: 9, fill: 'var(--text3)' }} tickLine={false} />
|
||||
@@ -516,7 +550,8 @@ export default function BodyHistoryVizSection({ profile, externalPeriod, footer
|
||||
{idxSeries.some((d) => d.waist_idx != null) && <Line type="monotone" dataKey="waist_idx" stroke="#EF9F27" strokeWidth={2} dot={{ r: 2 }} connectNulls name="waist_idx" />}
|
||||
{idxSeries.some((d) => d.belly_idx != null) && <Line type="monotone" dataKey="belly_idx" stroke="#D4537E" strokeWidth={2} dot={{ r: 2 }} connectNulls name="belly_idx" />}
|
||||
</LineChart>
|
||||
</ResponsiveContainer>
|
||||
</ResponsiveContainer>
|
||||
</ChartFrame>
|
||||
<div style={{ display: 'flex', gap: 12, justifyContent: 'center', marginTop: 6, fontSize: 10, color: 'var(--text3)', flexWrap: 'wrap' }}>
|
||||
<span><span style={{ display: 'inline-block', width: 12, height: 2, background: '#1D9E75', verticalAlign: 'middle', marginRight: 3 }} />Brust</span>
|
||||
<span><span style={{ display: 'inline-block', width: 12, height: 2, background: '#EF9F27', verticalAlign: 'middle', marginRight: 3 }} />Taille</span>
|
||||
@@ -525,14 +560,15 @@ export default function BodyHistoryVizSection({ profile, externalPeriod, footer
|
||||
</div>
|
||||
)}
|
||||
|
||||
{propChartData.length < 2 && cirCd.length >= 2 && (
|
||||
{display.show_circumference_lines_chart && propChartData.length < 2 && cirCd.length >= 2 && (
|
||||
<div className="card" style={{ marginBottom: 12 }}>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 8 }}>
|
||||
<div style={{ fontSize: 12, fontWeight: 600, color: 'var(--text3)' }}>Umfänge (Taille / Hüfte / Bauch)</div>
|
||||
<NavToCircum />
|
||||
</div>
|
||||
<div style={{ fontSize: 10, color: 'var(--text3)', marginBottom: 8, lineHeight: 1.4 }}>Mit Brust- und Taillenumfang erscheint die Proportionen-Ansicht oben.</div>
|
||||
<ResponsiveContainer width="100%" height={150}>
|
||||
<ChartFrame heightPx={chartHFallback}>
|
||||
<ResponsiveContainer width="100%" height="100%">
|
||||
<LineChart data={cirCd} margin={{ top: 4, right: 8, bottom: 0, left: -20 }}>
|
||||
<CartesianGrid stroke="var(--border)" strokeDasharray="3 3" />
|
||||
<XAxis dataKey="date" tick={{ fontSize: 9, fill: 'var(--text3)' }} tickLine={false} />
|
||||
@@ -542,7 +578,8 @@ export default function BodyHistoryVizSection({ profile, externalPeriod, footer
|
||||
<Line type="monotone" dataKey="hip" stroke="#7F77DD" strokeWidth={2} dot={{ r: 3 }} name="Hüfte" />
|
||||
{cirCd.some((d) => d.belly) && <Line type="monotone" dataKey="belly" stroke="#D4537E" strokeWidth={2} dot={{ r: 3 }} name="Bauch" />}
|
||||
</LineChart>
|
||||
</ResponsiveContainer>
|
||||
</ResponsiveContainer>
|
||||
</ChartFrame>
|
||||
</div>
|
||||
)}
|
||||
|
||||
|
||||
Reference in new issue
Block a user