diff --git a/src/components/Dashboard.tsx b/src/components/Dashboard.tsx index d8b64b2..2d98a57 100644 --- a/src/components/Dashboard.tsx +++ b/src/components/Dashboard.tsx @@ -84,6 +84,8 @@ function Dashboard({ data, seasons, userRole, showDataLabels, setShowDataLabels, const [channelChartType, setChannelChartType] = useState<'bar' | 'pie'>('pie'); const [channelDisplayMode, setChannelDisplayMode] = useState<'absolute' | 'percent'>('absolute'); const [eventDisplayMode, setEventDisplayMode] = useState<'absolute' | 'percent'>('absolute'); + const [districtChartType, setDistrictChartType] = useState<'bar' | 'pie'>('bar'); + const [districtDisplayMode, setDistrictDisplayMode] = useState<'absolute' | 'percent'>('absolute'); const filteredData = useMemo(() => filterData(data, filters), [data, filters]); @@ -290,6 +292,16 @@ function Dashboard({ data, seasons, userRole, showDataLabels, setShowDataLabels, }; }, [seasonFilteredData, includeVAT]); + const districtChartData = useMemo(() => { + if (districtDisplayMode === 'absolute') return districtData; + const total = districtData.datasets[0].data.reduce((s: number, v: number) => s + v, 0); + if (total === 0) return districtData; + return { + ...districtData, + datasets: [{ ...districtData.datasets[0], data: districtData.datasets[0].data.map((v: number) => parseFloat(((v / total) * 100).toFixed(1))) }] + }; + }, [districtData, districtDisplayMode]); + // Quarterly YoY const quarterlyYoYData = useMemo(() => { const revenueField = includeVAT ? 'revenue_gross' : 'revenue_net'; @@ -720,8 +732,36 @@ function Dashboard({ data, seasons, userRole, showDataLabels, setShowDataLabels,
- - + +
+ + +
+
+ + +
+
+ } + > + {districtChartType === 'bar' + ? + : v > 3 ? v.toFixed(1) + '%' : '' } + : { display: false }, + tooltip: { ...pieOptions.plugins.tooltip, callbacks: { label: (ctx: any) => districtDisplayMode === 'percent' ? ` ${ctx.parsed.toFixed(1)}%` : ` ${formatCurrency(ctx.parsed)}` } } + } + }} /> + } @@ -867,8 +907,30 @@ function Dashboard({ data, seasons, userRole, showDataLabels, setShowDataLabels,

{t('dashboard.districtPerformance')}

+
+
+ + +
+
+ + +
+
- + {districtChartType === 'bar' + ? + : v > 3 ? v.toFixed(1) + '%' : '' } + : { display: false }, + tooltip: { ...pieOptions.plugins.tooltip, callbacks: { label: (ctx: any) => districtDisplayMode === 'percent' ? ` ${ctx.parsed.toFixed(1)}%` : ` ${formatCurrency(ctx.parsed)}` } } + } + }} /> + }