Fix difference in visualisation between y-axis max = auto vs. value below line peak
This commit is contained in:
@@ -188,16 +188,37 @@ const SimulationChart = ({
|
||||
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);
|
||||
// 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;
|
||||
}
|
||||
|
||||
// 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]);
|
||||
|
||||
Reference in New Issue
Block a user