Fix difference in visualisation between y-axis max = auto vs. value below line peak
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "med-plan-assistant",
|
"name": "med-plan-assistant",
|
||||||
"version": "0.2.2",
|
"version": "0.2.3",
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@radix-ui/react-label": "^2.1.8",
|
"@radix-ui/react-label": "^2.1.8",
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ const SimulationChart = ({
|
|||||||
return ticks;
|
return ticks;
|
||||||
}, [totalHours, xTickInterval]);
|
}, [totalHours, xTickInterval]);
|
||||||
|
|
||||||
const chartDomain = React.useMemo(() => {
|
const chartDomain = React.useMemo(() => {
|
||||||
const numMin = parseFloat(yAxisMin);
|
const numMin = parseFloat(yAxisMin);
|
||||||
const numMax = parseFloat(yAxisMax);
|
const numMax = parseFloat(yAxisMax);
|
||||||
|
|
||||||
@@ -188,19 +188,40 @@ const SimulationChart = ({
|
|||||||
dataMax = Math.max(dataMax, 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);
|
// Calculate final domain min
|
||||||
const domainMax = !isNaN(numMax) ? numMax : (dataMax !== -Infinity ? Math.ceil(dataMax) : 100);
|
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];
|
return [domainMin, domainMax];
|
||||||
}, [yAxisMin, yAxisMax, combinedProfile, templateProfile, chartView]);
|
}, [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