{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "bar-chart",
  "title": "BarChart",
  "description": "Amounts across categories. More than one series stacks.",
  "registryDependencies": [
    "https://creance.pages.dev/r/creance-base.json",
    "https://creance.pages.dev/r/creance-chart.json"
  ],
  "files": [
    {
      "path": "bar-chart/BarChart.css",
      "content": "/* Room under the plot for the category labels, which hang below each column. */\n.cr-bar-chart__plot {\n  margin-bottom: 22px;\n}\n\n.cr-bar-chart__bars {\n  position: absolute;\n  inset: 0;\n  display: flex;\n  align-items: flex-end;\n}\n\n.cr-bar-chart__column {\n  position: relative;\n  display: flex;\n  flex: 1;\n  flex-direction: column;\n  align-items: center;\n  justify-content: flex-end;\n  min-width: 0;\n  height: 100%;\n}\n\n/* First series at the bottom. */\n.cr-bar-chart__stack {\n  display: flex;\n  flex-direction: column-reverse;\n  gap: 2px;\n  width: min(60%, 28px);\n  min-height: 2px;\n  overflow: hidden;\n  border-radius: 6px 6px 0 0;\n}\n\n.cr-bar-chart__bar {\n  flex-basis: 0;\n}\n\n.cr-bar-chart__column[data-dim] .cr-bar-chart__bar {\n  opacity: 0.32;\n}\n\n.cr-bar-chart__value {\n  margin-bottom: var(--cr-space-1);\n  font-size: 11px;\n  font-weight: var(--cr-font-weight-semibold);\n  visibility: hidden;\n}\n\n.cr-bar-chart__column:hover .cr-bar-chart__value,\n.cr-bar-chart__column[data-highlight] .cr-bar-chart__value {\n  visibility: visible;\n}\n\n.cr-bar-chart__column:hover .cr-bar-chart__bar {\n  opacity: 1;\n}\n\n.cr-bar-chart__label {\n  position: absolute;\n  top: 100%;\n  padding-top: 6px;\n  color: var(--cr-color-text-muted);\n  font-size: 11px;\n  white-space: nowrap;\n}\n\n.cr-bar-chart__column[data-highlight] .cr-bar-chart__label {\n  color: var(--cr-color-text-default);\n  font-weight: var(--cr-font-weight-semibold);\n}\n",
      "type": "registry:file",
      "target": "@components/creance/bar-chart/BarChart.css"
    },
    {
      "path": "bar-chart/BarChart.tsx",
      "content": "import { ChartLegend, ChartTable, formatter, niceScale, seriesColor, type ChartTone, type ValueFormat } from '@/lib/creance/chart';\nimport { cx } from '@/lib/creance/cx';\nimport './BarChart.css';\n\nexport interface BarSeries {\n  name: string;\n  /** One value per label. */\n  values: number[];\n  /** `danger` is red, for a failure. */\n  tone?: ChartTone;\n}\n\nexport interface BarChartProps extends ValueFormat {\n  /** The categories along the bottom. */\n  labels: string[];\n  /** One series draws plain bars. More than one stacks them, first at the bottom. */\n  series: BarSeries[];\n  /** What the chart shows, for screen readers and as the table's caption: \"Runs per day\". */\n  label: string;\n  /** What the labels are, as the heading of the table's first column. Default \"Category\". */\n  axisLabel?: string;\n  /** Index of one bar to pick out in ink with its value shown. The others turn grey. Single series only. */\n  highlight?: number;\n  /** Height in pixels. Default 200. */\n  height?: number;\n  /** Names the series. Default true when there is more than one. */\n  legend?: boolean;\n  className?: string;\n}\n\n/** Amounts across categories. Hovering a bar shows its value; the whole chart is also a table for screen readers. */\nexport function BarChart({ labels, series, label, axisLabel = 'Category', highlight, height = 200, legend = series.length > 1, className, ...format }: BarChartProps) {\n  const fmt = formatter(format);\n  const totals = labels.map((_, i) => series.reduce((sum, s) => sum + Math.max(s.values[i] ?? 0, 0), 0));\n  const scale = niceScale(Math.max(...totals, 0), 3);\n  const stacked = series.length > 1;\n  // Ink steps down through the series that are not failures.\n  const colors = series.map((s, i) => seriesColor(series.slice(0, i).filter((b) => b.tone !== 'danger').length, s.tone));\n\n  return (\n    <figure className={cx('cr-chart cr-bar-chart', className)}>\n      {legend && <ChartLegend items={series.map((s, i) => ({ name: s.name, color: colors[i]! }))} />}\n      <div className=\"cr-chart__plot cr-bar-chart__plot\" style={{ height }} aria-hidden=\"true\">\n        {scale.ticks.map((t) => (\n          <span key={t} className=\"cr-chart__tick\" style={{ bottom: `${(t / scale.max) * 100}%` }}>\n            <span className=\"cr-chart__tick-label\">{fmt(t)}</span>\n          </span>\n        ))}\n        <div className=\"cr-bar-chart__bars\">\n          {labels.map((name, i) => (\n            <div key={i} className=\"cr-bar-chart__column\" data-highlight={highlight === i || undefined} data-dim={(highlight !== undefined && highlight !== i) || undefined}>\n              <span className=\"cr-bar-chart__value\">{fmt(totals[i]!)}</span>\n              <span className=\"cr-bar-chart__stack\" style={{ height: `${(totals[i]! / scale.max) * 100}%` }}>\n                {series.map((s, n) => (\n                  <span key={n} className=\"cr-bar-chart__bar\" style={{ flexGrow: Math.max(s.values[i] ?? 0, 0), background: colors[n] }} />\n                ))}\n              </span>\n              <span className=\"cr-bar-chart__label\">{name}</span>\n            </div>\n          ))}\n        </div>\n      </div>\n      <ChartTable\n        caption={label}\n        columns={[axisLabel, ...series.map((s) => s.name), ...(stacked ? ['Total'] : [])]}\n        rows={labels.map((name, i) => [name, ...series.map((s) => fmt(s.values[i] ?? 0)), ...(stacked ? [fmt(totals[i]!)] : [])])}\n      />\n    </figure>\n  );\n}\n",
      "type": "registry:ui",
      "target": "@components/creance/bar-chart/BarChart.tsx"
    }
  ],
  "categories": [
    "molecule",
    "charts"
  ],
  "type": "registry:ui"
}