| 1 | "use client" |
| 2 | |
| 3 | import { createContext, use } from "react" |
| 4 | import type { Seed |
| 5 | |
| 6 | /** A single tooltip row - one series (cartesian/radar) or one slice (pie). */ |
| 7 | export type TooltipItem |
| 8 | name: string |
| 9 | label: string |
| 10 | value: number |
| 11 | seed: Seed |
| 12 | dimmed: boolean |
| 13 | } |
| 14 | |
| 15 | /** |
| 16 | * The minimal surface shared by every chart family, so `<Legend>` and |
| 17 | * `<Tooltip>` work identically whether they sit in a cartesian, bar, or polar |
| 18 | * root. Each root publishes one of these alongside its family-specific context. |
| 19 | */ |
| 20 | export type CommonChart |
| 21 | names: string |
| 22 | labelOf: (name |
| 23 | seedOf: (name |
| 24 | selectedDataKey: string |
| 25 | selectDataKey: (key |
| 26 | /** Transient legend-hover emphasis - spotlights one series (others dim) |
| 27 | * while the pointer rests on its legend entry. Selection still wins. */ |
| 28 | focusDataKey: string |
| 29 | setFocusDataKey: (key |
| 30 | hoverIndex: number |
| 31 | heading: (index |
| 32 | itemsAt: (index |
| 33 | ready: boolean |
| 34 | tooltipLeft: number |
| 35 | tooltipTop: number |
| 36 | } |
| 37 | |
| 38 | export const CommonChartContext = |
| 39 | |
| 40 | export function useCommonChart() |
| 41 | const ctx = |
| 42 | if (!ctx) |
| 43 | throw new Error( |
| 44 | "<Legend /> / <Tooltip /> must be used within a chart root." |
| 45 | ) |
| 46 | } |
| 47 | return ctx |
| 48 | } |