Fix difference in visualisation between y-axis max = auto vs. value below line peak

This commit is contained in:
2026-01-16 19:04:47 +00:00
parent 27afb4cd5a
commit 55a0742d13
2 changed files with 61 additions and 40 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "med-plan-assistant",
"version": "0.2.2",
"version": "0.2.3",
"private": true,
"dependencies": {
"@radix-ui/react-label": "^2.1.8",

View File

@@ -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]);