Update shorten day separator labels based on chart width
This commit is contained in:
@@ -184,24 +184,18 @@ const SimulationChart = ({
|
|||||||
}, [combinedProfile, templateProfile, simulationDays]);
|
}, [combinedProfile, templateProfile, simulationDays]);
|
||||||
|
|
||||||
// Determine label for each day's reference line
|
// Determine label for each day's reference line
|
||||||
const getDayLabel = React.useCallback((dayNumber: number) => {
|
const getDayLabel = React.useCallback((dayNumber: number, useShort = false) => {
|
||||||
if (dayNumber === 1) return t('refLineRegularPlan');
|
if (dayNumber === 1) return t(useShort ? 'refLineRegularPlanShort' : 'refLineRegularPlan');
|
||||||
|
|
||||||
// Check if this day has an actual schedule entry (not auto-filled)
|
|
||||||
const hasSchedule = days && days.length >= dayNumber;
|
const hasSchedule = days && days.length >= dayNumber;
|
||||||
|
|
||||||
// Check if this day deviates from template
|
|
||||||
const hasDeviation = daysWithDeviations.has(dayNumber);
|
const hasDeviation = daysWithDeviations.has(dayNumber);
|
||||||
|
|
||||||
if (!hasDeviation) {
|
if (!hasDeviation) {
|
||||||
// Matches template
|
return t(useShort ? 'refLineNoDeviationShort' : 'refLineNoDeviation');
|
||||||
return t('refLineNoDeviation');
|
|
||||||
} else if (!hasSchedule) {
|
} else if (!hasSchedule) {
|
||||||
// Deviates but no schedule = recovering
|
return t(useShort ? 'refLineRecoveringShort' : 'refLineRecovering');
|
||||||
return t('refLineRecovering');
|
|
||||||
} else {
|
} else {
|
||||||
// Has deviation and has schedule = actual irregular intake
|
return t(useShort ? 'refLineIrregularIntakeShort' : 'refLineIrregularIntake');
|
||||||
return t('refLineIrregularIntake');
|
|
||||||
}
|
}
|
||||||
}, [days, daysWithDeviations, t]);
|
}, [days, daysWithDeviations, t]);
|
||||||
|
|
||||||
@@ -424,12 +418,23 @@ const SimulationChart = ({
|
|||||||
/>
|
/>
|
||||||
<CartesianGrid strokeDasharray="1 1" xAxisId="hours" yAxisId="concentration" />
|
<CartesianGrid strokeDasharray="1 1" xAxisId="hours" yAxisId="concentration" />
|
||||||
|
|
||||||
{showDayReferenceLines !== false && [...Array(dispDays+1).keys()].map(day => (
|
{showDayReferenceLines !== false && [...Array(dispDays + 1).keys()].map(day => {
|
||||||
|
// Determine whether to use compact day labels to avoid overlap on narrow screens
|
||||||
|
const pxPerDay = scrollableWidth / Math.max(1, dispDays);
|
||||||
|
let label = "";
|
||||||
|
if (pxPerDay < 75) { // tweakable threshold, minimal label
|
||||||
|
label = t('refLineDayShort', { x: day + 1 });
|
||||||
|
} else if (pxPerDay < 110) { // tweakable threshold, compact label
|
||||||
|
label = t('refLineDayShort', { x: day + 1 }) + ' ' + getDayLabel(day + 1, true);
|
||||||
|
} else { // full label
|
||||||
|
label = t('refLineDayX', { x: day + 1 }) + ' ' + getDayLabel(day + 1);
|
||||||
|
}
|
||||||
|
return (
|
||||||
<ReferenceLine
|
<ReferenceLine
|
||||||
key={`day-${day+1}`}
|
key={`day-${day + 1}`}
|
||||||
x={24 * (day+1)}
|
x={24 * (day + 1)}
|
||||||
label={{
|
label={{
|
||||||
value: t('refLineDayX', { x: day+1 }) + ' ' + getDayLabel(day + 1),
|
value: `${label}`,
|
||||||
position: 'insideTopRight',
|
position: 'insideTopRight',
|
||||||
style: {
|
style: {
|
||||||
fontSize: '0.75rem',
|
fontSize: '0.75rem',
|
||||||
@@ -442,7 +447,8 @@ const SimulationChart = ({
|
|||||||
xAxisId="hours"
|
xAxisId="hours"
|
||||||
yAxisId="concentration"
|
yAxisId="concentration"
|
||||||
/>
|
/>
|
||||||
))}
|
);
|
||||||
|
})}
|
||||||
{showTherapeuticRange && (chartView === 'damph' || chartView === 'both') && (
|
{showTherapeuticRange && (chartView === 'damph' || chartView === 'both') && (
|
||||||
<ReferenceLine
|
<ReferenceLine
|
||||||
y={parseFloat(therapeuticRange.min) || 0}
|
y={parseFloat(therapeuticRange.min) || 0}
|
||||||
|
|||||||
@@ -48,6 +48,11 @@ export const de = {
|
|||||||
refLineRecovering: "Erholung",
|
refLineRecovering: "Erholung",
|
||||||
refLineIrregularIntake: "Irregulär",
|
refLineIrregularIntake: "Irregulär",
|
||||||
refLineDayX: "T{{x}}",
|
refLineDayX: "T{{x}}",
|
||||||
|
refLineRegularPlanShort: "(Reg.)",
|
||||||
|
refLineNoDeviationShort: "(Reg.)",
|
||||||
|
refLineRecoveringShort: "(Erh.)",
|
||||||
|
refLineIrregularIntakeShort: "(Irr.)",
|
||||||
|
refLineDayShort: "T{{x}}",
|
||||||
refLineMin: "Min",
|
refLineMin: "Min",
|
||||||
refLineMax: "Max",
|
refLineMax: "Max",
|
||||||
tooltipHour: "Stunde",
|
tooltipHour: "Stunde",
|
||||||
|
|||||||
@@ -48,6 +48,11 @@ export const en = {
|
|||||||
refLineRecovering: "Recovering",
|
refLineRecovering: "Recovering",
|
||||||
refLineIrregularIntake: "Irregular",
|
refLineIrregularIntake: "Irregular",
|
||||||
refLineDayX: "D{{x}}",
|
refLineDayX: "D{{x}}",
|
||||||
|
refLineRegularPlanShort: "(Reg.)",
|
||||||
|
refLineNoDeviationShort: "(Reg.)",
|
||||||
|
refLineRecoveringShort: "(Rec.)",
|
||||||
|
refLineIrregularIntakeShort: "(Ireg.)",
|
||||||
|
refLineDayShort: "D{{x}}",
|
||||||
refLineMin: "Min",
|
refLineMin: "Min",
|
||||||
refLineMax: "Max",
|
refLineMax: "Max",
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user