Update show regular plan overlay only if needed (per day)

This commit is contained in:
2025-12-04 00:06:21 +00:00
parent bb5569aada
commit 8bd69516c4
3 changed files with 49 additions and 9 deletions

View File

@@ -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<number>();
const deviatingDays = new Set<number>();
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 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);

View File

@@ -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",

View File

@@ -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",