import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer, Cell, } from 'recharts'; import type { TopicCluster } from '../../types'; interface TopicBarChartProps { topics: TopicCluster[]; height?: number; } const COLORS = [ '#6366f1', '#8b5cf6', '#a855f7', '#d946ef', '#ec4899', '#f43f5e', '#f97316', '#eab308', '#22c55e', '#14b8a6', '#06b6d4', '#3b82f6', ]; export function TopicBarChart({ topics, height = 300 }: TopicBarChartProps) { const data = topics .filter((t) => t.topic_id !== -1) .sort((a, b) => b.size - a.size) .slice(0, 15) .map((t) => ({ name: t.label.length > 25 ? t.label.slice(0, 25) + '…' : t.label, size: t.size, sentiment: t.avg_sentiment, topic_id: t.topic_id, })); if (!data.length) { return (
No topics found
); } return ( { if (name === 'size') return [value, 'Entries']; return [value.toFixed(3), 'Avg Sentiment']; }} /> {data.map((_, index) => ( ))} ); }