'use client';
import React from 'react';
import {
BarChart,
Bar,
XAxis,
YAxis,
CartesianGrid,
Tooltip,
ResponsiveContainer,
PieChart,
Pie,
Cell,
Legend,
} from 'recharts';
import type { ValueType, NameType } from 'recharts/types/component/DefaultTooltipContent';
import type { RapportData } from '@/types';
interface EmotionChartProps {
data: RapportData;
type?: 'repartition' | 'evolution' | 'intensite';
}
export default function EmotionChart({ data, type = 'repartition' }: EmotionChartProps) {
if (type === 'repartition') {
const pieData = data.repartition.map((item) => ({
name: item.nom,
value: item.count,
color: item.couleur,
pourcentage: item.pourcentage,
}));
if (pieData.length === 0) {
return ;
}
return (
`${name} (${pourcentage}%)`
}
>
{pieData.map((entry, index) => (
|
))}
[`${value} saisies`, name]
}
contentStyle={{
backgroundColor: 'rgba(255,255,255,0.95)',
border: 'none',
borderRadius: '12px',
boxShadow: '0 4px 12px rgba(0,0,0,0.1)',
}}
/>
);
}
if (type === 'evolution') {
const lineData = data.evolution.labels.map((label, index) => {
const point: Record = { date: label };
data.evolution.emotions.forEach((emotion) => {
point[emotion.nom] = emotion.data[index] || 0;
});
return point;
});
if (lineData.length === 0) {
return ;
}
return (
{data.evolution.emotions.map((emotion) => (
))}
);
}
if (type === 'intensite') {
const barData = data.evolution.labels.map((label, index) => ({
date: label,
intensite: data.evolution.intensite_moyenne[index] || 0,
}));
if (barData.length === 0) {
return ;
}
return (
[`${Number(value).toFixed(1)}`, 'Intensité moyenne']}
/>
);
}
return null;
}
function EmptyChart({ message }: { message: string }) {
return (
);
}