From 8bd69516c492a2088504c8858de79e614ee178ff Mon Sep 17 00:00:00 2001 From: Andreas Weyer Date: Thu, 4 Dec 2025 00:06:21 +0000 Subject: [PATCH] Update show regular plan overlay only if needed (per day) --- src/components/simulation-chart.tsx | 54 +++++++++++++++++++++++++---- src/locales/de.ts | 2 +- src/locales/en.ts | 2 +- 3 files changed, 49 insertions(+), 9 deletions(-) diff --git a/src/components/simulation-chart.tsx b/src/components/simulation-chart.tsx index 106be9f..9787444 100644 --- a/src/components/simulation-chart.tsx +++ b/src/components/simulation-chart.tsx @@ -79,6 +79,40 @@ const SimulationChart = ({ return [domainMin, domainMax]; }, [yAxisMin, yAxisMax]); + // Check which days have deviations (differ from template) + const daysWithDeviations = React.useMemo(() => { + if (!templateProfile || !combinedProfile) return new Set(); + + const deviatingDays = new Set(); + const simDays = parseInt(simulationDays, 10) || 3; + + // Check each day starting from day 2 (day 1 is always template) + for (let day = 2; day <= simDays; day++) { + const dayStartHour = (day - 1) * 24; + const dayEndHour = day * 24; + + // Sample points in this day to check for differences + // Check every hour in the day + for (let hour = dayStartHour; hour < dayEndHour; hour++) { + const combinedPoint = combinedProfile.find((p: any) => Math.abs(p.timeHours - hour) < 0.1); + const templatePoint = templateProfile.find((p: any) => Math.abs(p.timeHours - hour) < 0.1); + + if (combinedPoint && templatePoint) { + // Consider it different if values differ by more than 0.01 (tolerance for floating point) + const damphDiff = Math.abs(combinedPoint.damph - templatePoint.damph); + const ldxDiff = Math.abs(combinedPoint.ldx - templatePoint.ldx); + + if (damphDiff > 0.01 || ldxDiff > 0.01) { + deviatingDays.add(day); + break; // Found deviation in this day, no need to check more hours + } + } + } + } + + return deviatingDays; + }, [combinedProfile, templateProfile, simulationDays]); + // Merge all profiles into a single dataset for proper tooltip synchronization const mergedData = React.useMemo(() => { const dataMap = new Map(); @@ -93,17 +127,23 @@ const SimulationChart = ({ }); // Add template profile data (regular plan only) if provided + // Only include points for days that have deviations templateProfile?.forEach((point: any) => { - const existing = dataMap.get(point.timeHours) || { timeHours: point.timeHours }; - dataMap.set(point.timeHours, { - ...existing, - templateDamph: point.damph, - templateLdx: point.ldx - }); + const pointDay = Math.ceil(point.timeHours / 24); + + // Only include template data for days with deviations + if (daysWithDeviations.has(pointDay)) { + const existing = dataMap.get(point.timeHours) || { timeHours: point.timeHours }; + dataMap.set(point.timeHours, { + ...existing, + templateDamph: point.damph, + templateLdx: point.ldx + }); + } }); return Array.from(dataMap.values()).sort((a, b) => a.timeHours - b.timeHours); - }, [combinedProfile, templateProfile]); + }, [combinedProfile, templateProfile, daysWithDeviations]); // Calculate chart dimensions const [containerWidth, setContainerWidth] = React.useState(1000); diff --git a/src/locales/de.ts b/src/locales/de.ts index 38dc244..e90a608 100644 --- a/src/locales/de.ts +++ b/src/locales/de.ts @@ -58,7 +58,7 @@ export const de = { xAxisFormat24hDesc: "Wiederholender 0-24h Zyklus", xAxisFormat12h: "Tageszeit (12h AM/PM)", xAxisFormat12hDesc: "Wiederholend 12h Zyklus im AM/PM Format", - showTemplateDayInChart: "Regulären Plan kontinuierlich im Diagramm anzeigen", + showTemplateDayInChart: "Regulären Plan in abweichenden Tagen zusätzlich einblenden", showDayReferenceLines: "Tagestrenner anzeigen", simulationDuration: "Simulationsdauer", days: "Tage", diff --git a/src/locales/en.ts b/src/locales/en.ts index b408056..729db6b 100644 --- a/src/locales/en.ts +++ b/src/locales/en.ts @@ -58,7 +58,7 @@ export const en = { xAxisFormat24hDesc: "Repeating 0-24h cycle", xAxisFormat12h: "Time of Day (12h AM/PM)", xAxisFormat12hDesc: "Repeating 12h cycle in AM/PM format", - showTemplateDayInChart: "Overlay regular plan in chart", + showTemplateDayInChart: "Overlay regular plan for deviating days", showDayReferenceLines: "Show day separators", simulationDuration: "Simulation Duration", days: "Days",