import { Table2 } from 'lucide-react'
import { useState, type ReactNode } from 'react'
import { panel } from '../styles'
export interface LegendItem {
label: string
color: string
shape?: 'rect' | 'line'
}
export interface TableData {
columns: string[]
rows: (string | number)[][]
}
/**
* Card for one chart: title, legend (2+ series), and a table view that shows every value, so
* nothing depends on hovering or on telling colors apart.
*/
export function ChartFrame({ title, subtitle, legend, table, children, className = '' }: { title: string; subtitle?: string; legend?: LegendItem[]; table: TableData; children: ReactNode; className?: string }) {
const [showTable, setShowTable] = useState(false)
return (
{subtitle}
{legend.map((item) => (
)}
{showTable ?
| {column} | ))}
|---|
| {typeof cell === 'number' ? cell.toLocaleString('en-US', { maximumFractionDigits: 2 }) : cell} | ))}
{title}
{rows.map((row) => ({row.color && } {row.value} {row.label}
))}