From f4f614e86bd4c8a8d22ef02d74d5ae448ad2e97d Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Sun, 15 Jun 2025 22:00:39 +0000 Subject: [PATCH] Refactor: Improve dashboard chart layout and design Stacked charts and improved styling for a modern look. --- src/components/dashboard/CategoryChart.tsx | 67 +++++++++---------- src/components/dashboard/MonthlyChart.tsx | 78 ++++++++++++---------- src/pages/Index.tsx | 6 +- 3 files changed, 77 insertions(+), 74 deletions(-) diff --git a/src/components/dashboard/CategoryChart.tsx b/src/components/dashboard/CategoryChart.tsx index d5c3dac..8de11b6 100644 --- a/src/components/dashboard/CategoryChart.tsx +++ b/src/components/dashboard/CategoryChart.tsx @@ -10,19 +10,15 @@ interface CategoryChartProps { } const CategoryChart: React.FC = ({ categories, isLoading = false }) => { - // Filter out any categories with zero value to prevent rendering issues const validCategories = categories.filter(cat => cat.valor > 0); - - // Calcular o valor total para exibir no centro do gráfico const totalValue = validCategories.reduce((sum, cat) => sum + cat.valor, 0); - - const renderCustomizedLabel = ({ cx, cy, midAngle, innerRadius, outerRadius, percent, index, name }: any) => { - if (percent < 0.05) return null; // Não mostrar texto para fatias muito pequenas - + + const renderCustomizedLabel = ({ cx, cy, midAngle, innerRadius, outerRadius, percent, index }: any) => { + if (percent < 0.05) return null; const radius = innerRadius + (outerRadius - innerRadius) * 0.7; const x = cx + radius * Math.cos(-midAngle * Math.PI / 180); const y = cy + radius * Math.sin(-midAngle * Math.PI / 180); - + return ( = ({ categories, isLoading = f fill="#fff" textAnchor={x > cx ? 'start' : 'end'} dominantBaseline="central" - className="text-xs font-bold" + className="text-xs font-bold drop-shadow-lg" > {`${(percent * 100).toFixed(0)}%`} @@ -46,16 +42,15 @@ const CategoryChart: React.FC = ({ categories, isLoading = f const renderCustomLegend = (props: any) => { const { payload } = props; - return ( -
+
{payload.map((entry: any, index: number) => (
- {entry.value} + {entry.value}
))}
@@ -65,58 +60,59 @@ const CategoryChart: React.FC = ({ categories, isLoading = f const renderCustomTooltip = ({ active, payload }: any) => { if (active && payload && payload.length) { return ( -
-

{payload[0].name}

+
+

{payload[0].name}

{formatCurrency(payload[0].value)}

-

{`${(payload[0].payload.percentage * 100).toFixed(1)}%`}

+

{`${(payload[0].payload.percentage * 100).toFixed(1)}%`}

); } - return null; }; return ( - - - - Gastos por Categoria + + + + 🧾 Gastos por Categoria {isLoading ? ( -
+
) : validCategories.length === 0 ? ( -
-

Sem dados disponíveis

-

Verifique se existem transações do tipo 'despesa' cadastradas

+
+ Sem dados disponíveis + Verifique se existem transações do tipo 'despesa' cadastradas
) : ( -
+
{validCategories.map((entry, index) => ( ))} @@ -124,13 +120,12 @@ const CategoryChart: React.FC = ({ categories, isLoading = f - - {/* Valor total no centro do gráfico */} + {/* Valor total no centro */}
-
{formatCurrency(totalValue)}
+
{formatCurrency(totalValue)}
)} diff --git a/src/components/dashboard/MonthlyChart.tsx b/src/components/dashboard/MonthlyChart.tsx index 66d590c..59a501c 100644 --- a/src/components/dashboard/MonthlyChart.tsx +++ b/src/components/dashboard/MonthlyChart.tsx @@ -47,19 +47,15 @@ const MonthlyChart: React.FC = ({ data, isLoading = false }) maximumFractionDigits: 0, }).format(value); }; - + const customTooltip = ({ active, payload, label }: any) => { if (active && payload && payload.length) { return ( -
-

{`Mês: ${label}`}

-

- {`Receitas: ${formatCurrency(payload[0].value)}`} -

-

- {`Despesas: ${formatCurrency(payload[1].value)}`} -

-

+

+

{label}

+

{`Receitas: ${formatCurrency(payload[0].value)}`}

+

{`Despesas: ${formatCurrency(payload[1].value)}`}

+

{`Saldo: ${formatCurrency(payload[0].value - payload[1].value)}`}

@@ -70,12 +66,9 @@ const MonthlyChart: React.FC = ({ data, isLoading = false }) // Custom label component that only shows values above a threshold const CustomLabel = ({ x, y, width, value, dataKey }: any) => { - // Only show label if value is significant (above 100) if (!value || value < 100) return null; - const isReceita = dataKey === 'receitas'; const yPosition = isReceita ? y - 5 : y - 5; - return ( = ({ data, isLoading = false }) fill={isReceita ? '#10B981' : '#EF4444'} textAnchor="middle" dominantBaseline="middle" - className="text-xs font-semibold" + className="text-xs font-semibold drop-shadow-lg" > {formatCompactCurrency(value)} @@ -91,66 +84,69 @@ const MonthlyChart: React.FC = ({ data, isLoading = false }) }; return ( - - - Receitas vs Despesas + + + + 📈 Receitas vs Despesas + {isLoading ? ( -
+
) : data.length === 0 ? ( -
- Sem dados disponíveis +
+ Sem dados disponíveis
) : ( -
+
- + } > {data.map((entry, index) => ( ))} @@ -158,19 +154,29 @@ const MonthlyChart: React.FC = ({ data, isLoading = false }) name="Despesas" dataKey="despesas" fill="#EF4444" - radius={[4, 4, 0, 0]} - barSize={35} - animationDuration={1000} + radius={[8, 8, 0, 0]} + barSize={36} + animationDuration={1200} label={} > {data.map((entry, index) => ( ))} + + + + + + + + + +
diff --git a/src/pages/Index.tsx b/src/pages/Index.tsx index f6e1f81..5ee7b04 100644 --- a/src/pages/Index.tsx +++ b/src/pages/Index.tsx @@ -126,6 +126,7 @@ const Dashboard = () => { />
+ {/* Resumo em cards */}
{ />
-
- + {/* ---- GRÁFICOS EM COLUNA ---- */} +
+