From cdabda25cbb5d2740633f1942fc79ad9840f8f4f Mon Sep 17 00:00:00 2001 From: Matiss Janis Aboltins Date: Fri, 22 Nov 2024 19:09:41 +0000 Subject: [PATCH] Improve scaling of donut graph --- .../src/components/reports/ChooseGraph.tsx | 1 - .../components/reports/graphs/DonutGraph.tsx | 165 ++++++++++-------- 2 files changed, 95 insertions(+), 71 deletions(-) diff --git a/packages/desktop-client/src/components/reports/ChooseGraph.tsx b/packages/desktop-client/src/components/reports/ChooseGraph.tsx index e477e6e3491..a743ac84462 100644 --- a/packages/desktop-client/src/components/reports/ChooseGraph.tsx +++ b/packages/desktop-client/src/components/reports/ChooseGraph.tsx @@ -137,7 +137,6 @@ export function ChooseGraph({ return ( { } = props; const yAxis = payload.name ?? payload.date; + const sin = Math.sin(-RADIAN * 240); + const my = cy + outerRadius * sin; + const ey = my - 5; + return ( - + {`${yAxis}`} - + {`${amountToCurrency(value)}`} - + {`${(percent * 100).toFixed(2)}%`} @@ -184,7 +206,6 @@ type DonutGraphProps = { filters: RuleConditionEntity[]; groupBy: string; balanceTypeOp: balanceTypeOpType; - compact?: boolean; viewLabels: boolean; showHiddenCategories?: boolean; showOffBudget?: boolean; @@ -197,7 +218,6 @@ export function DonutGraph({ filters, groupBy, balanceTypeOp, - compact, viewLabels, showHiddenCategories, showOffBudget, @@ -226,72 +246,77 @@ export function DonutGraph({ const sortedData = unsortedData.slice().sort((a, b) => getVal(b) - getVal(a)); return ( - - {(width, height) => - sortedData && ( - -
- {!compact &&
} - - getVal(val)} - nameKey={yAxis} - isAnimationActive={false} - data={sortedData} - innerRadius={Math.min(width, height) * 0.2} - fill="#8884d8" - labelLine={false} - label={e => - viewLabels && !compact ? customLabel(e) :
- } - startAngle={90} - endAngle={-270} - onMouseLeave={() => setPointer('')} - onMouseEnter={(_, index) => { - setActiveIndex(index); - if (!['Group', 'Interval'].includes(groupBy)) { - setPointer('pointer'); - } - }} - onClick={item => - ((compact && showTooltip) || !compact) && - !['Group', 'Interval'].includes(groupBy) && - showActivity({ - navigate, - categories, - accounts, - balanceTypeOp, - filters, - showHiddenCategories, - showOffBudget, - type: 'totals', - startDate: data.startDate, - endDate: data.endDate, - field: groupBy.toLowerCase(), - id: item.id, - }) - } + + {(width, height) => { + const compact = height <= 300 || width <= 300; + + return ( + sortedData && ( + +
+ {!compact &&
} + - {data.legend.map((entry, index) => ( - - ))} - - -
- - ) - } + getVal(val)} + nameKey={yAxis} + isAnimationActive={false} + data={sortedData} + innerRadius={Math.min(width, height) * 0.2} + fill="#8884d8" + labelLine={false} + label={e => + viewLabels && !compact ? customLabel(e) :
+ } + startAngle={90} + endAngle={-270} + onMouseLeave={() => setPointer('')} + onMouseEnter={(_, index) => { + setActiveIndex(index); + if (!['Group', 'Interval'].includes(groupBy)) { + setPointer('pointer'); + } + }} + onClick={item => + ((compact && showTooltip) || !compact) && + !['Group', 'Interval'].includes(groupBy) && + showActivity({ + navigate, + categories, + accounts, + balanceTypeOp, + filters, + showHiddenCategories, + showOffBudget, + type: 'totals', + startDate: data.startDate, + endDate: data.endDate, + field: groupBy.toLowerCase(), + id: item.id, + }) + } + > + {data.legend.map((entry, index) => ( + + ))} + + +
+ + ) + ); + }} ); }