/* * Performance Chart Component * Shows anonymized ranking of outlets based on selected metric */ import React from 'react'; import { Bar } from 'react-chartjs-2'; import { Chart as ChartJS, CategoryScale, LinearScale, BarElement, Title, Tooltip, Legend, } from 'chart.js'; import { Card, CardContent } from '../ui/Card'; import { useTranslation } from 'react-i18next'; // Register Chart.js components ChartJS.register( CategoryScale, LinearScale, BarElement, Title, Tooltip, Legend ); interface PerformanceData { rank: number; tenant_id: string; anonymized_name: string; metric_value: number; } interface PerformanceChartProps { data?: PerformanceData[]; metric: string; period: number; } export const PerformanceChart: React.FC = ({ data, metric, period }) => { const { t } = useTranslation('dashboard'); // Prepare chart data const chartData = { labels: data?.map(item => item.anonymized_name) || [], datasets: [ { label: t(`enterprise.metric_labels.${metric}`) || metric, data: data?.map(item => item.metric_value) || [], backgroundColor: 'rgba(75, 192, 192, 0.6)', borderColor: 'rgba(75, 192, 192, 1)', borderWidth: 1, }, ], }; const options = { responsive: true, plugins: { legend: { display: false, }, title: { display: true, text: t('enterprise.outlet_performance_chart_title'), }, tooltip: { callbacks: { label: function(context: any) { let label = context.dataset.label || ''; if (label) { label += ': '; } if (context.parsed.y !== null) { if (metric === 'sales') { label += `€${context.parsed.y.toFixed(2)}`; } else { label += context.parsed.y; } } return label; } } } }, scales: { x: { title: { display: true, text: t('enterprise.outlet'), }, }, y: { title: { display: true, text: t(`enterprise.metric_labels.${metric}`) || metric, }, beginAtZero: true, }, }, }; return (
{t('enterprise.performance_based_on', { metric: t(`enterprise.metrics.${metric}`) || metric, period })}
{data && data.length > 0 ? (
) : (
{t('enterprise.no_performance_data')}
)} {/* Performance ranking table */}

{t('enterprise.ranking')}

{data?.map((item, index) => ( ))}
{t('enterprise.rank')} {t('enterprise.outlet')} {t(`enterprise.metric_labels.${metric}`) || metric}
{item.rank} {item.anonymized_name} {metric === 'sales' ? `€${item.metric_value.toFixed(2)}` : item.metric_value}
); };