'use client'; import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer, PieChart, Pie, Cell, Legend, } from 'recharts'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; interface ExtractionEntity { extraction_class: string; extraction_text: string; attributes?: Record; } interface EntityChartProps { extractions: ExtractionEntity[]; title?: string; } const COLORS = [ 'hsl(var(--chart-1))', 'hsl(var(--chart-2))', 'hsl(var(--chart-3))', 'hsl(var(--chart-4))', 'hsl(var(--chart-5))', ]; export function EntityBarChart({ extractions, title = 'Entities by Class' }: EntityChartProps) { const classCounts = extractions.reduce( (acc, e) => { acc[e.extraction_class] = (acc[e.extraction_class] || 0) + 1; return acc; }, {} as Record ); const data = Object.entries(classCounts) .map(([name, count]) => ({ name, count })) .sort((a, b) => b.count - a.count); if (data.length === 0) return null; return ( {title} ); } export function EntityPieChart({ extractions, title = 'Class Distribution' }: EntityChartProps) { const classCounts = extractions.reduce( (acc, e) => { acc[e.extraction_class] = (acc[e.extraction_class] || 0) + 1; return acc; }, {} as Record ); const data = Object.entries(classCounts) .map(([name, value]) => ({ name, value })) .sort((a, b) => b.value - a.value); if (data.length === 0) return null; return ( {title} `${name} (${((percent ?? 0) * 100).toFixed(0)}%)`} labelLine={false} fontSize={11} > {data.map((_, idx) => ( ))} ); } export function EntityTimeline({ extractions }: { extractions: ExtractionEntity[] }) { if (extractions.length === 0) return null; return ( Entity Timeline
{extractions.slice(0, 20).map((e, i) => (
{ acc[ex.extraction_class] = true; return acc; }, {} as Record ) ).indexOf(e.extraction_class) % COLORS.length ], }} />
{e.extraction_class}

{e.extraction_text}

))}
); }