import { ink } from './palette.ts' export interface LegendItem { label: string color: string /** stroke-dasharray for a line swatch */ dash?: string shape?: 'line' | 'dot' | 'cross' /** e.g. the max error for this series, shown after the label */ value?: string } /** * Identity is never carried by colour alone: every series that appears in a * plot appears here too, and the ones the reader most needs are also labelled * directly on the plot. */ export default function Legend({ items, onHover, active, }: { items: LegendItem[] /** hovering an entry reports its index, so the plot can pick that curve out */ onHover?: (k: number | null) => void /** the entry to show as picked out; the others are dimmed */ active?: number | null }) { return (
onHover(null) : undefined}> {items.map((it, k) => ( onHover(k) : undefined} style={onHover ? { cursor: 'default' } : undefined} > {it.label} {it.value && {it.value}} ))}
) }