Refactor chart components for improved formatting and import optimization

- Consolidated `recharts` imports for `BarChart`, `AreaChart`, and `LineChart` components.
- Reformatted inline styles for tooltips and axis elements to enhance readability and maintain consistency.
- Applied minor cleanups for improved project code styling.
This commit is contained in:
Felipe Cardoso
2025-11-24 18:42:13 +01:00
parent 487c8a3863
commit 9d40aece30
3 changed files with 56 additions and 39 deletions

View File

@@ -5,17 +5,7 @@
'use client'; 'use client';
import { import { Bar, BarChart, CartesianGrid, ResponsiveContainer, Tooltip, XAxis, YAxis } from 'recharts';
BarChart,
Bar,
XAxis,
YAxis,
CartesianGrid,
Tooltip,
ResponsiveContainer,
Legend,
Rectangle,
} from 'recharts';
import { ChartCard } from './ChartCard'; import { ChartCard } from './ChartCard';
import { CHART_PALETTES } from '@/lib/chart-colors'; import { CHART_PALETTES } from '@/lib/chart-colors';
@@ -44,11 +34,21 @@ const CustomTooltip = ({ active, payload }: any) => {
backdropFilter: 'blur(8px)', backdropFilter: 'blur(8px)',
}} }}
> >
<p style={{ color: 'hsl(var(--popover-foreground))', margin: 0, fontSize: '14px', fontWeight: 600 }}> <p
style={{
color: 'hsl(var(--popover-foreground))',
margin: 0,
fontSize: '14px',
fontWeight: 600,
}}
>
{payload[0].payload.name} {payload[0].payload.name}
</p> </p>
<p style={{ color: 'hsl(var(--muted-foreground))', margin: '4px 0 0 0', fontSize: '13px' }}> <p style={{ color: 'hsl(var(--muted-foreground))', margin: '4px 0 0 0', fontSize: '13px' }}>
Members: <span style={{ fontWeight: 600, color: 'hsl(var(--popover-foreground))' }}>{payload[0].value}</span> Members:{' '}
<span style={{ fontWeight: 600, color: 'hsl(var(--popover-foreground))' }}>
{payload[0].value}
</span>
</p> </p>
</div> </div>
); );
@@ -86,9 +86,7 @@ export function OrganizationDistributionChart({
textAnchor="end" textAnchor="end"
style={{ fill: 'var(--muted-foreground)', fontSize: '12px' }} style={{ fill: 'var(--muted-foreground)', fontSize: '12px' }}
/> />
<YAxis <YAxis style={{ fill: 'var(--muted-foreground)', fontSize: '12px' }} />
style={{ fill: 'var(--muted-foreground)', fontSize: '12px' }}
/>
<Tooltip content={<CustomTooltip />} /> <Tooltip content={<CustomTooltip />} />
<Bar <Bar
dataKey="value" dataKey="value"

View File

@@ -6,14 +6,14 @@
'use client'; 'use client';
import { import {
AreaChart,
Area, Area,
AreaChart,
CartesianGrid,
Legend,
ResponsiveContainer,
Tooltip,
XAxis, XAxis,
YAxis, YAxis,
CartesianGrid,
Tooltip,
ResponsiveContainer,
Legend,
} from 'recharts'; } from 'recharts';
import { ChartCard } from './ChartCard'; import { ChartCard } from './ChartCard';
import { CHART_PALETTES } from '@/lib/chart-colors'; import { CHART_PALETTES } from '@/lib/chart-colors';
@@ -29,7 +29,7 @@ interface RegistrationActivityChartProps {
error?: string | null; error?: string | null;
} }
// Custom tooltip with proper theme colors // Custom tooltip with proper theme colors
const CustomTooltip = ({ active, payload }: any) => { const CustomTooltip = ({ active, payload }: any) => {
if (active && payload && payload.length) { if (active && payload && payload.length) {
return ( return (
@@ -41,10 +41,19 @@ const CustomTooltip = ({ active, payload }: any) => {
padding: '8px 12px', padding: '8px 12px',
}} }}
> >
<p style={{ color: 'hsl(var(--popover-foreground))', margin: 0, fontSize: '13px', fontWeight: 600 }}> <p
style={{
color: 'hsl(var(--popover-foreground))',
margin: 0,
fontSize: '13px',
fontWeight: 600,
}}
>
{payload[0].payload.date} {payload[0].payload.date}
</p> </p>
<p style={{ color: 'hsl(var(--popover-foreground))', margin: '4px 0 0 0', fontSize: '12px' }}> <p
style={{ color: 'hsl(var(--popover-foreground))', margin: '4px 0 0 0', fontSize: '12px' }}
>
New Registrations: {payload[0].value} New Registrations: {payload[0].value}
</p> </p>
</div> </div>
@@ -83,13 +92,8 @@ export function RegistrationActivityChart({
</linearGradient> </linearGradient>
</defs> </defs>
<CartesianGrid strokeDasharray="3 3" style={{ stroke: 'var(--muted)', opacity: 0.2 }} /> <CartesianGrid strokeDasharray="3 3" style={{ stroke: 'var(--muted)', opacity: 0.2 }} />
<XAxis <XAxis dataKey="date" style={{ fill: 'var(--muted-foreground)', fontSize: '12px' }} />
dataKey="date" <YAxis style={{ fill: 'var(--muted-foreground)', fontSize: '12px' }} />
style={{ fill: 'var(--muted-foreground)', fontSize: '12px' }}
/>
<YAxis
style={{ fill: 'var(--muted-foreground)', fontSize: '12px' }}
/>
<Tooltip content={<CustomTooltip />} /> <Tooltip content={<CustomTooltip />} />
<Legend <Legend
wrapperStyle={{ wrapperStyle={{

View File

@@ -8,14 +8,14 @@
import { ChartCard } from './ChartCard'; import { ChartCard } from './ChartCard';
import { CHART_PALETTES } from '@/lib/chart-colors'; import { CHART_PALETTES } from '@/lib/chart-colors';
import { import {
ResponsiveContainer, CartesianGrid,
LineChart, Legend,
Line, Line,
LineChart,
ResponsiveContainer,
Tooltip,
XAxis, XAxis,
YAxis, YAxis,
CartesianGrid,
Tooltip,
Legend,
} from 'recharts'; } from 'recharts';
export interface UserGrowthData { export interface UserGrowthData {
@@ -42,14 +42,29 @@ const CustomTooltip = ({ active, payload }: any) => {
padding: '8px 12px', padding: '8px 12px',
}} }}
> >
<p style={{ color: 'hsl(var(--popover-foreground))', margin: 0, fontSize: '13px', fontWeight: 600 }}> <p
style={{
color: 'hsl(var(--popover-foreground))',
margin: 0,
fontSize: '13px',
fontWeight: 600,
}}
>
{payload[0].payload.date} {payload[0].payload.date}
</p> </p>
<p style={{ color: 'hsl(var(--popover-foreground))', margin: '4px 0 0 0', fontSize: '12px' }}> <p
style={{ color: 'hsl(var(--popover-foreground))', margin: '4px 0 0 0', fontSize: '12px' }}
>
Total Users: {payload[0].value} Total Users: {payload[0].value}
</p> </p>
{payload[1] && ( {payload[1] && (
<p style={{ color: 'hsl(var(--popover-foreground))', margin: '2px 0 0 0', fontSize: '12px' }}> <p
style={{
color: 'hsl(var(--popover-foreground))',
margin: '2px 0 0 0',
fontSize: '12px',
}}
>
Active Users: {payload[1].value} Active Users: {payload[1].value}
</p> </p>
)} )}