Skip to content

Commit

Permalink
fix: Correct number of months and weeks in tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
petterav committed Apr 17, 2024
1 parent dd3b2f5 commit 9409c14
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/components/GrowthChart/GrowthChartBuilder/ChartTooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';

Expand All @@ -79,17 +79,17 @@ 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
: timeUnitData.Months.plural} ${(weeks > 0) ? `${weeks} ${(weeks === 1)
? 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
Expand Down
2 changes: 1 addition & 1 deletion src/types/chartDataTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down

0 comments on commit 9409c14

Please sign in to comment.