Skip to content

Commit

Permalink
small improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbalonperin committed Jul 25, 2024
1 parent f786888 commit 662c2b7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/components/chart-elements/AreaChart/AreaChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,13 @@ const AreaChart = React.forwardRef<HTMLDivElement, AreaChartProps>((props, ref)
setActiveDot(undefined);
}

const yAxisConfigsValueFormatter = yAxisConfigs.flatMap((yAxisConfig) => {
return (
yAxisConfig.categories?.map((c) => [c, yAxisConfig.valueFormatter ?? valueFormatter]) ?? []
);
});
const yAxisValueFormatters = Object.fromEntries(
yAxisConfigsValueFormatter.length > 0
? yAxisConfigsValueFormatter
: categories.map((c, idx) => [c, yAxisConfigs[idx]?.valueFormatter ?? valueFormatter]),
yAxisConfigs.flatMap((yAxisConfig, i) => {
return (
yAxisConfig.categories?.map((c) => [c, yAxisConfig.valueFormatter ?? valueFormatter]) ??
categories.map((c) => [c, yAxisConfigs[i]?.valueFormatter ?? valueFormatter])
);
}),
);

return (
Expand Down
7 changes: 7 additions & 0 deletions src/stories/chart-elements/AreaChart.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,13 @@ export const MultipleYAxes: Story = {
},
};

export const SingleYAxisWithValueFormatter: Story = {
args: {
categories: ["Sales", "Successful Payments"],
yAxisConfigs: [{ orientation: "left", valueFormatter: (value: number) => `${value} S` }],
},
};

export const MultipleYAxesWithExplicitCategories: Story = {
args: {
yAxisConfigs: [
Expand Down

0 comments on commit 662c2b7

Please sign in to comment.