Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ (dashboards) piecharts - sorting and label spacing #3855

Merged
merged 10 commits into from
Dec 7, 2024
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ const ActiveShapeMobile = props => {

return (
<g>
<text x={cx} y={cy + 70} dy={-8} textAnchor="middle" fill={fill}>
<text x={cx} y={cy + 70} dy={0} textAnchor="middle" fill={fill}>
{`${yAxis}`}
</text>
<PrivacyFilter>
<text x={cx - 40} y={cy + 40} dy={0} textAnchor="end" fill={fill}>
<text x={cx - 50} y={cy + 40} dy={0} textAnchor="end" fill={fill}>
{`${amountToCurrency(value)}`}
</text>
<text x={cx + 45} y={cy + 40} dy={0} textAnchor="start" fill="#999">
<text x={cx + 50} y={cy + 40} dy={0} textAnchor="start" fill="#999">
{`${(percent * 100).toFixed(2)}%`}
</text>
</PrivacyFilter>
Expand Down Expand Up @@ -211,7 +211,7 @@ export function DonutGraph({
const accounts = useAccounts();
const [pointer, setPointer] = useState('');

const getVal = obj => {
const getVal = (obj: DataEntity) => {
if (['totalDebts', 'netDebts'].includes(balanceTypeOp)) {
return -1 * obj[balanceTypeOp];
} else {
Expand All @@ -221,6 +221,10 @@ export function DonutGraph({

const [activeIndex, setActiveIndex] = useState(0);

// Sort the data in the pie chart
const unsortedData = data[splitData];
const sortedData = unsortedData.toSorted((a, b) => getVal(b) - getVal(a));

return (
<Container
style={{
Expand All @@ -229,7 +233,7 @@ export function DonutGraph({
}}
>
{(width, height) =>
data[splitData] && (
sortedData && (
<ResponsiveContainer>
<div>
{!compact && <div style={{ marginTop: '15px' }} />}
Expand All @@ -244,13 +248,15 @@ export function DonutGraph({
dataKey={val => getVal(val)}
nameKey={yAxis}
isAnimationActive={false}
data={data[splitData]}
data={sortedData}
innerRadius={Math.min(width, height) * 0.2}
fill="#8884d8"
labelLine={false}
label={e =>
viewLabels && !compact ? customLabel(e) : <div />
}
startAngle={90}
endAngle={-270}
onMouseLeave={() => setPointer('')}
onMouseEnter={(_, index) => {
setActiveIndex(index);
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/3855.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Enhancements
authors: [MatissJanis]
---

Dashboards: sort pie-chart according to balances; add more spacing for labels.