import { useState } from 'react';
import {
LineChart, Line, XAxis, YAxis, Tooltip,
Legend, ResponsiveContainer, ReferenceLine
} from 'recharts';
const CLUSTER_COLORS = [
'#f59e0b', '#3b82f6', '#22c55e', '#ef4444',
'#a855f7', '#06b6d4', '#f97316', '#ec4899',
'#84cc16', '#14b8a6',
];
export default function TimelineChart({ timeline }) {
const { buckets, cluster_ids, cluster_labels } = timeline;
const [hidden, setHidden] = useState(new Set());
if (!buckets || buckets.length === 0) {
return (
TIMELINE — ERROR FREQUENCY OVER TIME
No timestamp data available for timeline.
);
}
function toggleCluster(cid) {
setHidden(prev => {
const next = new Set(prev);
next.has(cid) ? next.delete(cid) : next.add(cid);
return next;
});
}
const CustomTooltip = ({ active, payload, label }) => {
if (!active || !payload?.length) return null;
return (
{label}
{payload.map(p => (
p.value > 0 && (
{cluster_labels[p.dataKey.replace('cluster_', '')]} — {p.value} errors
)
))}
);
};
return (
TIMELINE — ERROR FREQUENCY OVER TIME
{cluster_ids.map((cid, i) => (
toggleCluster(cid)}
style={{
cursor: 'pointer',
opacity: hidden.has(cid) ? 0.3 : 1,
transition: 'opacity 0.2s',
}}
>
{cluster_labels[cid]}
))}
} />
{cluster_ids.map((cid, i) => (
!hidden.has(cid) && (
)
))}
);
}