Skip to content

Commit

Permalink
[@mantine/charts] Fix valueFormatter not working in point labels of…
Browse files Browse the repository at this point in the history
… LineChant, AreaChart and CompositeChart components (#6989)
  • Loading branch information
rtivital committed Nov 16, 2024
1 parent 5c04b62 commit ed68c87
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/@mantine/charts/src/AreaChart/AreaChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ export const AreaChart = factory<AreaChartFactory>((_props, ref) => {
strokeOpacity={dimmed ? 0.5 : 1}
strokeDasharray={item.strokeDasharray}
yAxisId={item.yAxisId || 'left'}
label={withPointLabels ? <PointLabel /> : undefined}
label={withPointLabels ? <PointLabel valueFormatter={valueFormatter} /> : undefined}
{...(typeof areaProps === 'function' ? areaProps(item) : areaProps)}
/>
</Fragment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export function Usage() {
]}
withLegend
withPointLabels
valueFormatter={(value) => `$ ${value}`}
/>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ export const CompositeChart = factory<CompositeChartFactory>((_props, ref) => {
type={curveType}
strokeDasharray={item.strokeDasharray}
yAxisId={item.yAxisId || 'left'}
label={withPointLabels ? <PointLabel /> : undefined}
label={withPointLabels ? <PointLabel valueFormatter={valueFormatter} /> : undefined}
{...(typeof lineProps === 'function' ? lineProps(item) : lineProps)}
/>
);
Expand Down Expand Up @@ -322,7 +322,7 @@ export const CompositeChart = factory<CompositeChartFactory>((_props, ref) => {
strokeOpacity={dimmed ? 0.5 : 1}
strokeDasharray={item.strokeDasharray}
yAxisId={item.yAxisId || 'left'}
label={withPointLabels ? <PointLabel /> : undefined}
label={withPointLabels ? <PointLabel valueFormatter={valueFormatter} /> : undefined}
{...(typeof areaProps === 'function' ? areaProps(item) : areaProps)}
/>
);
Expand Down
1 change: 1 addition & 0 deletions packages/@mantine/charts/src/LineChart/LineChart.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export function Usage() {
{ name: 'Oranges', color: 'blue.6' },
{ name: 'Tomatoes', color: 'teal.6' },
]}
valueFormatter={(value) => `$ ${value}`}
withLegend
withPointLabels
/>
Expand Down
2 changes: 1 addition & 1 deletion packages/@mantine/charts/src/LineChart/LineChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ export const LineChart = factory<LineChartFactory>((_props, ref) => {
type={curveType}
strokeDasharray={item.strokeDasharray}
yAxisId={item.yAxisId || 'left'}
label={withPointLabels ? <PointLabel /> : undefined}
label={withPointLabels ? <PointLabel valueFormatter={valueFormatter} /> : undefined}
{...(typeof lineProps === 'function' ? lineProps(item) : lineProps)}
/>
);
Expand Down
5 changes: 3 additions & 2 deletions packages/@mantine/charts/src/PointLabel/PointLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ interface PointLabelProps {
x?: number;
y?: number;
value?: number;
valueFormatter?: (value: number) => string;
}

export function PointLabel({ x, y, value }: PointLabelProps) {
export function PointLabel({ x, y, value, valueFormatter }: PointLabelProps) {
return (
<g transform={`translate(${x},${y})`}>
<text
Expand All @@ -16,7 +17,7 @@ export function PointLabel({ x, y, value }: PointLabelProps) {
fill="var(--chart-text-color, var(--mantine-color-dimmed))"
fontSize={8}
>
{value}
{valueFormatter ? valueFormatter(value!) : value}
</text>
</g>
);
Expand Down

0 comments on commit ed68c87

Please sign in to comment.