Skip to content

Commit

Permalink
refactor(charts): Move arc-styling to central PieChart
Browse files Browse the repository at this point in the history
  • Loading branch information
tklein1801 committed Sep 18, 2024
1 parent d295b7a commit 1c8a8af
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 21 deletions.
10 changes: 9 additions & 1 deletion src/components/Base/Charts/PieChart.component.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {useTheme} from '@mui/material';
import {PieChart as MuiPieChart, type PieChartProps as MuiPieChartProps} from '@mui/x-charts';
import React from 'react';

import {useScreenSize} from '@/hooks';
import {PieCenterLabel} from '@/routes/Charts.route';

import {ParentSize} from './ParentSize.component';
Expand Down Expand Up @@ -41,6 +43,8 @@ export type TPieChartProps = Omit<MuiPieChartProps, 'children'> & {
* @returns {JSX.Element} The rendered PieChart component.
*/
export const PieChart: React.FC<TPieChartProps> = ({fullWidth = false, primaryText, secondaryText, ...props}) => {
const theme = useTheme();
const screenSize = useScreenSize();
const defaultProps: Partial<MuiPieChartProps> = {
slotProps: {
legend: {
Expand All @@ -53,12 +57,16 @@ export const PieChart: React.FC<TPieChartProps> = ({fullWidth = false, primaryTe

const preparedData: typeof props.series = React.useMemo(() => {
return props.series.map(item => ({
...item,
innerRadius: screenSize === 'small' ? 90 : 110,
paddingAngle: 1,
cornerRadius: theme.shape.borderRadius,
arcLabel: params => params.label ?? '',
arcLabelMinAngle: 18,
highlightScope: {faded: 'global', highlighted: 'item'},
sortingValues(a, b) {
return b - a;
},
...item,
}));
}, [props.series]);

Expand Down
4 changes: 0 additions & 4 deletions src/components/Budget/BudgetPieChart.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,6 @@ export const BudgetPieChart: React.FC<TBudgetPieChartProps> = () => {
{
data: chartData,
valueFormatter: value => Formatter.formatBalance(value.value),
innerRadius: 110,
paddingAngle: 1,
cornerRadius: 5,
highlightScope: {faded: 'global', highlighted: 'item'},
},
]}
/>
Expand Down
4 changes: 0 additions & 4 deletions src/components/Category/Chart/CategoryPieChart.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,6 @@ export const CategoryPieChart: React.FC<TCategoryPieChartProps> = ({
{
data: currentChartData,
valueFormatter: value => Formatter.formatBalance(value.value),
innerRadius: 110,
paddingAngle: 1,
cornerRadius: 5,
highlightScope: {faded: 'global', highlighted: 'item'},
},
]}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,6 @@ export const SubscriptionPieChart = () => {
{
data: chartData,
valueFormatter: value => Formatter.formatBalance(value.value),
innerRadius: 110,
paddingAngle: 1,
cornerRadius: 5,
highlightScope: {faded: 'global', highlighted: 'item'},
},
]}
/>
Expand Down
8 changes: 0 additions & 8 deletions src/routes/Stock.route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -550,10 +550,6 @@ export const Stock = () => {
value: marketValue,
})),
valueFormatter: value => Formatter.formatBalance(value.value),
innerRadius: 110,
paddingAngle: 1,
cornerRadius: 5,
highlightScope: {faded: 'global', highlighted: 'item'},
},
]}
/>
Expand All @@ -575,10 +571,6 @@ export const Stock = () => {
{
data: stockDetails.asset.security.regions.map(({id, share}) => ({label: id, value: share})),
valueFormatter: value => `${value.value} shares`,
innerRadius: 110,
paddingAngle: 1,
cornerRadius: 5,
highlightScope: {faded: 'global', highlighted: 'item'},
},
]}
/>
Expand Down

0 comments on commit 1c8a8af

Please sign in to comment.