{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "opentui/line-chart",
  "title": "Line Chart",
  "description": "ASCII line chart with axes and multi-series support",
  "dependencies": [
    "@opentui/react"
  ],
  "registryDependencies": [
    "https://termcn.dev/r/opentui/use-theme.json"
  ],
  "files": [
    {
      "path": "registry/opentui/ui/line-chart.tsx",
      "content": "/* @jsxImportSource @opentui/react */\n\nimport { useTheme } from \"@/hooks/use-theme\";\n\nexport type LineChartDataPoint =\n  | number\n  | {\n      label?: string;\n      value: number;\n    };\n\nexport interface LineChartProps {\n  data: LineChartDataPoint[];\n  width?: number;\n  height?: number;\n  title?: string;\n  color?: string;\n  showAxes?: boolean;\n}\n\nconst getValue = (d: LineChartDataPoint): number =>\n  typeof d === \"number\" ? d : d.value;\n\nconst getLabel = (d: LineChartDataPoint): string =>\n  typeof d === \"number\" ? \"\" : (d.label ?? \"\");\n\nconst normalize = (\n  value: number,\n  min: number,\n  max: number,\n  rows: number\n): number => {\n  if (max === min) {\n    return Math.floor(rows / 2);\n  }\n  return Math.round(((value - min) / (max - min)) * (rows - 1));\n};\n\nconst PLOT_CHAR = \"●\";\nconst _CONNECT_H = \"─\";\nconst CONNECT_UP = \"╱\";\nconst CONNECT_DOWN = \"╲\";\nconst _CONNECT_FLAT = \"─\";\nconst AXIS_V = \"│\";\nconst AXIS_H = \"─\";\nconst AXIS_CORNER = \"└\";\nconst AXIS_TICK_V = \"┤\";\nconst _AXIS_TICK_H = \"┬\";\n\nexport const LineChart = ({\n  data,\n  width = 40,\n  height = 10,\n  title,\n  color,\n  showAxes = true,\n}: LineChartProps) => {\n  const theme = useTheme();\n  const resolvedColor = color ?? theme.colors.primary;\n\n  if (data.length === 0) {\n    return <text fg={theme.colors.mutedForeground}>No data</text>;\n  }\n\n  const values = data.map(getValue);\n  const minVal = Math.min(...values);\n  const maxVal = Math.max(...values);\n\n  const yAxisWidth = showAxes ? String(Math.round(maxVal)).length + 2 : 0;\n  const chartWidth = Math.max(4, width - yAxisWidth);\n\n  const numPoints = data.length;\n  const sampledIndices = Array.from({ length: chartWidth }, (_, i) =>\n    Math.round((i / (chartWidth - 1)) * (numPoints - 1))\n  );\n  const sampledValues = sampledIndices.map((si) => values[si] ?? 0);\n  const sampledData = sampledIndices.map((si) => data[si]);\n\n  const grid: string[][] = Array.from({ length: height }, () =>\n    Array.from({ length: chartWidth }, () => \" \")\n  );\n\n  const normalizedRows = sampledValues.map(\n    (v) => height - 1 - normalize(v, minVal, maxVal, height)\n  );\n\n  for (let col = 0; col < chartWidth; col += 1) {\n    const row = normalizedRows[col];\n    grid[row][col] = PLOT_CHAR;\n    if (col < chartWidth - 1) {\n      const nextRow = normalizedRows[col + 1] ?? row;\n      if (nextRow < row) {\n        let r = row - 1;\n        while (r > nextRow) {\n          grid[r][col] = AXIS_V;\n          r -= 1;\n        }\n        if (grid[nextRow][col] === \" \") {\n          grid[nextRow][col] = CONNECT_UP;\n        }\n      } else {\n        let r = row + 1;\n        while (r < nextRow) {\n          grid[r][col] = AXIS_V;\n          r += 1;\n        }\n        if (grid[nextRow][col] === \" \") {\n          grid[nextRow][col] = CONNECT_DOWN;\n        }\n      }\n    }\n  }\n\n  const yLabels = Array.from({ length: height }, (_, i) => {\n    const rowVal =\n      minVal + ((height - 1 - i) / (height - 1)) * (maxVal - minVal);\n    if (i === 0 || i === Math.floor(height / 2) || i === height - 1) {\n      return String(Math.round(rowVal));\n    }\n    return \"\";\n  });\n\n  return (\n    <box flexDirection=\"column\">\n      {title && (\n        <text fg={theme.colors.primary}>\n          <b>{title}</b>\n        </text>\n      )}\n      {grid.map((row, rowIdx) => (\n        <box key={rowIdx} flexDirection=\"row\">\n          {showAxes && (\n            <text\n              fg={theme.colors.mutedForeground}\n            >{`${String(yLabels[rowIdx] ?? \"\").padStart(yAxisWidth - 1)}${AXIS_TICK_V}`}</text>\n          )}\n          {row.map((cell, colIdx) => {\n            const isPlot = cell === PLOT_CHAR;\n            return (\n              <text\n                key={colIdx}\n                fg={isPlot ? resolvedColor : theme.colors.mutedForeground}\n              >\n                {cell}\n              </text>\n            );\n          })}\n        </box>\n      ))}\n      {showAxes && (\n        <box flexDirection=\"row\">\n          <text\n            fg={theme.colors.mutedForeground}\n          >{`${\" \".repeat(yAxisWidth - 1)}${AXIS_CORNER}${AXIS_H.repeat(chartWidth)}`}</text>\n        </box>\n      )}\n      {showAxes && (\n        <box flexDirection=\"row\">\n          <text fg={theme.colors.mutedForeground}>\n            {\" \".repeat(yAxisWidth)}\n          </text>\n          {sampledData.map((d, idx) => {\n            const lbl = getLabel(d);\n            if (\n              idx === 0 ||\n              idx === Math.floor(chartWidth / 2) ||\n              idx === chartWidth - 1\n            ) {\n              return (\n                <text key={idx} fg={theme.colors.mutedForeground}>\n                  {lbl || String(idx)}\n                </text>\n              );\n            }\n            return <text key={idx}> </text>;\n          })}\n        </box>\n      )}\n    </box>\n  );\n};\n",
      "type": "registry:ui",
      "target": "components/ui/line-chart.tsx"
    }
  ],
  "categories": [
    "charts"
  ],
  "type": "registry:ui"
}