fix: Pie chart center number now shows correct count for selected status

This commit is contained in:
dwindown
2025-11-04 20:50:48 +07:00
parent 6508a537f7
commit 549ef12802

View File

@@ -540,9 +540,9 @@ export default function Dashboard() {
<Label <Label
content={({ viewBox }) => { content={({ viewBox }) => {
if (viewBox && 'cx' in viewBox && 'cy' in viewBox) { if (viewBox && 'cx' in viewBox && 'cy' in viewBox) {
const activePieIndex = data.orderStatusDistribution.findIndex((item: any) => item.name === activeStatus); const activePieIndex = sortedOrderStatus.findIndex((item: any) => (item.status || item.name) === activeStatus);
const displayIndex = hoverIndex !== undefined ? hoverIndex : (activePieIndex >= 0 ? activePieIndex : 0); const displayIndex = hoverIndex !== undefined ? hoverIndex : (activePieIndex >= 0 ? activePieIndex : 0);
const selectedData = data.orderStatusDistribution[displayIndex]; const selectedData = sortedOrderStatus[displayIndex];
return ( return (
<text <text
x={viewBox.cx} x={viewBox.cx}
@@ -555,14 +555,14 @@ export default function Dashboard() {
y={viewBox.cy} y={viewBox.cy}
className="fill-foreground text-3xl font-bold" className="fill-foreground text-3xl font-bold"
> >
{(selectedData?.value ?? 0).toLocaleString()} {(selectedData?.count ?? 0).toLocaleString()}
</tspan> </tspan>
<tspan <tspan
x={viewBox.cx} x={viewBox.cx}
y={(viewBox.cy || 0) + 24} y={(viewBox.cy || 0) + 24}
className="fill-muted-foreground text-sm" className="fill-muted-foreground text-sm"
> >
{selectedData?.name} {selectedData?.status || selectedData?.name}
</tspan> </tspan>
</text> </text>
); );