{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "chart",
  "title": "Chart",
  "description": "A chart drawn in the theme's colors, which people can use without seeing it: a figure named by its `title`, a summary for screen readers, and a table of every value (visible with `showTable`).",
  "dependencies": [
    "recharts@^3.10.1"
  ],
  "registryDependencies": [
    "@ouro/lib-class-name-check",
    "@ouro/lib-cn",
    "@ouro/lib-dev",
    "@ouro/lib-env",
    "@ouro/lib-scroll-fade",
    "@ouro/lib-use-dev-messages"
  ],
  "files": [
    {
      "path": "registry/ouro/components/ouro/chart/chart-styles.ts",
      "content": "export { chartTones, defaultFormatValue, defaultSummary, isCssName, markerShapes, plotClass, toneVar };\nexport type { ChartMarkerShape, ChartSummaryInfo, ChartTone, ChartType };\n\n// The export list comes first because the shadcn CLI drops comments before a file's\n// first statement, which would take the JSDoc below with it.\n\n/**\n * The colors a series can take: the theme's five chart tokens (`--chart-1` to\n * `--chart-5`, which shadcn themes define for light and dark), and the tones for series\n * that mean something, such as failures in `destructive`.\n * @claim \"The colors a series can take\" registry/ouro/components/ouro/chart/chart.test.tsx verify:testExists(registry/ouro/components/ouro/chart/chart.test.tsx::Chart > colors each series from the theme's chart tokens, in light and dark)\n * @claim \"The colors a series can take\" registry/ouro/components/ouro/chart/chart.test.tsx verify:testExists(registry/ouro/components/ouro/chart/chart.test.tsx::Chart > maps tones to theme tokens and gives series without one the chart tokens in order)\n */\ntype ChartTone = \"chart-1\" | \"chart-2\" | \"chart-3\" | \"chart-4\" | \"chart-5\" | \"primary\" | \"destructive\" | \"success\" | \"warning\";\n\n/**\n * What `Chart` draws when it has no children.\n *\n * @claim \"What `Chart` draws when it has\" registry/ouro/components/ouro/chart/chart.test.tsx verify:testExists(registry/ouro/components/ouro/chart/chart.test.tsx::Chart > draws lines with a different point shape per series)\n * @claim \"What `Chart` draws when it has\" registry/ouro/components/ouro/chart/chart.test.tsx verify:testExists(registry/ouro/components/ouro/chart/chart.test.tsx::Chart > draws areas)\n */\ntype ChartType = \"bar\" | \"line\" | \"area\";\n\n/** What a `Chart` summary is written from. */\ninterface ChartSummaryInfo {\n  /** The chart's title. */\n  title: string;\n  /** What the props draw, or `undefined` for a chart passed as children. */\n  type: ChartType | undefined;\n  /**\n   * Each series' label, in config order.\n   *\n   * @claim \"Each series' label, in config order\" registry/ouro/components/ouro/chart/chart.test.tsx verify:testExists(registry/ouro/components/ouro/chart/chart.test.tsx::Chart > labels each series in a legend with a marker shape, so color is not the only cue)\n   */\n  series: string[];\n  /** The category's label: the `config` label for `categoryKey`, or the key itself. */\n  category: string;\n  /** How many rows `data` has. */\n  count: number;\n}\n\n/**\n * The tones a series can take, mapped to the theme variable each reads.\n *\n * @internal\n * @claim \"The tones a series can take\" registry/ouro/components/ouro/chart/chart.test.tsx verify:testExists(registry/ouro/components/ouro/chart/chart.test.tsx::Chart > maps tones to theme tokens and gives series without one the chart tokens in order)\n */\nconst chartTones: Readonly<Record<ChartTone, string>> = {\n  \"chart-1\": \"var(--chart-1)\",\n  \"chart-2\": \"var(--chart-2)\",\n  \"chart-3\": \"var(--chart-3)\",\n  \"chart-4\": \"var(--chart-4)\",\n  \"chart-5\": \"var(--chart-5)\",\n  primary: \"var(--primary)\",\n  destructive: \"var(--destructive)\",\n  success: \"var(--success)\",\n  warning: \"var(--warning)\",\n};\n\n/**\n * The theme variable for a tone, or for the series' place in order when it has none.\n *\n * @internal\n * @claim \"The theme variable for a tone\" registry/ouro/components/ouro/chart/chart.test.tsx verify:testExists(registry/ouro/components/ouro/chart/chart.test.tsx::Chart > maps tones to theme tokens and gives series without one the chart tokens in order)\n */\nfunction toneVar(tone: string | undefined, index: number): string {\n  return tone !== undefined && Object.hasOwn(chartTones, tone) ? chartTones[tone as ChartTone] : `var(--chart-${(index % 5) + 1})`;\n}\n\n/**\n * The marker each series gets in the legend, the tooltip and on line points, in order.\n *\n * @claim \"The marker each series gets in\" registry/ouro/components/ouro/chart/chart.test.tsx verify:testExists(registry/ouro/components/ouro/chart/chart.test.tsx::Chart > labels each series in a legend with a marker shape, so color is not the only cue)\n * @claim \"The marker each series gets in\" registry/ouro/components/ouro/chart/chart.test.tsx verify:testExists(registry/ouro/components/ouro/chart/chart.test.tsx::Chart > gives five series five marker shapes)\n */\ntype ChartMarkerShape = \"circle\" | \"square\" | \"triangle\" | \"diamond\" | \"cross\";\n\n/**\n * Marker shapes in series order, so series differ by shape as well as color.\n *\n * @internal\n */\nconst markerShapes: readonly ChartMarkerShape[] = [\"circle\", \"square\", \"triangle\", \"diamond\", \"cross\"];\n\n/**\n * Whether a config key can be part of a CSS custom property name (`--color-<key>`).\n *\n * @internal\n */\nconst isCssName = (key: string): boolean => /^[A-Za-z_][\\w-]*$/.test(key);\n\nconst numbers = new Intl.NumberFormat(\"en\");\n\n/**\n * \"1,250\": the value in English digits, which apps replace with `formatValue`.\n *\n * @internal\n */\nfunction defaultFormatValue(value: number): string {\n  return numbers.format(value);\n}\n\n/** \"A\", \"A and B\", \"A, B and C\". */\nfunction listOf(items: string[]): string {\n  return items.length < 2 ? (items[0] ?? \"\") : `${items.slice(0, -1).join(\", \")} and ${items.at(-1)}`;\n}\n\nconst typeNames: Readonly<Record<ChartType, string>> = { bar: \"Bar chart\", line: \"Line chart\", area: \"Area chart\" };\n\n/**\n * \"Bar chart of Cooked and Saved by Month, 3 points. The table that follows lists every value.\"\n *\n * @internal\n * @claim \"The table that follows lists every\" registry/ouro/components/ouro/chart/chart.test.tsx verify:testExists(registry/ouro/components/ouro/chart/chart.test.tsx::Chart > lists every value in a table for screen readers, visible with showTable)\n * @claim \"Bar chart of Cooked and Saved by Month,\" registry/ouro/components/ouro/chart/chart.test.tsx verify:testExists(registry/ouro/components/ouro/chart/chart.test.tsx::Chart > describes itself with a summary that points to the data table, which the app can translate)\n */\nfunction defaultSummary({ type, series, category, count }: ChartSummaryInfo): string {\n  const kind = type ? typeNames[type] : \"Chart\";\n  return `${kind} of ${listOf(series)} by ${category}, ${count} ${count === 1 ? \"point\" : \"points\"}. The table that follows lists every value.`;\n}\n\n/**\n * The plot area: recharts' default grays replaced with theme tokens, a visible focus ring on\n * the plot (which takes the arrow keys), and no focus outline on the shapes inside it.\n *\n * @internal\n * @claim \"The plot area: recharts' default grays\" registry/ouro/components/ouro/chart/chart.test.tsx verify:testExists(registry/ouro/components/ouro/chart/chart.test.tsx::Chart > shows the tooltip from the keyboard: Tab to the plot, then the arrow keys)\n * @claim \"The plot area: recharts' default grays\" registry/ouro/components/ouro/chart/chart.test.tsx verify:testExists(registry/ouro/components/ouro/chart/chart.test.tsx::Chart > takes a recharts chart as children, giving it the data, the name and the theme)\n * @claim \"The plot area: recharts' default grays\" registry/ouro/components/ouro/chart/chart.test.tsx verify:testExists(registry/ouro/components/ouro/chart/chart.test.tsx::Chart > writes the axis labels in the theme's muted text color, not recharts' gray, in light and dark)\n */\nconst plotClass =\n  \"relative aspect-video min-h-0 w-full flex-1 text-xs \" +\n  \"[&_.recharts-cartesian-axis-tick-value]:fill-muted-foreground \" +\n  \"[&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border \" +\n  \"[&_.recharts-curve.recharts-tooltip-cursor]:stroke-border \" +\n  \"[&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted \" +\n  \"[&_.recharts-reference-line_[stroke='#ccc']]:stroke-border \" +\n  \"[&_.recharts-dot[stroke='#fff']]:stroke-transparent \" +\n  \"[&_.recharts-layer]:outline-hidden [&_.recharts-sector]:outline-hidden \" +\n  \"[&_.recharts-surface]:rounded-ouro-md [&_.recharts-surface]:outline-ring [&_.recharts-surface]:outline-offset-2 \" +\n  \"[&_.recharts-surface:focus-visible]:outline-2 [&_.recharts-surface:focus-visible]:outline-solid\";\n",
      "type": "registry:ui",
      "target": "@components/ouro/chart/chart-styles.ts"
    },
    {
      "path": "registry/ouro/components/ouro/chart/chart.tsx",
      "content": "\"use client\";\n\nimport { Children, cloneElement, createContext, isValidElement, useContext, useId, useMemo, useRef, useState } from \"react\";\nimport type { CSSProperties, HTMLAttributes, JSX, ReactElement, ReactNode, Ref } from \"react\";\nimport { Area, AreaChart, Bar, BarChart, CartesianGrid, Legend, Line, LineChart, ResponsiveContainer, Tooltip, XAxis, YAxis } from \"recharts\";\nimport { useAppearanceClassNameCheck } from \"@/registry/ouro/lib/ouro/class-name-check\";\nimport { cn } from \"@/registry/ouro/lib/ouro/cn\";\nimport { devThrow } from \"@/registry/ouro/lib/ouro/dev\";\nimport { scrollFadeClass, useScrollFade } from \"@/registry/ouro/lib/ouro/scroll-fade\";\nimport { useDevWarnings, type DevWarning } from \"@/registry/ouro/lib/ouro/use-dev-messages\";\nimport {\n  chartTones,\n  defaultFormatValue,\n  defaultSummary,\n  isCssName,\n  markerShapes,\n  plotClass,\n  toneVar,\n  type ChartMarkerShape,\n  type ChartSummaryInfo,\n  type ChartTone,\n  type ChartType,\n} from \"@/registry/ouro/components/ouro/chart/chart-styles\";\n\nexport type { ChartMarkerShape, ChartSummaryInfo, ChartTone, ChartType } from \"@/registry/ouro/components/ouro/chart/chart-styles\";\n\n/** One series in a chart's `config`: its label and the theme tone it is drawn in. */\nexport interface ChartSeries {\n  /** What the series is called in the legend, the tooltip and the data table: \"Recipes cooked\". */\n  label: string;\n  /**\n   * The theme color: `chart-1` to `chart-5`, or a tone that means something (`destructive`\n   * for failures). Without it, series take `chart-1`, `chart-2` and so on, in order.\n   */\n  tone?: ChartTone | (string & { 'Use \"chart-1\" to \"chart-5\", \"primary\", \"destructive\", \"success\" or \"warning\"': never }) | undefined;\n\n  /** Not a prop. Colors come from the theme: `{ label: \"Cooked\", tone: \"chart-1\" }`. */\n  color?: { 'Colors come from the theme. Use { label: \"Cooked\", tone: \"chart-1\" }': never };\n  /** Not a prop. Light and dark colors come from the theme's chart tokens: `{ label: \"Cooked\", tone: \"chart-1\" }`. */\n  theme?: { 'Colors come from the theme. Use { label: \"Cooked\", tone: \"chart-1\" }': never };\n}\n\n/**\n * The series a chart draws, by their key in each row, as in shadcn's `ChartConfig`. Each key\n * also names a CSS variable, `--color-<key>`, for recharts children\n * (`fill=\"var(--color-cooked)\"`). A label for `categoryKey` names the category column.\n * @claim \"The series a chart draws, by\" registry/ouro/components/ouro/chart/chart.test.tsx verify:testExists(registry/ouro/components/ouro/chart/chart.test.tsx::Chart > draws lines with a different point shape per series)\n * @claim \"The series a chart draws, by\" registry/ouro/components/ouro/chart/chart.test.tsx verify:testExists(registry/ouro/components/ouro/chart/chart.test.tsx::Chart > colors each series from the theme's chart tokens, in light and dark)\n * @claim \"Each key also names a CSS\" registry/ouro/components/ouro/chart/chart.test.tsx verify:testExists(registry/ouro/components/ouro/chart/chart.test.tsx::Chart > takes a recharts chart as children, giving it the data, the name and the theme)\n */\nexport type ChartConfig<Row extends object = Record<string, unknown>> = { [Key in keyof Row & string]?: ChartSeries };\n\n/** The props Chart adds to the `<figure>` attributes it passes through. */\nexport interface ChartOwnProps<Row extends object = Record<string, unknown>> {\n  /** What the chart shows: \"Recipes cooked per month\". Its name for screen readers, shown above it. Required. */\n  title: string;\n  /** Hides the title visually; screen readers still hear it. */\n  hideTitle?: boolean | undefined;\n  /** A line under the title, such as the period: \"January to June\". */\n  description?: ReactNode;\n  /** The rows to draw, one per category (a month, a recipe). */\n  data: readonly Row[];\n  /**\n   * The key in each row that names its category: the x axis and the table's first column.\n   *\n   * @claim \"The key in each row that\" registry/ouro/components/ouro/chart/chart.test.tsx verify:testExists(registry/ouro/components/ouro/chart/chart.test.tsx::Chart > formats values with formatValue in the table, the axis and the tooltip)\n   */\n  categoryKey: keyof Row & string;\n  /**\n   * The series to draw, by their key in each row, with their labels and tones.\n   *\n   * @claim \"The series to draw, by their\" registry/ouro/components/ouro/chart/chart.test.tsx verify:testExists(registry/ouro/components/ouro/chart/chart.test.tsx::Chart > maps tones to theme tokens and gives series without one the chart tokens in order)\n   * @claim \"The series to draw, by their\" registry/ouro/components/ouro/chart/chart.test.tsx verify:testExists(registry/ouro/components/ouro/chart/chart.test.tsx::Chart > labels each series in a legend with a marker shape, so color is not the only cue)\n   */\n  config: ChartConfig<Row>;\n  /**\n   * What to draw when there are no children: bars, lines or areas, one per series. @default \"bar\"\n   *\n   * @claim \"What to draw when there are\" registry/ouro/components/ouro/chart/chart.test.tsx verify:testExists(registry/ouro/components/ouro/chart/chart.test.tsx::Chart > draws lines with a different point shape per series)\n   * @claim \"What to draw when there are\" registry/ouro/components/ouro/chart/chart.test.tsx verify:testExists(registry/ouro/components/ouro/chart/chart.test.tsx::Chart > draws areas)\n   */\n  type?: ChartType | (string & { 'Use \"bar\", \"line\" or \"area\"; for another chart pass recharts children': never }) | undefined;\n  /**\n   * A recharts chart (`<LineChart>`) for anything `type` cannot draw. It gets `data`, the\n   * title as its name and the theme colors as `var(--color-<key>)`; add `<ChartTooltip />`\n   * and `<ChartLegend />` inside it.\n   */\n  children?: ReactNode;\n  /**\n   * Writes a value for the axis, the tooltip and the table, for other languages or units.\n   * `series` is the value's key in `config`, and `\"\"` for the y axis, which all series share.\n   * @default \"1,250\"\n   * @claim \"`series` is the value's key in\" registry/ouro/components/ouro/chart/chart.test.tsx verify:testExists(registry/ouro/components/ouro/chart/chart.test.tsx::Chart > formats values with formatValue in the table, the axis and the tooltip)\n   */\n  formatValue?: ((value: number, series: string) => string) | undefined;\n  /**\n   * What screen readers hear about the chart after its title, for other languages.\n   * @default (info) => \"Bar chart of Cooked and Saved by Month, 3 points. The table that follows lists every value.\"\n   */\n  summary?: ((info: ChartSummaryInfo) => string) | undefined;\n  /**\n   * Shows the data table under the chart. It is always there for screen readers.\n   *\n   * @claim \"It is always there for screen\" registry/ouro/components/ouro/chart/chart.test.tsx verify:testExists(registry/ouro/components/ouro/chart/chart.test.tsx::Chart > lists every value in a table for screen readers, visible with showTable)\n   */\n  showTable?: boolean | undefined;\n  /**\n   * Layout only: the chart's height (`h-64`, `aspect-square`), margins. The plot is 16:9\n   * until you set a height. Appearance classes warn in development.\n   * @claim \"The plot is 16:9 until you\" registry/ouro/components/ouro/chart/chart-styles.ts verify:fileLine(registry/ouro/components/ouro/chart/chart-styles.ts, /aspect-video/)\n   */\n  className?: string | undefined;\n  ref?: Ref<HTMLElement> | undefined;\n}\n\n/** Props for {@link Chart}: its own props and the `<figure>` attributes it passes through. */\nexport type ChartProps<Row extends object = Record<string, unknown>> = Omit<HTMLAttributes<HTMLElement>, keyof ChartOwnProps<Row> | \"role\"> &\n  ChartOwnProps<Row>;\n\n/** Props for {@link ChartTooltip}. */\nexport interface ChartTooltipProps {\n  /** Not a prop. ChartTooltip draws its own content from the chart's config: `<ChartTooltip />`. */\n  content?: { 'ChartTooltip draws its content from config. Use <ChartTooltip />': never };\n}\n\n/** Props for {@link ChartLegend}. */\nexport interface ChartLegendProps {\n  /** Not a prop. ChartLegend draws its own content from the chart's config: `<ChartLegend />`. */\n  content?: { 'ChartLegend draws its content from config. Use <ChartLegend />': never };\n}\n\ninterface Series {\n  key: string;\n  label: string;\n  color: string;\n  shape: ChartMarkerShape;\n}\n\ninterface ChartState {\n  byKey: Map<string, Series>;\n  formatValue: (value: number, series: string) => string;\n  /** The element a `ChartLegend` portals its list into, below the plot; `null` until it mounts. */\n  legendTarget: HTMLElement | null;\n}\n\nconst ChartContext = createContext<ChartState | null>(null);\n\nconst types = [\"bar\", \"line\", \"area\"] as const;\nconst toneNames = Object.keys(chartTones);\n\n/** The JSX a part belongs in, for the dev message when it is not inside a Chart. */\nconst partShape = (part: string) => `<Chart title=\"Cooking\" data={rows} categoryKey=\"month\" config={config}><BarChart><${part} /></BarChart></Chart>`;\n\nfunction useChartPart(part: string): ChartState {\n  const state = useContext(ChartContext);\n  if (!state) {\n    devThrow(part, \"must be rendered inside <Chart>\", process.env.NODE_ENV !== \"production\" ? partShape(part) : /* istanbul ignore next @preserve -- production only */ \"\");\n  }\n  return state;\n}\n\n/**\n * The series in config order: every key but the category, each with its color and marker.\n *\n * @claim \"The series in config order: every\" registry/ouro/components/ouro/chart/chart.test.tsx verify:testExists(registry/ouro/components/ouro/chart/chart.test.tsx::Chart > labels each series in a legend with a marker shape, so color is not the only cue)\n * @claim \"The series in config order: every\" registry/ouro/components/ouro/chart/chart.test.tsx verify:testExists(registry/ouro/components/ouro/chart/chart.test.tsx::Chart > leaves series that are not in config out of the tooltip and the legend)\n */\nfunction seriesOf(config: Record<string, ChartSeries | undefined>, categoryKey: string): Series[] {\n  return Object.entries(config)\n    .filter((entry): entry is [string, ChartSeries] => entry[0] !== categoryKey && entry[1] !== undefined)\n    .map(([key, entry], index) => ({ key, label: entry.label, color: toneVar(entry.tone, index), shape: markerShapes[index % markerShapes.length]! }));\n}\n\nfunction chartWarnings(props: ChartProps<Record<string, unknown>>, series: Series[]): DevWarning[] {\n  const { title, data, categoryKey, config, type, children } = props;\n  const rows = data as ReadonlyArray<Record<string, unknown>>;\n  const entries = Object.entries(config as Record<string, ChartSeries>);\n  return [\n    title === undefined && [\"title is missing, so the chart has no name\", '<Chart title=\"Recipes cooked per month\">'],\n    type !== undefined && !(types as readonly string[]).includes(type) && [`type=\"${type}\" is not a chart type; use \"bar\", \"line\" or \"area\"`, '<Chart type=\"bar\">'],\n    series.length === 0 && [\"config has no series to draw\", '<Chart config={{ cooked: { label: \"Cooked\" } }}>'],\n    rows.length > 0 && !rows.some((row) => Object.hasOwn(row, categoryKey)) && [`categoryKey=\"${categoryKey}\" is not a key of the rows`, `<Chart categoryKey=\"${Object.keys(rows[0]!)[0]}\">`],\n    ...entries.flatMap(([key, entry]): DevWarning[] => {\n      const raw = entry as unknown as Record<string, unknown>;\n      return [\n        raw[\"tone\"] !== undefined &&\n          !toneNames.includes(String(raw[\"tone\"])) && [\n            `tone \"${String(raw[\"tone\"])}\" for ${key} is not a tone; use \"chart-1\" to \"chart-5\", \"primary\", \"destructive\", \"success\" or \"warning\"`,\n            `{ ${key}: { label: \"${String(raw[\"label\"])}\", tone: \"chart-1\" } }`,\n          ],\n        ...([\"color\", \"theme\"] as const).map(\n          (name): DevWarning => raw[name] !== undefined && [`config.${key}.${name} is not a prop; series colors come from the theme`, `{ ${key}: { label: \"${String(raw[\"label\"])}\", tone: \"chart-1\" } }`],\n        ),\n        !isCssName(key) && [`config key \"${key}\" is not a CSS name, so var(--color-${key}) cannot work`, `{ ${key.replace(/\\W/g, \"_\")}: { label: \"${String(raw[\"label\"])}\" } }`],\n        key !== categoryKey &&\n          children === undefined &&\n          rows.length > 0 &&\n          !rows.some((row) => Object.hasOwn(row, key)) && [`config.${key} has no values in data`, '<Chart config={{ cooked: { label: \"Cooked\" } }}> with keys that are in each row'],\n      ];\n    }),\n  ];\n}\n\n/**\n * A chart drawn in the theme's colors, which people can use without seeing it: a figure\n * named by its `title`, a summary for screen readers, and a table of every value (visible\n * with `showTable`). The plot is a tab stop, and the arrow keys move its tooltip from point\n * to point. Each series is labeled in a legend with its own marker shape, so color is\n * never the only cue.\n *\n * Pass `type` for bars, lines or areas, one per series in `config`. For anything else, pass\n * a recharts chart as children with `<ChartTooltip />` and `<ChartLegend />` inside it, as in\n * shadcn's charts; it draws with `var(--color-<key>)`. The marks Chart draws itself appear at\n * once; your own `<Line>` or `<Bar>` keeps recharts' draw-in unless you pass\n * `isAnimationActive={false}`.\n *\n * Built on recharts, which Bundlephobia measures at about 150 KB gzip (566 KB minified) for\n * the whole package; a bundler that drops what Chart does not import adds less to the page\n * that renders it. Load it with `next/dynamic` or `React.lazy` when the chart is below the\n * fold.\n *\n * Colors come from the theme's `--chart-1` to `--chart-5`, which must reach 3:1 against the\n * background for the marks to be seen (WCAG's non-text contrast).\n *\n * Use `Progress` instead for one value out of a total, and a table alone when readers\n * need exact figures more than the shape of the data.\n *\n * @group Data\n * @see https://ui.ouroboros.bot/docs/chart\n *\n * @example\n * <Chart\n *   title=\"Recipes cooked per month\"\n *   data={months}\n *   categoryKey=\"month\"\n *   config={{ cooked: { label: \"Cooked\" }, saved: { label: \"Saved\", tone: \"chart-2\" } }}\n * />\n * @claim \"A chart drawn in the theme's\" registry/ouro/components/ouro/chart/chart.test.tsx verify:testExists(registry/ouro/components/ouro/chart/chart.test.tsx::Chart > lists every value in a table for screen readers, visible with showTable)\n * @claim \"A chart drawn in the theme's\" registry/ouro/components/ouro/chart/chart.test.tsx verify:testExists(registry/ouro/components/ouro/chart/chart.test.tsx::Chart > renders its title, summary and table in server HTML and hydrates without a warning)\n * @claim \"A chart drawn in the theme's\" registry/ouro/components/ouro/chart/chart.test.tsx verify:testExists(registry/ouro/components/ouro/chart/chart.test.tsx::Chart > colors each series from the theme's chart tokens, in light and dark)\n * @claim \"Colors come from the theme's `--chart-1`\" registry/ouro/components/ouro/chart/chart.test.tsx verify:testExists(registry/ouro/components/ouro/chart/chart.test.tsx::Chart > colors each series from the theme's chart tokens, in light and dark)\n * @claim \"Colors come from the theme's `--chart-1`\" https://bundlephobia.com/package/recharts@3.10.1 verify:urlOk(https://bundlephobia.com/package/recharts@3.10.1)\n * @claim \"Colors come from the theme's `--chart-1`\" https://www.w3.org/TR/WCAG22/#non-text-contrast verify:urlOk(https://www.w3.org/TR/WCAG22/#non-text-contrast)\n * @claim \"Each series is labeled in a\" registry/ouro/components/ouro/chart/chart.test.tsx verify:testExists(registry/ouro/components/ouro/chart/chart.test.tsx::Chart > labels each series in a legend with a marker shape, so color is not the only cue)\n * @claim \"Each series is labeled in a\" registry/ouro/components/ouro/chart/chart.test.tsx verify:testExists(registry/ouro/components/ouro/chart/chart.test.tsx::Chart > gives five series five marker shapes)\n * @claim \"Built on recharts, which Bundlephobia measures\" https://bundlephobia.com/package/recharts@3.10.1 verify:urlOk(https://bundlephobia.com/package/recharts@3.10.1)\n */\nexport function Chart<Row extends object = Record<string, unknown>>(props: ChartProps<Row>): JSX.Element {\n  const {\n    title,\n    hideTitle = false,\n    description,\n    data,\n    categoryKey,\n    config,\n    type: typeProp,\n    children,\n    formatValue = defaultFormatValue,\n    summary = defaultSummary,\n    showTable = false,\n    className,\n    style,\n    ...rest\n  } = props;\n  const type: ChartType = (types as readonly string[]).includes(typeProp ?? \"bar\") ? (typeProp as ChartType | undefined) ?? \"bar\" : \"bar\";\n  const entries = config as Record<string, ChartSeries | undefined>;\n  // The series once per config and category, so the memos built on them hold.\n  const series = useMemo(() => seriesOf(entries, categoryKey), [entries, categoryKey]);\n  const category = entries[categoryKey]?.label ?? categoryKey;\n  const rows = data as ReadonlyArray<Record<string, unknown>>;\n  useAppearanceClassNameCheck(\n    \"Chart\",\n    className,\n    process.env.NODE_ENV !== \"production\" ? (token: string) => `<div className=\"${token}\"><Chart /></div>` : /* istanbul ignore next @preserve -- production only */ \"\",\n  );\n  useDevWarnings(\n    \"Chart\",\n    process.env.NODE_ENV !== \"production\"\n      ? () => chartWarnings(props as unknown as ChartProps<Record<string, unknown>>, series)\n      : /* istanbul ignore next @preserve -- production only */ undefined,\n  );\n  const id = useId();\n  const summaryId = `${id}-summary`;\n  const tableRef = useRef<HTMLDivElement>(null);\n  useScrollFade(tableRef);\n  const [legendTarget, setLegendTarget] = useState<HTMLElement | null>(null);\n  // Indexed once per series and formatter, not on every render (a tooltip's move renders the chart).\n  const state = useMemo<ChartState>(\n    () => ({ byKey: new Map(series.map((item) => [item.key, item])), formatValue, legendTarget }),\n    [series, formatValue, legendTarget],\n  );\n  const colors = useMemo(() => Object.fromEntries(series.map((item) => [`--color-${item.key}`, item.color])) as CSSProperties, [series]);\n  // Recharts makes the plot a tab stop (role \"application\"), so it carries the control marker.\n  const plotProps = { \"aria-label\": title, \"aria-describedby\": summaryId, \"data-ouro-control\": \"chart\", \"data-ouro-part\": \"plot\" };\n  const child = Children.toArray(children).find(isValidElement) as ReactElement<{ data?: unknown }> | undefined;\n  const plot = child ? (\n    cloneElement(child, { data: child.props.data ?? data, ...plotProps })\n  ) : (\n    <SeriesChart type={type} data={rows} categoryKey={categoryKey} series={series} formatValue={formatValue} plotProps={plotProps} />\n  );\n  return (\n    <figure\n      {...rest}\n      data-ouro=\"chart\"\n      aria-describedby={[summaryId, rest[\"aria-describedby\"]].filter(Boolean).join(\" \")}\n      style={{ ...colors, ...style }}\n      className={cn(\"[@layer_ouro-reset]:m-0 box-border flex w-full min-w-0 flex-col gap-3 text-foreground\", className)}\n    >\n      <figcaption className={hideTitle ? \"sr-only\" : \"text-base font-semibold pointer-fine:text-sm\"}>{title}</figcaption>\n      {description !== undefined && <p className=\"-mt-2 mb-0 text-sm text-muted-foreground\">{description}</p>}\n      <div data-ouro-chart-plot=\"\" className={plotClass}>\n        <ChartContext value={state}>\n          <ResponsiveContainer width=\"100%\" height=\"100%\" initialDimension={{ width: 1, height: 1 }}>\n            {plot}\n          </ResponsiveContainer>\n        </ChartContext>\n      </div>\n      {/* Empty until a ChartLegend portals its list here, so it takes no gap. */}\n      <div ref={setLegendTarget} data-ouro-chart-legend-slot=\"\" className=\"empty:hidden\" />\n      <p id={summaryId} data-ouro-chart-summary=\"\" className=\"sr-only\">\n        {summary({ title, type: child ? undefined : type, series: series.map((item) => item.label), category, count: rows.length })}\n      </p>\n      {/* A table can't shrink below its content, so the wrapper is what hides it. */}\n      <div ref={tableRef} data-ouro-chart-table=\"\" className={showTable ? cn(\"max-w-full overflow-x-auto\", scrollFadeClass) : \"sr-only\"}>\n        <table className=\"w-full border-collapse text-sm tabular-nums\">\n          <caption className=\"sr-only\">{title}</caption>\n          <thead>\n            <tr className=\"border-b border-solid border-border\">\n              <th scope=\"col\" className=\"px-2 py-1.5 text-start font-medium\">\n                {category}\n              </th>\n              {series.map((item) => (\n                <th key={item.key} scope=\"col\" className=\"px-2 py-1.5 text-end font-medium\">\n                  {item.label}\n                </th>\n              ))}\n            </tr>\n          </thead>\n          <tbody>\n            {rows.map((row, index) => (\n              <tr key={index} className=\"border-b border-solid border-border last:border-0\">\n                <th scope=\"row\" className=\"px-2 py-1.5 text-start font-normal\">\n                  {String(row[categoryKey] ?? \"\")}\n                </th>\n                {series.map((item) => (\n                  <td key={item.key} className=\"px-2 py-1.5 text-end\">\n                    {typeof row[item.key] === \"number\" ? formatValue(row[item.key] as number, item.key) : String(row[item.key] ?? \"\")}\n                  </td>\n                ))}\n              </tr>\n            ))}\n          </tbody>\n        </table>\n      </div>\n    </figure>\n  );\n}\n\n/**\n * shadcn's name for {@link Chart}: the same component with the same props, so code ported\n * from shadcn's chart docs finds it. Unlike shadcn's, it needs a `title`, `data` and\n * `categoryKey`, which give the chart its name and its data table.\n *\n * Use `Chart` instead in new code; it is the same component.\n *\n * @group Data\n * @see https://ui.ouroboros.bot/docs/chart\n *\n * @example\n * <ChartContainer title=\"Recipes cooked\" data={months} categoryKey=\"month\" config={config}>\n *   <BarChart>\n *     <Bar dataKey=\"cooked\" fill=\"var(--color-cooked)\" />\n *     <ChartTooltip />\n *   </BarChart>\n * </ChartContainer>\n */\nexport function ChartContainer<Row extends object = Record<string, unknown>>(props: ChartProps<Row>): JSX.Element {\n  return <Chart {...props} />;\n}\n\ninterface SeriesChartProps {\n  type: ChartType;\n  data: ReadonlyArray<Record<string, unknown>>;\n  categoryKey: string;\n  series: Series[];\n  formatValue: (value: number, series: string) => string;\n  plotProps: Record<string, string>;\n}\n\n/**\n * The chart `type` draws: a grid, both axes, the tooltip, the legend for two or more series, and one mark per series.\n *\n * @claim \"The chart `type` draws: a grid\" registry/ouro/components/ouro/chart/chart.test.tsx verify:testExists(registry/ouro/components/ouro/chart/chart.test.tsx::Chart > draws lines with a different point shape per series)\n * @claim \"The chart `type` draws: a grid\" registry/ouro/components/ouro/chart/chart.test.tsx verify:testExists(registry/ouro/components/ouro/chart/chart.test.tsx::Chart > leaves series that are not in config out of the tooltip and the legend)\n * @claim \"The chart `type` draws: a grid\" registry/ouro/components/ouro/chart/chart.test.tsx verify:testExists(registry/ouro/components/ouro/chart/chart.test.tsx::Chart > leaves out the legend for a single series, which the title already names)\n */\nfunction SeriesChart({ type, data, categoryKey, series, formatValue, plotProps }: SeriesChartProps): JSX.Element {\n  const Plot = type === \"line\" ? LineChart : type === \"area\" ? AreaChart : BarChart;\n  const marks = series.map((item) => {\n    const shared = {\n      dataKey: item.key,\n      name: item.label,\n      className: `ouro-chart-series-${item.key}`,\n      // Series geometry would animate in JavaScript for 400 to 1500ms, outside the compositor and past the 300ms limit.\n      isAnimationActive: false,\n    };\n    if (type === \"bar\") return <Bar key={item.key} {...shared} fill={`var(--color-${item.key})`} radius={4} />;\n    const dot = (dotProps: DotProps) => <ShapeDot {...dotProps} series={item.key} shape={item.shape} />;\n    if (type === \"line\") return <Line key={item.key} {...shared} type=\"monotone\" stroke={`var(--color-${item.key})`} strokeWidth={2} dot={dot} activeDot={dot} />;\n    return (\n      <Area key={item.key} {...shared} type=\"monotone\" stroke={`var(--color-${item.key})`} fill={`var(--color-${item.key})`} fillOpacity={0.2} strokeWidth={2} dot={dot} activeDot={dot} />\n    );\n  });\n  return (\n    <Plot data={data as Record<string, unknown>[]} margin={{ top: 8, right: 8, bottom: 0, left: 0 }} {...plotProps}>\n      <CartesianGrid vertical={false} />\n      <XAxis dataKey={categoryKey} tickLine={false} axisLine={false} tickMargin={8} minTickGap={16} />\n      <YAxis tickLine={false} axisLine={false} tickMargin={8} width=\"auto\" tickFormatter={(value: number) => formatValue(value, \"\")} />\n      <ChartTooltip />\n      {series.length > 1 && <ChartLegend />}\n      {marks}\n    </Plot>\n  );\n}\n\ninterface DotProps {\n  cx?: number | undefined;\n  cy?: number | undefined;\n  stroke?: string | undefined;\n  index?: number | undefined;\n}\n\n/** A point on a line or area, in the series' marker shape. */\nfunction ShapeDot({ cx, cy, stroke, index, series, shape }: DotProps & { series: string; shape: ChartMarkerShape }): JSX.Element {\n  return (\n    <g key={index} data-ouro-chart-dot={shape} data-ouro-chart-series={series} transform={`translate(${cx} ${cy})`} color={stroke}>\n      <MarkerPath shape={shape} size={9} />\n    </g>\n  );\n}\n\n/**\n * A marker centered on 0,0, filled with the current color, outlined in the page's background.\n *\n * @claim \"A marker centered on 0,0, filled\" registry/ouro/components/ouro/chart/chart.test.tsx verify:testExists(registry/ouro/components/ouro/chart/chart.test.tsx::Chart > gives five series five marker shapes)\n */\nfunction MarkerPath({ shape, size }: { shape: ChartMarkerShape; size: number }): JSX.Element {\n  const r = size / 2;\n  const common = { fill: \"currentColor\", stroke: \"var(--background)\", strokeWidth: 1 };\n  if (shape === \"circle\") return <circle r={r} {...common} />;\n  if (shape === \"square\") return <rect x={-r * 0.9} y={-r * 0.9} width={r * 1.8} height={r * 1.8} rx={1} {...common} />;\n  if (shape === \"triangle\") return <path d={`M0 ${-r * 1.1}L${r * 1.05} ${r * 0.8}H${-r * 1.05}Z`} {...common} />;\n  if (shape === \"diamond\") return <path d={`M0 ${-r * 1.15}L${r * 1.15} 0L0 ${r * 1.15}L${-r * 1.15} 0Z`} {...common} />;\n  const t = r * 0.4;\n  return <path d={`M${-t} ${-r}H${t}V${-t}H${r}V${t}H${t}V${r}H${-t}V${t}H${-r}V${-t}H${-t}Z`} {...common} />;\n}\n\n/** A legend or tooltip marker: the series' shape in its color. */\nfunction Marker({ item }: { item: Series }): JSX.Element {\n  return (\n    <svg aria-hidden=\"true\" data-ouro-chart-marker={item.shape} viewBox=\"-6 -6 12 12\" className=\"size-3 shrink-0\" style={{ color: item.color }}>\n      <MarkerPath shape={item.shape} size={10} />\n    </svg>\n  );\n}\n\ninterface TooltipEntry {\n  dataKey?: unknown;\n  value?: unknown;\n}\n\n/**\n * The tooltip card: the category, then each series' marker, label and value. Series not in config are left out.\n *\n * @claim \"The tooltip card: the category, then\" registry/ouro/components/ouro/chart/chart.test.tsx verify:testExists(registry/ouro/components/ouro/chart/chart.test.tsx::Chart > labels each series in a legend with a marker shape, so color is not the only cue)\n * @claim \"The tooltip card: the category, then\" registry/ouro/components/ouro/chart/chart.test.tsx verify:testExists(registry/ouro/components/ouro/chart/chart.test.tsx::Chart > leaves series that are not in config out of the tooltip and the legend)\n */\nfunction TooltipContent({ active, payload, label }: { active: boolean; payload: readonly TooltipEntry[]; label: unknown }): JSX.Element | null {\n  const { byKey, formatValue } = useChartPart(\"ChartTooltip\");\n  const entries = payload.flatMap((entry) => {\n    const item = byKey.get(String(entry.dataKey));\n    return item ? [{ item, value: entry.value }] : [];\n  });\n  if (!active || entries.length === 0) return null;\n  // Recharts gives an active tooltip no label only for a moment, as when a chart is drawn under a\n  // resting pointer, which no test can hold; without the fallback the card would read \"undefined\".\n  /* istanbul ignore next @preserve -- a momentary Recharts state, above */\n  // Stryker disable next-line StringLiteral: the fallback shows only in that momentary state, which no test can hold.\n  const heading = String(label ?? \"\");\n  return (\n    // A polite live region (recharts' own card is assertive), so a screen reader in the plot\n    // hears each point the arrow keys reach.\n    <div\n      data-ouro-chart-tooltip=\"\"\n      role=\"status\"\n      aria-live=\"polite\"\n      className=\"grid min-w-32 gap-1.5 rounded-ouro-lg border border-solid border-border bg-popover px-2.5 py-1.5 text-xs text-popover-foreground shadow-(--shadow-lg)\"\n    >\n      <div className=\"font-medium\">{heading}</div>\n      {entries.map(({ item, value }) => (\n        <div key={item.key} className=\"flex items-center gap-2\">\n          <Marker item={item} />\n          <span className=\"text-muted-foreground\">{item.label}</span>\n          <span className=\"ms-auto ps-3 font-medium tabular-nums\">{formatValue(Number(value), item.key)}</span>\n        </div>\n      ))}\n    </div>\n  );\n}\n\n/**\n * The legend: each drawn series' marker and label from config, in a row under the plot.\n *\n * @claim \"The legend: each drawn series' marker\" registry/ouro/components/ouro/chart/chart.test.tsx verify:testExists(registry/ouro/components/ouro/chart/chart.test.tsx::Chart > labels each series in a legend with a marker shape, so color is not the only cue)\n * @claim \"The legend: each drawn series' marker\" registry/ouro/components/ouro/chart/chart.test.tsx verify:testExists(registry/ouro/components/ouro/chart/chart.test.tsx::Chart > leaves series that are not in config out of the tooltip and the legend)\n */\nfunction LegendContent({ payload }: { payload: readonly { dataKey?: unknown }[] }): JSX.Element {\n  const { byKey } = useChartPart(\"ChartLegend\");\n  const shown = payload.flatMap((entry) => byKey.get(String(entry.dataKey)) ?? []);\n  return (\n    <ul data-ouro-chart-legend=\"\" className=\"m-0 flex list-none flex-wrap items-center justify-center gap-x-4 gap-y-1 p-0 text-xs text-foreground\">\n      {shown.map((item) => (\n        <li key={item.key} className=\"flex items-center gap-1.5\">\n          <Marker item={item} />\n          {item.label}\n        </li>\n      ))}\n    </ul>\n  );\n}\n\n/**\n * The tooltip for a recharts chart inside `Chart`: the category, then each series' marker,\n * label and value from the chart's `config`, in the theme's popover colors. It follows the\n * pointer, and the arrow keys when the plot has focus. `Chart` adds it for you with `type`.\n *\n * Use `Chart` with `type` instead when bars, lines or areas are enough: it adds the tooltip\n * itself. Use it only inside a recharts chart passed to `Chart` as children.\n *\n * @group Data\n * @see https://ui.ouroboros.bot/docs/chart\n *\n * @example\n * <Chart title=\"Recipes cooked\" data={months} categoryKey=\"month\" config={config}>\n *   <LineChart>\n *     <Line dataKey=\"cooked\" stroke=\"var(--color-cooked)\" />\n *     <ChartTooltip />\n *   </LineChart>\n * </Chart>\n * @claim \"The tooltip for a recharts chart\" registry/ouro/components/ouro/chart/chart.test.tsx verify:testExists(registry/ouro/components/ouro/chart/chart.test.tsx::Chart > labels each series in a legend with a marker shape, so color is not the only cue)\n * @claim \"The tooltip for a recharts chart\" registry/ouro/components/ouro/chart/chart.test.tsx verify:testExists(registry/ouro/components/ouro/chart/chart.test.tsx::Chart > colors each series from the theme's chart tokens, in light and dark)\n */\nexport function ChartTooltip(props: ChartTooltipProps): JSX.Element {\n  const { content } = props;\n  useChartPart(\"ChartTooltip\");\n  useDevWarnings(\n    \"ChartTooltip\",\n    process.env.NODE_ENV !== \"production\"\n      ? () => [content !== undefined && [\"content is not a prop; ChartTooltip draws its content from config\", \"<ChartTooltip />\"]]\n      : /* istanbul ignore next @preserve -- production only */ undefined,\n  );\n  return <Tooltip cursor content={(tooltip) => <TooltipContent active={tooltip.active} payload={tooltip.payload as readonly TooltipEntry[]} label={tooltip.label} />} />;\n}\n\n/**\n * The legend for a recharts chart inside `Chart`: each series' marker shape and label from\n * the chart's `config`, under the plot. `Chart` adds it for you with `type` when it draws two\n * or more series.\n *\n * Use `Chart` with `type` instead when bars, lines or areas are enough: it adds the legend\n * itself. Use it only inside a recharts chart passed to `Chart` as children.\n *\n * @group Data\n * @see https://ui.ouroboros.bot/docs/chart\n *\n * @example\n * <Chart title=\"Recipes\" data={months} categoryKey=\"month\" config={config}>\n *   <BarChart>\n *     <Bar dataKey=\"cooked\" fill=\"var(--color-cooked)\" />\n *     <Bar dataKey=\"saved\" fill=\"var(--color-saved)\" />\n *     <ChartLegend />\n *   </BarChart>\n * </Chart>\n * @claim \"The legend for a recharts chart\" registry/ouro/components/ouro/chart/chart.test.tsx verify:testExists(registry/ouro/components/ouro/chart/chart.test.tsx::Chart > labels each series in a legend with a marker shape, so color is not the only cue)\n * @claim \"The legend for a recharts chart\" registry/ouro/components/ouro/chart/chart.test.tsx verify:testExists(registry/ouro/components/ouro/chart/chart.test.tsx::Chart > leaves out the legend for a single series, which the title already names)\n * @claim \"`Chart` adds it for you with\" registry/ouro/components/ouro/chart/chart.test.tsx verify:testExists(registry/ouro/components/ouro/chart/chart.test.tsx::Chart > leaves out the legend for a single series, which the title already names)\n * @claim \"`Chart` adds it for you with\" registry/ouro/components/ouro/chart/chart.test.tsx verify:testExists(registry/ouro/components/ouro/chart/chart.test.tsx::Chart > draws lines with a different point shape per series)\n */\nexport function ChartLegend(props: ChartLegendProps): JSX.Element | null {\n  const { content } = props;\n  const { legendTarget } = useChartPart(\"ChartLegend\");\n  useDevWarnings(\n    \"ChartLegend\",\n    process.env.NODE_ENV !== \"production\"\n      ? () => [content !== undefined && [\"content is not a prop; ChartLegend draws its content from config\", \"<ChartLegend />\"]]\n      : /* istanbul ignore next @preserve -- production only */ undefined,\n  );\n  // Recharts measures the plot before it renders its children, by which time the slot is mounted. A null\n  // target would make Legend fall back to the list inside the chart's own wrapper, so render nothing then.\n  /* istanbul ignore if @preserve -- the slot mounts before Recharts measures the plot, so a target is always set when this renders */\n  // Stryker disable next-line ConditionalExpression: the slot mounts before Recharts measures the plot, so this never runs with a null target and forcing it false changes nothing.\n  if (legendTarget === null) return null;\n  return <Legend verticalAlign=\"bottom\" portal={legendTarget} content={(legend) => <LegendContent payload={legend.payload as readonly { dataKey?: unknown }[]} />} />;\n}\n",
      "type": "registry:ui",
      "target": "@components/ouro/chart/chart.tsx"
    }
  ],
  "docs": "A chart drawn in the theme's colors, which people can use without seeing it: a figure named by its `title`, a summary for screen readers, and a table of every value (visible with `showTable`). Import: import { Chart } from \"@/components/ouro/chart/chart\", with @/components replaced by your components alias (aliases.components in components.json, such as ~/components). Also installed: the helpers it imports in lib/ouro. Needs ouro-base in your stylesheet: add that item once per app, from the same place as this one, if you have not. Docs: https://ui.ouroboros.bot/docs/chart.md Ouro UI v1.3.257.",
  "type": "registry:ui"
}