{
  "$schema": "https://uipkge.dev/schema/registry-item.json",
  "name": "bar-chart",
  "title": "Bar Chart",
  "type": "registry:ui",
  "files": [
    {
      "path": "packages/registry-angular/components/charts/bar-chart/bar-chart.component.ts",
      "content": "import {\n  AfterViewInit,\n  Component,\n  ElementRef,\n  Input,\n  OnChanges,\n  OnDestroy,\n  SimpleChanges,\n  ViewChild,\n  ChangeDetectionStrategy,\n} from '@angular/core'\nimport type * as echarts from 'echarts/core'\nimport { cn } from '@/lib/utils'\nimport {\n  getChartAxisColor,\n  getChartBgColor,\n  getChartColors,\n  getChartSplitLineColor,\n  getChartTextColor,\n  getChartTooltipBg,\n  getChartTooltipBorder,\n  getChartTooltipText,\n  mergeOptionBlock,\n} from '../use-chart-theme'\n\n/**\n * Angular port of the UIPKGE BarChart — ECharts wrapper with vertical,\n * horizontal, grouped, stacked, and negative-value variants. Standalone,\n * theme-aware via registry tokens. Same inputs as the Vue `BarChart`.\n */\n@Component({\n  changeDetection: ChangeDetectionStrategy.Eager,\n  selector: 'ui-bar-chart, [ui-bar-chart]',\n  standalone: true,\n  host: {\n    '[attr.data-slot]': '\"bar-chart\"',\n    '[attr.data-uipkge]': '\"\"',\n    '[class]': 'hostClass',\n    '[attr.role]': '\"img\"',\n    '[attr.aria-label]': 'ariaLabel || \"Chart\"',\n    '[attr.tabindex]': '0',\n    '[style.height]': 'heightStyle',\n  },\n  template: `<div #chartEl class=\"size-full\"></div>`,\n})\nexport class UiBarChartComponent implements AfterViewInit, OnChanges, OnDestroy {\n  @Input() data: Record<string, unknown>[] = []\n  @Input() xField = 'x'\n  @Input() yField: string | string[] = 'y'\n  /** Stack series on one baseline. Default false. */\n  @Input() stacked = false\n  /** Gap in px between stacked bar segments. Default 1. Set to 0 to disable. */\n  @Input() stackGap = 1\n  /** Color of the gap between stacked bar segments. Defaults to card background. */\n  @Input() stackGapColor?: string\n  /** Show value labels on top of each bar. Default false. */\n  @Input() valueLabels = false\n  /** Top corner rounding in px. Default 6. */\n  @Input() radius = 6\n  @Input() height: number | string = 300\n  @Input() option?: Record<string, unknown>\n  /** Accessible name announced for the chart image. Defaults to \"Chart\". */\n  @Input() ariaLabel?: string\n  @Input('class') className?: string\n\n  @ViewChild('chartEl', { static: false }) chartEl?: ElementRef<HTMLDivElement>\n\n  private chart: echarts.ECharts | null = null\n  private unsubscribeTheme: (() => void) | null = null\n\n  get hostClass(): string {\n    return cn('block focus-visible:ring-ring w-full focus-visible:ring-2 focus-visible:outline-none', this.className)\n  }\n\n  get heightStyle(): string {\n    return /^\\d+$/.test(String(this.height)) ? `${this.height}px` : String(this.height)\n  }\n\n  fields(): string[] {\n    return Array.isArray(this.yField) ? this.yField : [this.yField]\n  }\n\n  /** Build the merged ECharts option (pure — no DOM needed, unit-testable). */\n  getOption(): Record<string, unknown> {\n    const fields = this.fields()\n    const colors = getChartColors()\n    const xData = this.data.map((d) => d[this.xField])\n\n    const userOption: Record<string, any> = this.option ?? {}\n    const {\n      series: userSeries,\n      xAxis: userXAxis,\n      yAxis: userYAxis,\n      grid: userGrid,\n      tooltip: userTooltip,\n      legend: userLegend,\n      ...userRest\n    } = userOption\n\n    const hasUserStack = Array.isArray(userSeries) && userSeries.some((s: any) => Boolean(s?.stack))\n    const stackGap = this.stackGap\n    const stackGapColor = this.stackGapColor ?? getChartBgColor()\n    const defaultRadius = [this.radius, this.radius, this.radius, this.radius]\n\n    const series = fields.map((field, i) => {\n      const u = Array.isArray(userSeries) ? (userSeries[i] ?? {}) : {}\n      const isStacked = Boolean(this.stacked || u?.stack || hasUserStack)\n      return {\n        // Single series hides the legend; blank name keeps the raw field key out of the tooltip.\n        name: fields.length > 1 ? field : '',\n        type: 'bar',\n        stack: this.stacked ? 'bars' : undefined,\n        barMaxWidth: 32,\n        itemStyle: {\n          color: colors[i % colors.length],\n          borderRadius: defaultRadius,\n          ...(isStacked && stackGap > 0 ? { borderColor: stackGapColor, borderWidth: stackGap } : {}),\n        },\n        label: this.valueLabels ? { show: true, position: 'top', color: getChartTextColor(), fontSize: 11 } : undefined,\n        data: this.data.map((d) => d[field]),\n      }\n    })\n\n    const count = Math.max(fields.length, Array.isArray(userSeries) ? userSeries.length : 0)\n    const mergedSeries = Array.isArray(userSeries)\n      ? Array.from({ length: count }, (_, i) => {\n          const s: any = series[i] ?? { type: 'bar', barMaxWidth: 32, itemStyle: { color: colors[i % colors.length] } }\n          const u = userSeries[i] ?? {}\n          const isStacked = Boolean(this.stacked || s.stack || u?.stack || hasUserStack)\n          return {\n            ...s,\n            ...u,\n            itemStyle: {\n              ...s.itemStyle,\n              borderRadius: defaultRadius,\n              ...(isStacked && stackGap > 0 ? { borderColor: stackGapColor, borderWidth: stackGap } : {}),\n              ...(u.itemStyle ?? {}),\n            },\n          }\n        })\n      : series\n\n    const baseLegend: Record<string, unknown> =\n      fields.length > 1\n        ? {\n            bottom: 0,\n            icon: 'circle',\n            itemWidth: 8,\n            itemHeight: 8,\n            textStyle: { fontSize: 11, color: getChartTextColor() },\n          }\n        : { show: false }\n\n    return {\n      color: colors,\n      grid: mergeOptionBlock(\n        {\n          left: 16,\n          right: 16,\n          top: 24,\n          bottom: fields.length > 1 ? 32 : 24,\n          outerBoundsMode: 'same',\n          outerBoundsContain: 'axisLabel',\n        },\n        userGrid,\n      ),\n      tooltip: mergeOptionBlock(\n        {\n          trigger: 'axis',\n          backgroundColor: getChartTooltipBg(),\n          borderColor: getChartTooltipBorder(),\n          textStyle: { color: getChartTooltipText(), fontSize: 12 },\n        },\n        userTooltip,\n      ),\n      legend: userLegend?.show === false ? undefined : mergeOptionBlock(baseLegend, userLegend),\n      xAxis: mergeOptionBlock(\n        {\n          type: 'category',\n          data: xData,\n          axisLine: { lineStyle: { color: getChartAxisColor() } },\n          axisLabel: { color: getChartTextColor(), fontSize: 11 },\n          axisTick: { show: false },\n        },\n        userXAxis,\n      ),\n      yAxis: mergeOptionBlock(\n        {\n          type: 'value',\n          splitLine: { lineStyle: { color: getChartSplitLineColor() } },\n          axisLabel: { color: getChartTextColor(), fontSize: 11 },\n          axisLine: { show: false },\n          axisTick: { show: false },\n        },\n        userYAxis,\n      ),\n      series: mergedSeries,\n      ...userRest,\n    }\n  }\n\n  async ngAfterViewInit(): Promise<void> {\n    if (typeof window === 'undefined' || !this.chartEl?.nativeElement) return\n    const [{ use }, { CanvasRenderer }, { BarChart }, comps] = await Promise.all([\n      import('echarts/core'),\n      import('echarts/renderers'),\n      import('echarts/charts'),\n      import('echarts/components'),\n    ])\n    use([\n      CanvasRenderer,\n      BarChart,\n      comps.GridComponent,\n      comps.TooltipComponent,\n      comps.LegendComponent,\n      comps.MarkAreaComponent,\n    ])\n    const { init } = await import('echarts/core')\n    this.chart = init(this.chartEl.nativeElement)\n    this.chart.setOption(this.getOption())\n    const { onChartThemeChange } = await import('../use-chart-theme')\n    this.unsubscribeTheme = onChartThemeChange(() => this.chart?.setOption(this.getOption()))\n    if (typeof ResizeObserver !== 'undefined') {\n      new ResizeObserver(() => this.chart?.resize()).observe(this.chartEl.nativeElement)\n    }\n  }\n\n  ngOnChanges(changes: SimpleChanges): void {\n    if (\n      this.chart &&\n      (changes['data'] ||\n        changes['option'] ||\n        changes['xField'] ||\n        changes['yField'] ||\n        changes['stacked'] ||\n        changes['stackGap'] ||\n        changes['stackGapColor'] ||\n        changes['valueLabels'] ||\n        changes['radius'])\n    ) {\n      this.chart.setOption(this.getOption())\n    }\n  }\n\n  ngOnDestroy(): void {\n    this.unsubscribeTheme?.()\n    this.unsubscribeTheme = null\n    try {\n      this.chart?.dispose()\n    } catch {\n      /* already disposed */\n    }\n    this.chart = null\n  }\n}\n",
      "type": "registry:ui",
      "target": "~/src/app/components/ui/charts/bar-chart/bar-chart.component.ts"
    },
    {
      "path": "packages/registry-angular/components/charts/bar-chart/index.ts",
      "content": "export { UiBarChartComponent } from './bar-chart.component'\n",
      "type": "registry:ui",
      "target": "~/src/app/components/ui/charts/bar-chart/index.ts"
    },
    {
      "path": "packages/registry-angular/components/charts/use-chart-theme.ts",
      "content": "// Angular port of `useChartTheme.ts` (Vue) — framework-free helpers + plain\n// functions instead of Vue `computed` refs. The palette is driven by Tailwind\n// v4 CSS variables (`--chart-1`..`--chart-5`, `--muted-foreground`, `--border`,\n// `--popover`, …) so dark/light flips happen automatically when the consumer\n// toggles their theme class. Values resolve at runtime via `getComputedStyle`,\n// so they pick up whatever the consumer set in their own `tailwind.css`.\n//\n// In a non-DOM environment (SSR / unit tests) every accessor returns the\n// fallback palette, which roughly matches the shadcn Neutral defaults so the\n// first paint doesn't flicker.\n\nexport const CHART_FALLBACK = ['#f59e0b', '#14b8a6', '#3b82f6', '#f97316', '#eab308']\n\n// ECharts' canvas renderer does not accept OKLCH in every browser. Assigning\n// one of our Tailwind tokens to `fillStyle` can silently leave the sentinel\n// colour in place, turning a whole chart black. Convert OKLCH ourselves and\n// let the canvas normalize older CSS colour formats.\nlet _hexCanvas: CanvasRenderingContext2D | null = null\n\nexport function toCanvasColor(cssColor: string): string {\n  const value = cssColor.trim()\n  const match = value.match(\n    /^oklch\\(\\s*([+-]?(?:\\d+\\.?\\d*|\\.\\d+))(%?)\\s+([+-]?(?:\\d+\\.?\\d*|\\.\\d+))\\s+([+-]?(?:\\d+\\.?\\d*|\\.\\d+))(?:deg)?(?:\\s*\\/\\s*([+-]?(?:\\d+\\.?\\d*|\\.\\d+))(%?))?\\s*\\)$/i,\n  )\n\n  if (match) {\n    const lightness = Number(match[1]) / (match[2] === '%' ? 100 : 1)\n    const chroma = Number(match[3])\n    const hue = (Number(match[4]) * Math.PI) / 180\n    const alpha = match[5] == null ? 1 : Number(match[5]) / (match[6] === '%' ? 100 : 1)\n    const a = chroma * Math.cos(hue)\n    const b = chroma * Math.sin(hue)\n\n    const l = Math.pow(lightness + 0.3963377774 * a + 0.2158037573 * b, 3)\n    const m = Math.pow(lightness - 0.1055613458 * a - 0.0638541728 * b, 3)\n    const s = Math.pow(lightness - 0.0894841775 * a - 1.291485548 * b, 3)\n    const linear = [\n      4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,\n      -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,\n      -0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s,\n    ]\n    const rgb = linear.map((channel) => {\n      const encoded = channel <= 0.0031308 ? 12.92 * channel : 1.055 * Math.pow(channel, 1 / 2.4) - 0.055\n      return Math.round(Math.min(1, Math.max(0, encoded)) * 255)\n    })\n\n    return alpha < 1 ? `rgba(${rgb.join(', ')}, ${alpha})` : `rgb(${rgb.join(', ')})`\n  }\n\n  if (typeof document === 'undefined') return cssColor\n  if (!_hexCanvas) {\n    _hexCanvas = document.createElement('canvas').getContext('2d')\n  }\n  if (!_hexCanvas) return cssColor\n  _hexCanvas.fillStyle = '#010203'\n  _hexCanvas.fillStyle = value\n  const normalized = _hexCanvas.fillStyle as string\n  return normalized === '#010203' && value.toLowerCase() !== '#010203' ? value : normalized\n}\n\n// Convert any CSS color (hex, rgb, oklch, color()) + alpha 0..1 to a\n// canvas-safe rgba(r,g,b,a). `colorString + '40'` (8-digit hex alpha)\n// only works when `colorString` is `#rrggbb`; once tokens resolve to\n// oklch() post-hydration the gradient stops break and the canvas paint\n// throws every frame. Stay defensive and always return rgba.\nexport function toRgba(cssColor: string, alpha: number): string {\n  const normalized = toCanvasColor(cssColor)\n  if (normalized.startsWith('#') && normalized.length === 7) {\n    const r = parseInt(normalized.slice(1, 3), 16)\n    const g = parseInt(normalized.slice(3, 5), 16)\n    const b = parseInt(normalized.slice(5, 7), 16)\n    return `rgba(${r},${g},${b},${alpha})`\n  }\n  if (normalized.startsWith('rgba(')) {\n    return normalized.replace(/,\\s*[\\d.]+\\s*\\)$/, `,${alpha})`)\n  }\n  if (normalized.startsWith('rgb(')) {\n    return normalized.replace(/^rgb\\(/, 'rgba(').replace(/\\)$/, `,${alpha})`)\n  }\n  // Canvas refused to parse this color -- ship the original string and\n  // let ECharts complain (better than crashing the paint loop).\n  return cssColor\n}\n\nexport function resolveCssVar(name: string, fallback: string): string {\n  if (typeof window === 'undefined') return fallback\n  const v = getComputedStyle(document.documentElement).getPropertyValue(name).trim()\n  if (!v) return fallback\n  return toCanvasColor(v)\n}\n\nexport function getChartColors(): string[] {\n  return Array.from({ length: 5 }, (_, i) => resolveCssVar(`--chart-${i + 1}`, CHART_FALLBACK[i]!))\n}\n\nexport function getChartTextColor(): string {\n  return resolveCssVar('--muted-foreground', '#888888')\n}\n\nexport function getChartAxisColor(): string {\n  return resolveCssVar('--border', '#e5e5e5')\n}\n\nexport function getChartSplitLineColor(): string {\n  return resolveCssVar('--border', '#f0f0f0')\n}\n\nexport function getChartTooltipBg(): string {\n  return resolveCssVar('--popover', 'rgba(255,255,255,0.96)')\n}\n\nexport function getChartTooltipBorder(): string {\n  return resolveCssVar('--border', '#e5e5e5')\n}\n\nexport function getChartTooltipText(): string {\n  return resolveCssVar('--popover-foreground', '#333333')\n}\n\nexport function getChartBgColor(): string {\n  return resolveCssVar('--card', resolveCssVar('--background', '#ffffff'))\n}\n\n// The app's accent, for the one highlighted element on a chart or map — a\n// selected route, a focused bar. Category series keep using getChartColors().\nexport function getChartAccentColor(): string {\n  return resolveCssVar('--primary', '#38bdf8')\n}\n\n// Out-of-bounds / failure colour for charts that encode good vs bad rather\n// than a category — control limits, error series.\nexport function getChartDangerColor(): string {\n  return resolveCssVar('--destructive', '#dc2626')\n}\n\n// Two-level deep merge for ECharts option blocks (xAxis, yAxis, grid,\n// tooltip, legend, singleAxis, parallel, etc.). The top-level keys merge\n// shallowly, but one nested level (axisLabel, axisLine, splitLine, etc.)\n// merges shallowly too so a consumer passing `xAxis: { axisLabel: { fontSize: 9 } }`\n// doesn't blow away the wrapper's `color` + base font defaults on the same\n// axisLabel block. Arrays + primitives replace outright.\nexport function mergeOptionBlock<T extends Record<string, any>>(base: T, user: Partial<T> | undefined): T {\n  if (!user) return base\n  const out: any = { ...base }\n  for (const k of Object.keys(user)) {\n    const bv = (base as any)[k]\n    const uv = (user as any)[k]\n    if (\n      bv != null &&\n      uv != null &&\n      typeof bv === 'object' &&\n      typeof uv === 'object' &&\n      !Array.isArray(bv) &&\n      !Array.isArray(uv)\n    ) {\n      out[k] = { ...bv, ...uv }\n    } else {\n      out[k] = uv\n    }\n  }\n  return out\n}\n\n// Default gauge stoplight: teal (safe) -> amber (warning) -> red (danger).\n// Static because gauges have semantic meaning (green safe / red danger) that\n// we deliberately don't theme-flip.\nexport const gaugeThresholds: [number, string][] = [\n  [0.6, '#14b8a6'],\n  [0.85, '#f59e0b'],\n  [1, '#dc2626'],\n]\n\n/**\n * Re-render callback subscription for theme flips: bumps every listener\n * whenever `<html>` class/style changes (the typical shadcn dark-mode pivot)\n * so chart components can rebuild their options and re-paint. Returns an\n * unsubscribe function. No-op (never fires) outside the DOM.\n */\nexport function onChartThemeChange(cb: () => void): () => void {\n  if (typeof window === 'undefined' || typeof MutationObserver === 'undefined') return () => {}\n  const observer = new MutationObserver(() => cb())\n  observer.observe(document.documentElement, { attributes: true, attributeFilter: ['class', 'style', 'data-theme'] })\n  return () => observer.disconnect()\n}\n",
      "type": "registry:ui",
      "target": "~/src/app/components/ui/charts/use-chart-theme.ts"
    }
  ],
  "dependencies": [
    "echarts"
  ],
  "devDependencies": [],
  "registryDependencies": [],
  "description": "Bar chart wrapper around Apache ECharts. Vertical, horizontal, grouped, stacked, and negative-value variants. Theme-aware via registry tokens.",
  "categories": [
    "chart"
  ]
}