Fix y-axis range min/max value logic
This commit is contained in:
@@ -76,10 +76,48 @@ const SimulationChart = ({
|
|||||||
const chartDomain = React.useMemo(() => {
|
const chartDomain = React.useMemo(() => {
|
||||||
const numMin = parseFloat(yAxisMin);
|
const numMin = parseFloat(yAxisMin);
|
||||||
const numMax = parseFloat(yAxisMax);
|
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];
|
return [domainMin, domainMax];
|
||||||
}, [yAxisMin, yAxisMax]);
|
}, [yAxisMin, yAxisMax, combinedProfile, templateProfile, chartView]);
|
||||||
|
|
||||||
// Check which days have deviations (differ from template)
|
// Check which days have deviations (differ from template)
|
||||||
const daysWithDeviations = React.useMemo(() => {
|
const daysWithDeviations = React.useMemo(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user