diff --git a/src/components/reports/CategoryDonutChart.tsx b/src/components/reports/CategoryDonutChart.tsx index 6b194e3..c75231e 100644 --- a/src/components/reports/CategoryDonutChart.tsx +++ b/src/components/reports/CategoryDonutChart.tsx @@ -2,6 +2,7 @@ import { useTranslation } from "react-i18next"; import { PieChart, Pie, Cell, ResponsiveContainer, Tooltip } from "recharts"; import type { CategoryZoomChild } from "../../shared/types"; import { ChartPatternDefs, getPatternFill } from "../../utils/chartPatterns"; +import { donutParts } from "./donutParts"; export interface CategoryDonutChartProps { byChild: CategoryZoomChild[]; @@ -15,58 +16,70 @@ export default function CategoryDonutChart({ centerValue, }: CategoryDonutChartProps) { const { t } = useTranslation(); + // Only the positive parts can be drawn; the negative ones are named by count (D7, #392). + const { parts, negativeCount } = donutParts(byChild); + const omitted = + negativeCount > 0 ? ( +

+ {t("reports.category.donutOmitted", { count: negativeCount })} +

+ ) : null; - if (byChild.length === 0) { + if (parts.length === 0) { return (
{t("reports.empty.noData")} + {omitted}
); } return ( -
- - - ({ color: c.categoryColor, index }))} - /> - - {byChild.map((entry, index) => ( - - ))} - - - typeof value === "number" - ? new Intl.NumberFormat("en-CA", { style: "currency", currency: "CAD" }).format(value) - : String(value) - } - contentStyle={{ - backgroundColor: "var(--card)", - border: "1px solid var(--border)", - borderRadius: "0.5rem", - }} - /> - - -
- {centerLabel} - {centerValue} +
+
+ + + ({ color: c.categoryColor, index }))} + /> + + {parts.map((entry, index) => ( + + ))} + + + typeof value === "number" + ? new Intl.NumberFormat("en-CA", { style: "currency", currency: "CAD" }).format(value) + : String(value) + } + contentStyle={{ + backgroundColor: "var(--card)", + border: "1px solid var(--border)", + borderRadius: "0.5rem", + }} + /> + + +
+ {centerLabel} + {centerValue} +
+ {omitted}
); } diff --git a/src/components/reports/CategoryOverTimeChart.tsx b/src/components/reports/CategoryOverTimeChart.tsx index 742706d..6c43513 100644 --- a/src/components/reports/CategoryOverTimeChart.tsx +++ b/src/components/reports/CategoryOverTimeChart.tsx @@ -63,6 +63,9 @@ export default function CategoryOverTimeChart({ // (Issue #264 sidecar) so the stacked series never explode to 80+ layers. The // full, uncapped hierarchy lives in `data.tree` and drives the table instead. const visibleCategories = data.categories.filter((name) => !hiddenCategories.has(name)); + // The series of the rows without a category (its id is null) is keyed by the + // SQL's 'Uncategorized': show the translated label instead (#392). + const labelOf = (name: string) => (data.categoryIds[name] === null ? t("reports.uncategorized") : name); const categoryEntries = visibleCategories.map((name, index) => ({ name, color: data.colors[name], @@ -108,7 +111,7 @@ export default function CategoryOverTimeChart({ /> { - if (hoveredCategory && name !== hoveredCategory) return [null, null]; + if (hoveredCategory && name !== labelOf(hoveredCategory)) return [null, null]; return [cadFormatter(Number(value) || 0), String(name)]; }} labelFormatter={(label) => formatMonth(String(label))} @@ -147,7 +150,7 @@ export default function CategoryOverTimeChart({ className="inline-flex items-center gap-1 px-2 py-0.5 text-xs rounded-full bg-[var(--muted)] text-[var(--muted-foreground)] hover:bg-[var(--border)] transition-colors" > - {name} + {labelOf(name)} ))}