From 002103e6762e334d3865f6b3981c6f3ef2e141bf Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Tue, 20 May 2025 14:35:43 +0000 Subject: [PATCH] Refactor: Improve chart visuals Improve the visual appearance of the pie chart and the "Receitas vs Despesas" chart, aiming for a more modern look, without affecting other functionalities. --- src/components/dashboard/CategoryChart.tsx | 53 +++++++---- src/components/dashboard/MonthlyChart.tsx | 100 ++++++++++++++++++--- 2 files changed, 124 insertions(+), 29 deletions(-) diff --git a/src/components/dashboard/CategoryChart.tsx b/src/components/dashboard/CategoryChart.tsx index 99239b6..d5c3dac 100644 --- a/src/components/dashboard/CategoryChart.tsx +++ b/src/components/dashboard/CategoryChart.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; -import { PieChart, Pie, Cell, ResponsiveContainer, Legend, Tooltip, Label } from 'recharts'; +import { PieChart, Pie, Cell, ResponsiveContainer, Legend, Tooltip } from 'recharts'; import { CategorySummary } from '@/types/financialTypes'; interface CategoryChartProps { @@ -13,6 +13,9 @@ const CategoryChart: React.FC = ({ categories, isLoading = f // 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 @@ -27,7 +30,7 @@ const CategoryChart: React.FC = ({ categories, isLoading = f fill="#fff" textAnchor={x > cx ? 'start' : 'end'} dominantBaseline="central" - className="text-xs font-medium" + className="text-xs font-bold" > {`${(percent * 100).toFixed(0)}%`} @@ -45,14 +48,14 @@ const CategoryChart: React.FC = ({ categories, isLoading = f const { payload } = props; return ( -
+
{payload.map((entry: any, index: number) => (
- {entry.value} + {entry.value}
))}
@@ -62,10 +65,10 @@ const CategoryChart: React.FC = ({ categories, isLoading = f const renderCustomTooltip = ({ active, payload }: any) => { if (active && payload && payload.length) { return ( -
+

{payload[0].name}

-

{formatCurrency(payload[0].value)}

-

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

+

{formatCurrency(payload[0].value)}

+

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

); } @@ -74,9 +77,11 @@ const CategoryChart: React.FC = ({ categories, isLoading = f }; return ( - - - Gastos por Categoria + + + + Gastos por Categoria + {isLoading ? ( @@ -89,28 +94,44 @@ const CategoryChart: React.FC = ({ categories, isLoading = f

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

) : ( -
+
{validCategories.map((entry, index) => ( - + ))} - + + + {/* Valor total no centro do gráfico */} +
+
{formatCurrency(totalValue)}
+
)} diff --git a/src/components/dashboard/MonthlyChart.tsx b/src/components/dashboard/MonthlyChart.tsx index 87233e9..2e6f999 100644 --- a/src/components/dashboard/MonthlyChart.tsx +++ b/src/components/dashboard/MonthlyChart.tsx @@ -10,6 +10,8 @@ import { Tooltip, Legend, ResponsiveContainer, + Cell, + LabelList, } from 'recharts'; import { MonthlyData } from '@/types/financialTypes'; @@ -27,10 +29,35 @@ const MonthlyChart: React.FC = ({ data, isLoading = false }) maximumFractionDigits: 0, }).format(value); }; + + // Adicionar formatação condicional para os barras + const getBarColor = (dataPoint: MonthlyData) => { + return dataPoint.receitas > dataPoint.despesas ? '#10B981' : '#EF4444'; + }; + + 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)}`} +

+

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

+
+ ); + } + return null; + }; return ( - - + + Receitas vs Despesas @@ -43,35 +70,82 @@ const MonthlyChart: React.FC = ({ data, isLoading = false }) Sem dados disponíveis
) : ( -
+
- - + + formatCurrency(value)} - labelFormatter={(label) => `Mês: ${label}`} + cursor={{ fill: 'rgba(0, 0, 0, 0.05)' }} + content={customTooltip} + /> + - + barSize={30} + animationDuration={1000} + > + {data.map((entry, index) => ( + + ))} + + + radius={[4, 4, 0, 0]} + barSize={30} + animationDuration={1000} + > + {data.map((entry, index) => ( + + ))} + +