Skip to content

Commit

Permalink
refactor: add numeric value to bar totals data
Browse files Browse the repository at this point in the history
  • Loading branch information
joaopedromatias committed Mar 19, 2024
1 parent ab67405 commit 999ba05
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/bar/src/BarCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function renderTotalsToCanvas<RawDatum extends BarDatum>(
ctx.textAlign = layout === 'vertical' ? 'center' : 'start'

barTotals.forEach(barTotal => {
ctx.fillText(barTotal.value, barTotal.x, barTotal.y)
ctx.fillText(barTotal.formattedValue, barTotal.x, barTotal.y)
})
}

Expand Down
2 changes: 1 addition & 1 deletion packages/bar/src/BarTotals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const BarTotals = <RawDatum extends BarDatum>({
textAnchor={layout === 'vertical' ? 'middle' : 'start'}
alignmentBaseline={layout === 'vertical' ? 'alphabetic' : 'middle'}
>
{barTotal.value}
{barTotal.formattedValue}
</animated.text>
))
}
9 changes: 6 additions & 3 deletions packages/bar/src/compute/totals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export interface BarTotalsData {
key: string
x: number
y: number
value: string
value: number
formattedValue: string
animationOffset: number
}

Expand Down Expand Up @@ -61,7 +62,8 @@ export const computeBarTotals = <RawDatum extends BarDatum>(
key: 'total_' + indexValue,
x: xPosition,
y: yPosition,
value: formatValue(indexTotal),
value: indexTotal,
formattedValue: formatValue(indexTotal),
animationOffset,
})
})
Expand Down Expand Up @@ -104,7 +106,8 @@ export const computeBarTotals = <RawDatum extends BarDatum>(
key: 'total_' + indexValue,
x: xPosition,
y: yPosition,
value: formatValue(indexTotal),
value: indexTotal,
formattedValue: formatValue(indexTotal),
animationOffset,
})
})
Expand Down

0 comments on commit 999ba05

Please sign in to comment.