80 lines
2.1 KiB
JavaScript
80 lines
2.1 KiB
JavaScript
|
|
/**
|
||
|
|
* Sichtbarkeit für nutrition_history_viz (sync mit backend dashboard_widget_config).
|
||
|
|
* `visibility === undefined` → Verlauf-Tab: alles an.
|
||
|
|
*/
|
||
|
|
|
||
|
|
export const NUTRITION_HISTORY_VIZ_HISTORY_FULL = {
|
||
|
|
chart_days: 30,
|
||
|
|
show_goals_strip: true,
|
||
|
|
show_intro_blurb: true,
|
||
|
|
show_kpis: true,
|
||
|
|
kpi_detail: 'full',
|
||
|
|
show_kcal_vs_weight: true,
|
||
|
|
show_calorie_balance_chart: true,
|
||
|
|
show_protein_lean_chart: true,
|
||
|
|
show_heuristics: true,
|
||
|
|
show_macro_daily_bars: true,
|
||
|
|
show_macro_distribution_pair: true,
|
||
|
|
show_energy_protein_charts: true,
|
||
|
|
}
|
||
|
|
|
||
|
|
export const NUTRITION_HISTORY_VIZ_WIDGET_DEFAULTS = {
|
||
|
|
chart_days: 30,
|
||
|
|
show_goals_strip: false,
|
||
|
|
show_intro_blurb: false,
|
||
|
|
show_kpis: true,
|
||
|
|
kpi_detail: 'compact',
|
||
|
|
show_kcal_vs_weight: true,
|
||
|
|
show_calorie_balance_chart: false,
|
||
|
|
show_protein_lean_chart: false,
|
||
|
|
show_heuristics: false,
|
||
|
|
show_macro_daily_bars: true,
|
||
|
|
show_macro_distribution_pair: true,
|
||
|
|
show_energy_protein_charts: false,
|
||
|
|
}
|
||
|
|
|
||
|
|
const BOOL_KEYS = [
|
||
|
|
'show_goals_strip',
|
||
|
|
'show_intro_blurb',
|
||
|
|
'show_kpis',
|
||
|
|
'show_kcal_vs_weight',
|
||
|
|
'show_calorie_balance_chart',
|
||
|
|
'show_protein_lean_chart',
|
||
|
|
'show_heuristics',
|
||
|
|
'show_macro_daily_bars',
|
||
|
|
'show_macro_distribution_pair',
|
||
|
|
'show_energy_protein_charts',
|
||
|
|
]
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @param {Record<string, unknown>|null|undefined} raw
|
||
|
|
*/
|
||
|
|
export function normalizeNutritionHistoryVizConfig(raw) {
|
||
|
|
const base = { ...NUTRITION_HISTORY_VIZ_WIDGET_DEFAULTS }
|
||
|
|
if (!raw || typeof raw !== 'object') return base
|
||
|
|
for (const k of BOOL_KEYS) {
|
||
|
|
if (Object.prototype.hasOwnProperty.call(raw, k)) {
|
||
|
|
base[k] = raw[k] === true
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (raw.kpi_detail === 'full' || raw.kpi_detail === 'compact') {
|
||
|
|
base.kpi_detail = raw.kpi_detail
|
||
|
|
}
|
||
|
|
if (raw.chart_days != null) {
|
||
|
|
const n = Number(raw.chart_days)
|
||
|
|
if (Number.isFinite(n)) {
|
||
|
|
base.chart_days = Math.min(90, Math.max(7, Math.round(n)))
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return base
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @param {Array<object>} kpiTiles
|
||
|
|
* @param {'compact'|'full'} detail
|
||
|
|
*/
|
||
|
|
export function filterNutritionHistoryKpiTiles(kpiTiles, detail) {
|
||
|
|
if (detail === 'full' || !Array.isArray(kpiTiles)) return kpiTiles
|
||
|
|
return kpiTiles.slice(0, 4)
|
||
|
|
}
|