{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "parallel-coordinates",
  "type": "registry:component",
  "title": "Parallel Coordinates",
  "description": "Many measures of many things at once: one upright axis per measure, each thing a line that crosses every axis at its value, so trade-offs and clusters show as patterns of crossing or parallel lines; each line lit and read by arrow keys.",
  "categories": [
    "viz"
  ],
  "dependencies": [
    "d3-scale"
  ],
  "devDependencies": [
    "@types/d3-scale"
  ],
  "registryDependencies": [
    "@rivier-ui/theme",
    "@rivier-ui/chart",
    "@rivier-ui/cn"
  ],
  "files": [
    {
      "path": "registry/viz/parallel-coordinates.tsx",
      "type": "registry:component",
      "target": "components/viz/parallel-coordinates.tsx",
      "content": "\"use client\";\n/**\n * @name parallel-coordinates\n * @category viz\n * @description Many measures of many things at once: one upright axis per measure, each thing a line that crosses every axis at its value, so trade-offs and clusters show as patterns of crossing or parallel lines; each line lit and read by arrow keys.\n * @when Comparing things across four to ten measures with different units: cars by price, power and weight; plans by cost and limits. For two measures use scatter-chart; for a few things on one scale use radar-chart; for exact values use table or data-grid.\n * @example\n * <ParallelCoordinates\n *   label=\"Laptops compared\"\n *   data={[\n *     { name: \"Alder\", price: 900, weight: 1.3, battery: 12, kind: \"Light\" },\n *     { name: \"Birch\", price: 1400, weight: 2.1, battery: 8, kind: \"Power\" },\n *     { name: \"Cedar\", price: 700, weight: 1.6, battery: 10, kind: \"Light\" },\n *   ]}\n *   dimensions={[{ key: \"price\", label: \"Price\" }, { key: \"weight\", label: \"Weight (kg)\" }, { key: \"battery\", label: \"Battery (h)\" }]}\n *   name=\"name\"\n *   group=\"kind\"\n * />\n */\nimport { scaleLinear, scalePoint } from \"d3-scale\";\nimport { useMemo } from \"react\";\nimport { cn } from \"@/lib/cn\";\nimport {\n  axisNumberFormatter,\n  ChartContainer,\n  ChartEmpty,\n  ChartLegend,\n  chartSeries,\n  ChartSvg,\n  ChartTooltip,\n  fitText,\n  formatNumber,\n  readNumber,\n  useChartCursor,\n  type ChartBaseProps,\n  type ChartSeries,\n} from \"@/components/viz/chart\";\n\nexport type ParallelCoordinatesProps<T extends object> = ChartBaseProps & {\n  data: readonly T[];\n  /** The measures, one axis each, left to right. */\n  dimensions: readonly ChartSeries<T>[];\n  /** A field naming each thing. */\n  name?: keyof T & string;\n  /** A field naming each thing's group: one colour per group, in order of first appearance. */\n  group?: keyof T & string;\n  showLegend?: boolean;\n};\n\nexport function ParallelCoordinates<T extends object>({\n  data,\n  dimensions,\n  name,\n  group,\n  showLegend,\n  label,\n  aspect = 16 / 9,\n  height,\n  emptyLabel,\n  locale,\n  formatValue,\n  className,\n  ...props\n}: ParallelCoordinatesProps<T>) {\n  const model = useMemo(() => {\n    const read = (row: T, key: string | undefined): string => (key ? String((row as Record<string, unknown>)[key] ?? \"\") : \"\");\n    const groups = group ? [...new Set(data.map((row) => read(row, group)))] : [];\n    const lines = data.map((row, index) => ({\n      name: name ? read(row, name) : String(index + 1),\n      group: group ? groups.indexOf(read(row, group)) : 0,\n      values: dimensions.map((d) => readNumber(row, d.key)),\n    }));\n    const extents = dimensions.map((_, d) => {\n      const values = lines.flatMap((line) => (line.values[d] === null || line.values[d] === undefined ? [] : [line.values[d] as number]));\n      return [Math.min(...values), Math.max(...values)] as const;\n    });\n    return { lines, groups, extents };\n  }, [data, dimensions, name, group]);\n  const { lines, groups, extents } = model;\n  const cursor = useChartCursor(lines.length);\n  const number = formatValue ?? ((value: number) => formatNumber(value, locale));\n  const table = {\n    caption: label,\n    columns: [name ?? \"#\", ...(group ? [group] : []), ...dimensions.map((d) => d.label)],\n    rows: lines.map((line) => [line.name, ...(group ? [groups[line.group] ?? \"\"] : []), ...line.values.map((v) => (v === null || v === undefined ? \"\" : number(v)))]),\n  };\n  const current = cursor.active === null ? undefined : lines[cursor.active];\n  const rowsOf = (line: (typeof lines)[number]): { label: string; value: string }[] =>\n    dimensions.map((d, i) => ({ label: d.label, value: line.values[i] === null || line.values[i] === undefined ? \"\" : number(line.values[i] as number) }));\n  const legend = showLegend ?? groups.length > 1;\n\n  return (\n    <div data-slot=\"parallel-coordinates\" className={cn(\"flex w-full min-w-0 flex-col gap-3\", className)} {...props}>\n      {legend ? <ChartLegend items={groups.map((g, i) => ({ label: g, index: i < 5 ? i : -1 }))} /> : null}\n      <ChartContainer\n        aspect={aspect}\n        height={height}\n        table={table}\n        announcement={\n          cursor.keyboard && current\n            ? `${current.name}: ${rowsOf(current)\n                .map((row) => `${row.label} ${row.value}`)\n                .join(\", \")}`\n            : \"\"\n        }\n      >\n        {({ width, height: plotHeight }) => {\n          if (lines.length === 0 || dimensions.length < 2) return <ChartEmpty>{emptyLabel}</ChartEmpty>;\n          const top = 30;\n          const bottom = 20;\n          const sx = scalePoint<number>()\n            .domain(dimensions.map((_, i) => i))\n            .range([28, width - 28]);\n          const scales = extents.map(([low, high]) =>\n            scaleLinear()\n              .domain(low === high || !Number.isFinite(low) ? [(Number.isFinite(low) ? low : 0) - 1, (Number.isFinite(high) ? high : 0) + 1] : [low, high])\n              .nice(4)\n              .range([plotHeight - bottom, top]),\n          );\n          const path = (line: (typeof lines)[number]): string =>\n            line.values\n              .map((v, i) => (v === null || v === undefined ? null : `${sx(i) ?? 0},${scales[i]?.(v) ?? 0}`))\n              .filter((p): p is string => p !== null)\n              .map((p, i) => `${i === 0 ? \"M\" : \"L\"}${p}`)\n              .join(\"\");\n          const step = sx.step();\n          const shown = current ? { x: sx(dimensions.length - 1) ?? 0, y: scales[dimensions.length - 1]?.(current.values[dimensions.length - 1] ?? 0) ?? 0 } : undefined;\n          return (\n            <>\n              <ChartSvg label={label} width={width} height={plotHeight} interactive {...cursor.svgProps}>\n                <g aria-hidden=\"true\" fill=\"none\">\n                  {lines.map((line, i) => (\n                    <path\n                      key={i}\n                      d={path(line)}\n                      className={cn(chartSeries(group ? (line.group < 5 ? line.group : -1) : 0).stroke, \"transition-opacity duration-instant motion-reduce:transition-none\")}\n                      strokeOpacity={cursor.active === null ? 0.55 : cursor.active === i ? 1 : 0.12}\n                      strokeWidth={cursor.active === i ? 2.5 : 1.5}\n                      strokeLinejoin=\"round\"\n                    />\n                  ))}\n                  {/* Wide invisible strokes take the pointer, so a thin line is easy to hit. */}\n                  {lines.map((line, i) => (\n                    <path key={`hit${i}`} d={path(line)} stroke=\"transparent\" strokeWidth={10} onPointerEnter={() => cursor.point(i)} />\n                  ))}\n                </g>\n                <g aria-hidden=\"true\">\n                  {dimensions.map((d, i) => {\n                    const scale = scales[i];\n                    if (!scale) return null;\n                    const ticks = scale.ticks(4);\n                    const format = formatValue ?? axisNumberFormatter(Math.max(...ticks.map(Math.abs)), locale);\n                    const x = sx(i) ?? 0;\n                    return (\n                      <g key={d.key}>\n                        <line x1={x} x2={x} y1={top} y2={plotHeight - bottom} className=\"stroke-border-strong\" />\n                        <text x={x} y={top - 14} textAnchor=\"middle\" className=\"fill-foreground text-xs font-medium\">\n                          {fitText(d.label, Math.max(40, step - 8))}\n                        </text>\n                        {ticks.map((tick) => (\n                          <text key={tick} x={x + 4} y={scale(tick)} dy=\"0.32em\" className=\"fill-muted-foreground stroke-background text-xs tabular-nums\" paintOrder=\"stroke\" strokeWidth={3}>\n                            {format(tick)}\n                          </text>\n                        ))}\n                      </g>\n                    );\n                  })}\n                </g>\n              </ChartSvg>\n              {current && shown ? <ChartTooltip x={shown.x} y={shown.y} side=\"left\" title={current.name} rows={rowsOf(current)} /> : null}\n            </>\n          );\n        }}\n      </ChartContainer>\n    </div>\n  );\n}\n"
    }
  ],
  "meta": {
    "category": "viz",
    "when": "Comparing things across four to ten measures with different units: cars by price, power and weight; plans by cost and limits. For two measures use scatter-chart; for a few things on one scale use radar-chart; for exact values use table or data-grid.",
    "example": "<ParallelCoordinates\n  label=\"Laptops compared\"\n  data={[\n    { name: \"Alder\", price: 900, weight: 1.3, battery: 12, kind: \"Light\" },\n    { name: \"Birch\", price: 1400, weight: 2.1, battery: 8, kind: \"Power\" },\n    { name: \"Cedar\", price: 700, weight: 1.6, battery: 10, kind: \"Light\" },\n  ]}\n  dimensions={[{ key: \"price\", label: \"Price\" }, { key: \"weight\", label: \"Weight (kg)\" }, { key: \"battery\", label: \"Battery (h)\" }]}\n  name=\"name\"\n  group=\"kind\"\n/>",
    "client": true
  }
}
