From abd8e790b8a5d43024cfe0925896c0a868a3f6fe Mon Sep 17 00:00:00 2001 From: Andreas Weyer Date: Thu, 8 Jan 2026 18:37:02 +0000 Subject: [PATCH] Fix y-axis range min/max value logic --- src/components/simulation-chart.tsx | 44 +++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/src/components/simulation-chart.tsx b/src/components/simulation-chart.tsx index bf0aac0..f503ce8 100644 --- a/src/components/simulation-chart.tsx +++ b/src/components/simulation-chart.tsx @@ -76,10 +76,48 @@ const SimulationChart = ({ const chartDomain = React.useMemo(() => { const numMin = parseFloat(yAxisMin); const numMax = parseFloat(yAxisMax); - const domainMin = !isNaN(numMin) ? numMin : 'auto'; - const domainMax = !isNaN(numMax) ? numMax : 'auto'; + + // Calculate actual data range if auto is needed + let dataMin = Infinity; + let dataMax = -Infinity; + + if (isNaN(numMin) || isNaN(numMax)) { + // Scan through combined profile data to find actual min/max + combinedProfile?.forEach((point: any) => { + if (chartView === 'damph' || chartView === 'both') { + dataMin = Math.min(dataMin, point.damph); + dataMax = Math.max(dataMax, point.damph); + } + if (chartView === 'ldx' || chartView === 'both') { + dataMin = Math.min(dataMin, point.ldx); + dataMax = Math.max(dataMax, point.ldx); + } + }); + + // Also check template profile if shown + templateProfile?.forEach((point: any) => { + if (chartView === 'damph' || chartView === 'both') { + dataMin = Math.min(dataMin, point.damph); + dataMax = Math.max(dataMax, point.damph); + } + if (chartView === 'ldx' || chartView === 'both') { + dataMin = Math.min(dataMin, point.ldx); + dataMax = Math.max(dataMax, point.ldx); + } + }); + + // Add small padding (5% on each side) for better visualization + const range = dataMax - dataMin; + const padding = range * 0.05; + dataMin = Math.max(0, dataMin - padding); // Don't go below 0 + dataMax = dataMax + padding; + } + + const domainMin = !isNaN(numMin) ? numMin : (dataMin !== Infinity ? Math.floor(dataMin) : 0); + const domainMax = !isNaN(numMax) ? numMax : (dataMax !== -Infinity ? Math.ceil(dataMax) : 100); + return [domainMin, domainMax]; - }, [yAxisMin, yAxisMax]); + }, [yAxisMin, yAxisMax, combinedProfile, templateProfile, chartView]); // Check which days have deviations (differ from template) const daysWithDeviations = React.useMemo(() => {