{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"combo-chart","type":"registry:ui","title":"Combo Chart","description":"Bars and lines on one chart, such as revenue as bars and margin as a line, with a second axis on the right for values of another kind. Plain SVG.","dependencies":[],"registryDependencies":["https://dashral.com/r/utils.json","https://dashral.com/r/lib-chart.json","https://dashral.com/r/lib-locale.json"],"files":[{"path":"registry/dashral/combo-chart.tsx","type":"registry:file","target":"components/dashral/combo-chart.tsx","content":"\"use client\"\n\nimport * as React from \"react\"\n\nimport {\n  barPath,\n  type CartesianChartProps,\n  ChartAxes,\n  ChartLegend,\n  ChartReading,\n  type Curve,\n  linePath,\n  type RightAxisProps,\n  seriesColor,\n  useCartesianChart,\n} from \"./lib/chart\"\nimport { useLocale } from \"./lib/locale\"\nimport { cn } from \"./lib/utils\"\n\ntype ComboChartProps = Omit<React.ComponentProps<\"div\">, \"children\"> &\n  CartesianChartProps &\n  RightAxisProps & {\n    /** How a line bends between points: smoothly (never past a value it didn't have), straight, or in steps. */\n    curve?: Curve\n    /** Corner radius of a bar's end, in pixels. */\n    radius?: number\n    classNames?: { legend?: string; tooltip?: string }\n  }\n\n/**\n * Bars and lines on one chart, in one tag: revenue as bars and margin as a line, orders as bars and a target as a\n * dashed line. Each series says what it is (`type: \"bar\"`, the default, or `\"line\"`), and a line of another kind of\n * value reads against an axis of its own on the right (`axis: \"right\"`), whose ticks fall on the same grid lines.\n * Hover, or focus it and use the arrow keys, to read a column: the other bars fade back, the lines show a dot, and a\n * tooltip lists every series. Plain SVG, fills its container's width; bars grow up from the axis and lines draw in\n * from the left when it first shows, and both move to new data.\n */\nfunction ComboChart({\n  data,\n  index,\n  labelKey,\n  series,\n  height,\n  locale,\n  formatOptions,\n  rightFormatOptions,\n  alignZero,\n  timeFormat,\n  showLegend,\n  showGrid,\n  showYAxis,\n  curve = \"smooth\",\n  radius = 4,\n  className,\n  classNames,\n  \"aria-label\": ariaLabel,\n  ...props\n}: ComboChartProps) {\n  const { t } = useLocale()\n  // Bars by default: a series is a line only when it says so.\n  const typed = React.useMemo(() => series.map((s) => ({ ...s, type: s.type ?? (\"bar\" as const) })), [series])\n  const h = useCartesianChart({\n    data,\n    index,\n    labelKey,\n    series: typed,\n    height,\n    locale,\n    formatOptions,\n    rightFormatOptions,\n    alignZero,\n    timeFormat,\n    showLegend,\n    showGrid,\n    showYAxis,\n    band: true,\n    axes: true,\n    \"aria-label\": ariaLabel,\n    roledescription: t(\"comboChart\"),\n  })\n  const n = data.length\n  const bars = typed.map((s, k) => ({ s, k })).filter(({ s }) => s.type === \"bar\")\n  const lines = typed.map((s, k) => ({ s, k })).filter(({ s }) => s.type === \"line\")\n  // Each column takes most of its slot; its bars stand side by side in it with a little gap, as in BarChart.\n  const group = Math.min(h.slot * 0.7, 36 * bars.length + 4 * Math.max(0, bars.length - 1))\n  const gap = bars.length > 1 ? Math.min(4, group * 0.08) : 0\n  const bar = bars.length ? (group - gap * (bars.length - 1)) / bars.length : 0\n  const zero = h.y(Math.max(h.ticks[0]!, Math.min(0, h.ticks.at(-1)!)))\n\n  return (\n    <div data-slot=\"combo-chart\" {...h.root} className={cn(\"grid gap-3 rounded-md outline-none focus-visible:ring-2 focus-visible:ring-ring/50\", className)} {...props}>\n      {h.showLegend && <ChartLegend series={typed} className={classNames?.legend} />}\n\n      <div ref={h.box} dir=\"ltr\" className=\"relative w-full touch-none select-none\" style={{ height: h.height }} {...h.plot}>\n        {h.width !== null && n > 0 && (\n          <>\n            <ChartAxes chart={h} band />\n\n            {/* The bars, growing up from the axis when the chart first shows and to new heights when the data changes. */}\n            <svg aria-hidden width={h.width} height={h.height} className=\"pointer-events-none absolute inset-0\">\n              {h.columns.map((cells, i) => {\n                const left = h.x(i) - group / 2\n                return (\n                  // The column being read keeps its color; the others fade back.\n                  <g key={i} opacity={h.active === null || h.active === i ? 1 : 0.4} className=\"transition-opacity duration-(--duration-fast)\">\n                    {bars.map(({ s, k }, j) => {\n                      const end = h.yFor(k, cells[k]!.value)\n                      return (\n                        <path\n                          key={s.key}\n                          d={barPath(Math.round(left + j * (bar + gap)), Math.max(1, Math.round(bar)), zero, h.drawn ? end : zero, radius)}\n                          fill={seriesColor(s, k)}\n                          className=\"transition-[d] duration-(--duration-considered) ease-standard motion-reduce:transition-none\"\n                        />\n                      )\n                    })}\n                  </g>\n                )\n              })}\n            </svg>\n\n            {/* The lines over the bars, drawn in from the left when the chart first shows; new data moves them. */}\n            <svg\n              aria-hidden\n              width={h.width}\n              height={h.height}\n              className=\"pointer-events-none absolute inset-0 overflow-visible transition-[clip-path] duration-(--duration-considered) ease-enter motion-reduce:transition-none\"\n              style={{ clipPath: h.drawn ? \"inset(-8px -8px -8px -8px)\" : `inset(0 ${h.width}px 0 0)` }}\n            >\n              {lines.map(({ s, k }) => {\n                const points = h.columns.map((cells, i) => ({ x: h.x(i), y: h.yFor(k, cells[k]!.value) }))\n                return (\n                  <g key={s.key}>\n                    <path\n                      d={linePath(points, curve)}\n                      fill=\"none\"\n                      stroke={seriesColor(s, k)}\n                      strokeWidth={s.dashed ? 1.5 : 2}\n                      strokeDasharray={s.dashed ? \"4 4\" : undefined}\n                      strokeOpacity={s.dashed ? 0.7 : 1}\n                      strokeLinejoin=\"round\"\n                      strokeLinecap=\"round\"\n                      className=\"transition-[d] duration-(--duration-considered) ease-standard motion-reduce:transition-none\"\n                    />\n                    {/* The point being read, on each line. */}\n                    {h.active !== null && (\n                      <circle cx={points[h.active]!.x} cy={points[h.active]!.y} r={4} fill=\"var(--background)\" stroke={seriesColor(s, k)} strokeWidth={2} />\n                    )}\n                  </g>\n                )\n              })}\n            </svg>\n\n            <ChartReading chart={h} series={typed} band className={classNames?.tooltip} />\n          </>\n        )}\n        {n === 0 && <p className=\"grid h-full place-items-center text-sm text-muted-foreground\">{t(\"noData\")}</p>}\n      </div>\n      <p aria-live=\"polite\" className=\"sr-only\">\n        {h.announce}\n      </p>\n    </div>\n  )\n}\n\nexport { ComboChart, type ComboChartProps }\nexport type { ChartDatum, ChartSeries } from \"./lib/chart\"\n"}],"cssVars":{"theme":{"ease-standard":"var(--ease-standard)","ease-enter":"var(--ease-enter)","ease-exit":"var(--ease-exit)","ease-spring":"var(--ease-spring)"},"light":{"duration-fast":"160ms","duration-standard":"240ms","duration-considered":"480ms","ease-standard":"cubic-bezier(0.2, 0, 0, 1)","ease-enter":"cubic-bezier(0, 0, 0, 1)","ease-exit":"cubic-bezier(0.3, 0, 1, 1)","ease-spring":"linear(0, 0.071 4%, 0.234 8%, 0.433 12%, 0.626 17%, 0.791 21%, 0.917 25%, 1.004 29%, 1.055 33%, 1.079 38%, 1.083 42%, 1.075 46%, 1.06 50%, 1.043 54%, 1.027 58%, 1.015 62%, 1.005 67%, 0.998 71%, 0.995 75%, 0.993 79%, 0.993 83%, 0.994 88%, 0.995 92%, 0.997 96%, 1)"},"dark":{}}}