Skip to content

Commit

Permalink
Make defaultizeValueFormatter types more permissive
Browse files Browse the repository at this point in the history
  • Loading branch information
JCQuintas committed Apr 11, 2024
1 parent 0cf2b85 commit 11bf5a0
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 13 deletions.
5 changes: 1 addition & 4 deletions packages/x-charts/src/BarChart/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,7 @@ const formatter: Formatter<'bar'> = (params, dataset) => {
return {
seriesOrder,
stackingGroups,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
series: defaultizeValueFormatter(completedSeries, (v, _) =>
v == null ? '' : v.toLocaleString(),
),
series: defaultizeValueFormatter(completedSeries, (v) => (v == null ? '' : v.toLocaleString())),
};
};

Expand Down
5 changes: 1 addition & 4 deletions packages/x-charts/src/LineChart/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,7 @@ const formatter: Formatter<'line'> = (params, dataset) => {
return {
seriesOrder,
stackingGroups,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
series: defaultizeValueFormatter(completedSeries, (v, _) =>
v == null ? '' : v.toLocaleString(),
),
series: defaultizeValueFormatter(completedSeries, (v) => (v == null ? '' : v.toLocaleString())),
};
};

Expand Down
3 changes: 1 addition & 2 deletions packages/x-charts/src/ScatterChart/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { Formatter } from '../models/seriesType/config';

const formatter: Formatter<'scatter'> = ({ series, seriesOrder }) => {
return {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
series: defaultizeValueFormatter(series, (v, _) => `(${v.x}, ${v.y})`),
series: defaultizeValueFormatter(series, (v) => `(${v.x}, ${v.y})`),
seriesOrder,
};
};
Expand Down
6 changes: 3 additions & 3 deletions packages/x-charts/src/internals/defaultizeValueFormatter.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { SeriesId } from '../models/seriesType/common';

function defaultizeValueFormatter<
ISeries extends { valueFormatter?: IFormatter },
IFormatter extends (v: any, context: any) => string,
IFormatter extends (v: any, context?: unknown) => string,
ISeries extends { valueFormatter?: Function },
>(
series: Record<SeriesId, ISeries>,
defaultValueFormatter: IFormatter,
Expand All @@ -11,7 +11,7 @@ function defaultizeValueFormatter<
Object.keys(series).forEach((seriesId) => {
defaultizedSeries[seriesId] = {
...series[seriesId],
valueFormatter: series[seriesId].valueFormatter ?? defaultValueFormatter,
valueFormatter: (series[seriesId].valueFormatter as IFormatter) ?? defaultValueFormatter,
};
});
return defaultizedSeries;
Expand Down

0 comments on commit 11bf5a0

Please sign in to comment.