From 9409c14c1508e53fed3d45a4dae4514bdf4c110a Mon Sep 17 00:00:00 2001 From: petterav Date: Wed, 17 Apr 2024 11:39:25 +0200 Subject: [PATCH] fix: Correct number of months and weeks in tooltip --- .../GrowthChart/GrowthChartBuilder/ChartTooltip.ts | 10 +++++----- src/types/chartDataTypes.ts | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/components/GrowthChart/GrowthChartBuilder/ChartTooltip.ts b/src/components/GrowthChart/GrowthChartBuilder/ChartTooltip.ts index 203ede3..80de91c 100644 --- a/src/components/GrowthChart/GrowthChartBuilder/ChartTooltip.ts +++ b/src/components/GrowthChart/GrowthChartBuilder/ChartTooltip.ts @@ -68,7 +68,7 @@ export const ChartTooltip = (category: string, xAxisLabel: string, yAxisLabel: s }, label: (tooltipItem) => { let yValue = Number(tooltipItem.formattedValue.replace(',', '.')); - let xValue = Number(tooltipItem.label.replace(',', '.')); + let xValue = Number(tooltipItem.label.replace(',', '.')) + 0.01; let xLabel = ''; @@ -79,8 +79,8 @@ export const ChartTooltip = (category: string, xAxisLabel: string, yAxisLabel: s xLabel = `${xAxisLabel}: ${xValue} ${xUnit}`; if (xAxisLabel === TimeUnitCodes.weeks) { - const weeks = Number((xValue % timeUnitData.Months.divisor).toFixed(0)); - const months = Number((Math.floor(xValue / timeUnitData.Months.divisor)).toFixed(0)); + const weeks = Number(Math.floor(xValue % timeUnitData.Months.divisor)); + const months = Number(Math.floor(xValue / timeUnitData.Months.divisor)); xLabel = (months === 0 ? `${i18n.t('Age')}: ${weeks} ${(weeks === 1) ? timeUnitData.Weeks.singular : timeUnitData.Weeks.plural}` : `${i18n.t('Age')}: ${months} ${(months === 1) ? timeUnitData.Months.singular @@ -88,8 +88,8 @@ export const ChartTooltip = (category: string, xAxisLabel: string, yAxisLabel: s ? timeUnitData.Weeks.singular : timeUnitData.Weeks.plural}` : ''}`); } if (xAxisLabel === TimeUnitCodes.months) { - const months = Number(Math.floor(xValue % timeUnitData.Years.divisor).toFixed(0)); - const years = Number(Math.floor(xValue / timeUnitData.Years.divisor).toFixed(0)); + const months = Number(Math.floor(xValue % timeUnitData.Years.divisor)); + const years = Number(Math.floor(xValue / timeUnitData.Years.divisor)); xLabel = (years === 0 ? `${i18n.t('Age')}: ${months} ${(months === 1) ? timeUnitData.Months.singular : timeUnitData.Months.plural}` : `${i18n.t('Age')}: ${years} ${(years === 1) ? timeUnitData.Years.singular diff --git a/src/types/chartDataTypes.ts b/src/types/chartDataTypes.ts index 6f4ae87..0d11079 100644 --- a/src/types/chartDataTypes.ts +++ b/src/types/chartDataTypes.ts @@ -64,7 +64,7 @@ export const timeUnitData: { [key: string]: TimeUnitData } = { [TimeUnitCodes.months]: { singular: i18n.t('month'), plural: i18n.t('months'), - divisor: 4, + divisor: 4.34812141, }, [TimeUnitCodes.weeks]: { singular: i18n.t('week'),