Fix difference in visualisation between y-axis max = auto vs. value below line peak
This commit is contained in:
@@ -156,51 +156,72 @@ const SimulationChart = ({
|
||||
return ticks;
|
||||
}, [totalHours, xTickInterval]);
|
||||
|
||||
const chartDomain = React.useMemo(() => {
|
||||
const numMin = parseFloat(yAxisMin);
|
||||
const numMax = parseFloat(yAxisMax);
|
||||
const chartDomain = React.useMemo(() => {
|
||||
const numMin = parseFloat(yAxisMin);
|
||||
const numMax = parseFloat(yAxisMax);
|
||||
|
||||
// Calculate actual data range if auto is needed
|
||||
let dataMin = Infinity;
|
||||
let dataMax = -Infinity;
|
||||
// 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);
|
||||
}
|
||||
});
|
||||
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);
|
||||
}
|
||||
});
|
||||
// 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;
|
||||
}
|
||||
// Calculate final domain min
|
||||
let domainMin: number;
|
||||
if (!isNaN(numMin)) { // max value provided via settings
|
||||
// User set yAxisMin explicitly
|
||||
domainMin = numMin;
|
||||
} else if (dataMin !== Infinity) { // data exists
|
||||
// Auto mode: add 5% padding below so the line is not flush with x-axis
|
||||
const range = dataMax - dataMin;
|
||||
const padding = range * 0.05;
|
||||
domainMin = Math.max(0, dataMin - padding);
|
||||
} else { // no data
|
||||
domainMin = 0;
|
||||
}
|
||||
|
||||
const domainMin = !isNaN(numMin) ? numMin : (dataMin !== Infinity ? Math.floor(dataMin) : 0);
|
||||
const domainMax = !isNaN(numMax) ? numMax : (dataMax !== -Infinity ? Math.ceil(dataMax) : 100);
|
||||
// Calculate final domain max
|
||||
let domainMax: number;
|
||||
if (!isNaN(numMax)) { // max value provided via settings
|
||||
// User set yAxisMax explicitly - use it as-is without padding
|
||||
domainMax = numMax;
|
||||
} else if (dataMax !== -Infinity) { // data exists
|
||||
// No padding needed since it seems to be added automatically by Recharts
|
||||
// // Auto mode: add 5% padding above
|
||||
// const range = dataMax - dataMin;
|
||||
// const padding = range * 0.05;
|
||||
// domainMax = dataMax + padding;
|
||||
domainMax = dataMax;
|
||||
} else { // no data
|
||||
domainMax = 100;
|
||||
}
|
||||
|
||||
return [domainMin, domainMax];
|
||||
}, [yAxisMin, yAxisMax, combinedProfile, templateProfile, chartView]);
|
||||
return [domainMin, domainMax];
|
||||
}, [yAxisMin, yAxisMax, combinedProfile, templateProfile, chartView]);
|
||||
|
||||
// Check which days have deviations (differ from template)
|
||||
const daysWithDeviations = React.useMemo(() => {
|
||||
|
||||
Reference in New Issue
Block a user