{"version":3,"file":"acorex-charts-chart-legend.mjs","sources":["../../../../packages/charts/chart-legend/src/lib/chart-legend.component.ts","../../../../packages/charts/chart-legend/src/lib/chart-legend.component.html","../../../../packages/charts/chart-legend/src/acorex-charts-chart-legend.ts"],"sourcesContent":["import { CommonModule } from '@angular/common';\nimport { Component, ElementRef, ViewEncapsulation, computed, input, output, signal, viewChild } from '@angular/core';\nimport { AXChartLegendCompatible, AXChartLegendItem, AXChartLegendOptions } from './chart-legend.type';\n\n@Component({\n  selector: 'ax-chart-legend',\n  templateUrl: './chart-legend.component.html',\n  styleUrls: ['./chart-legend.component.css'],\n  imports: [CommonModule],\n\n  encapsulation: ViewEncapsulation.None,\n})\nexport class AXChartLegendComponent {\n  /**\n   * Chart component instance\n   * Must implement AXChartLegendCompatible interface\n   */\n  chart = input.required<AXChartLegendCompatible>();\n\n  /**\n   * Configuration options for the legend\n   */\n  options = input<AXChartLegendOptions>({});\n\n  /**\n   * Event emitted when a legend item is clicked\n   * Returns the item that was clicked\n   */\n  itemClick = output<AXChartLegendItem>();\n\n  /**\n   * Event emitted when the mouse enters a legend item\n   */\n  itemMouseEnter = output<AXChartLegendItem>();\n\n  /**\n   * Event emitted when the mouse leaves a legend item\n   */\n  itemMouseLeave = output<AXChartLegendItem>();\n\n  /**\n   * Reference to legend container for measuring dimensions\n   */\n  legendContainer = viewChild<ElementRef<HTMLDivElement>>('legendContainer');\n\n  private readonly interactionVersion = signal(0);\n\n  // Computed values for the template\n  protected showValues = computed(() => this.options()?.showValues !== false);\n  protected showPercentage = computed(() => this.options()?.showPercentage !== false);\n  protected containerClass = computed(() => {\n    const opts = this.options();\n    const className = opts?.className || '';\n    const mode = opts?.mode || 'vertical';\n    return {\n      'ax-chart-legend': true,\n      [className]: !!className,\n      [`ax-legend-${mode}`]: true,\n    };\n  });\n\n  // Track if the legend is interactive\n  protected isInteractive = computed(() => this.options()?.interactive !== false);\n\n  // Compute the items to display from the chart\n  protected displayItems = computed(() => {\n    const chart = this.chart();\n    chart.legendStateVersion?.();\n    this.interactionVersion();\n    return chart.getLegendItems();\n  });\n\n  /**\n   * Handle clicks on legend items\n   */\n  protected onItemClick(item: AXChartLegendItem): void {\n    const chartInstance = this.chart();\n\n    if (this.isInteractive()) {\n      chartInstance.toggleSegment(item.id);\n      this.interactionVersion.update((version) => version + 1);\n    }\n\n    const refreshedItem = this.displayItems().find((legendItem) => legendItem.id === item.id) ?? item;\n    this.itemClick.emit(refreshedItem);\n  }\n\n  /**\n   * Handle mouse enter on legend items\n   */\n  protected onItemMouseEnter(item: AXChartLegendItem): void {\n    this.itemMouseEnter.emit(item);\n    this.chart().highlightSegment(item.id);\n  }\n\n  /**\n   * Handle mouse leave on legend items\n   */\n  protected onItemMouseLeave(item: AXChartLegendItem): void {\n    this.itemMouseLeave.emit(item);\n    this.chart().highlightSegment(null);\n  }\n\n  protected hasValidPercentage(value: number | undefined): boolean {\n    return value != null && !Number.isNaN(value);\n  }\n\n  /**\n   * Get legend container dimensions\n   */\n  getDimensions(): { width: number; height: number } {\n    if (!this.legendContainer()?.nativeElement) {\n      return { width: 0, height: 0 };\n    }\n\n    return {\n      width: this.legendContainer().nativeElement.offsetWidth,\n      height: this.legendContainer().nativeElement.offsetHeight,\n    };\n  }\n}\n","<div #legendContainer [ngClass]=\"containerClass()\">\n  @for (item of displayItems(); track item.id) {\n  <div class=\"ax-legend-item\" [class.ax-legend-item-hidden]=\"item.hidden\" (click)=\"onItemClick(item)\"\n    (mouseenter)=\"onItemMouseEnter(item)\" (mouseleave)=\"onItemMouseLeave(item)\">\n    <span class=\"ax-legend-color\" [style.background-color]=\"item.color\"></span>\n    <span class=\"ax-legend-name\">{{ item.name }}</span>\n    @if (showValues()) {\n    <span class=\"ax-legend-value\">{{ item.value | number: '1.0-2' }}</span>\n    }\n    @if (showPercentage() && hasValidPercentage(item.percentage)) {\n    <span class=\"ax-legend-percentage\">{{ item.percentage | number: '1.0-2' }}%</span>\n    }\n  </div>\n  }\n</div>","/**\n * Generated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