From cdaa27cb3a50fa5852c285f671607969efb08ac5 Mon Sep 17 00:00:00 2001 From: SejoB Date: Sun, 14 Apr 2024 17:02:21 +0200 Subject: [PATCH] yaxis added --- src/components/molecules/GenericBarChart.tsx | 60 ++++++++++++++------ 1 file changed, 42 insertions(+), 18 deletions(-) diff --git a/src/components/molecules/GenericBarChart.tsx b/src/components/molecules/GenericBarChart.tsx index 9089e7f5..ad6af231 100644 --- a/src/components/molecules/GenericBarChart.tsx +++ b/src/components/molecules/GenericBarChart.tsx @@ -1,8 +1,8 @@ import React, { FC } from 'react'; -import { ResponsiveContainer, BarChart, LabelList, XAxis, Bar, Tooltip, Legend } from 'recharts'; -import {roseColor, blackColor, ColorScheme, whiteColor} from 'style'; +import { ResponsiveContainer, BarChart, LabelList, XAxis, Bar, Tooltip, Legend, YAxis } from 'recharts'; +import { roseColor, blackColor, ColorScheme, whiteColor } from 'style'; import tinycolor from 'tinycolor2'; -import {useTheme} from "@material-ui/core/styles"; +import { useTheme } from '@material-ui/core/styles'; const Y_AXIS_OFFSET = 20; const MIN_BAR_HEIGHT = 20; @@ -55,7 +55,7 @@ const BarChartContainer: FC = ({ data, textLabel, subtitle, return ( <> - + = ({ data, textLabel, subtitle, /> {isStacked && } + {isStacked && ( + + )} {children} @@ -89,21 +98,32 @@ const SingleBarChart: FC = ({ data, isPercentage, textLabe ); }; -const MultiBarChart: FC = ({ data, isPercentage, isStacked, textLabel, subtitle, editorBarOptions }) => { +const MultiBarChart: FC = ({ + data, + isPercentage, + isStacked, + textLabel, + subtitle, + editorBarOptions, +}) => { const theme = useTheme(); const colors = (theme.palette.primary as ColorScheme).barChartColors; const yLabels = data ? Object.keys(data[0]) : []; yLabels.splice(0, 1); const maxBarsNum = yLabels.length; - const filteredColors : Record = (editorBarOptions && Object.keys(editorBarOptions).length !== 0) ? - Object.values(editorBarOptions).map((include: any, i: number) => { - if (include) { - return colors[i]; - } else { - return false; - } - }).filter( Boolean ) : colors; + const filteredColors: Record = + editorBarOptions && Object.keys(editorBarOptions).length !== 0 + ? Object.values(editorBarOptions) + .map((include: any, i: number) => { + if (include) { + return colors[i]; + } else { + return false; + } + }) + .filter(Boolean) + : colors; return ( = ({ data, isPercentage, isStacked, > {Array.from({ length: maxBarsNum }, (_, i) => { const barStyle = { - filter: `drop-shadow(0.2em ${isStacked ? '0' : '0.2em'} 0 ${tinycolor(filteredColors[i]).darken().toString()})`, + filter: `drop-shadow(0.2em ${isStacked ? '0' : '0.2em'} 0 ${tinycolor(filteredColors[i]) + .darken() + .toString()})`, }; return ( @@ -127,10 +149,12 @@ const MultiBarChart: FC = ({ data, isPercentage, isStacked, style={barStyle} isAnimationActive={false} > - } - dataKey={yLabels[i]} - /> + {!isStacked && ( + } + dataKey={yLabels[i]} + /> + )} ); })}