{"version":3,"file":"primeng-chart.mjs","sources":["../../src/app/components/chart/chart.ts","../../src/app/components/chart/primeng-chart.ts"],"sourcesContent":["import { CommonModule, isPlatformBrowser } from '@angular/common';\nimport { AfterViewInit, ChangeDetectionStrategy, Component, ElementRef, EventEmitter, Inject, Input, NgModule, OnDestroy, Output, PLATFORM_ID, ViewEncapsulation } from '@angular/core';\nimport Chart from 'chart.js/auto';\nimport { LicenseManager } from 'primeng/api';\n\n@Component({\n selector: 'p-chart',\n template: `\n
\n \n
\n `,\n changeDetection: ChangeDetectionStrategy.OnPush,\n encapsulation: ViewEncapsulation.None,\n host: {\n class: 'p-element'\n }\n})\nexport class UIChart implements AfterViewInit, OnDestroy {\n @Input() type: string;\n\n @Input() plugins: any[] = [];\n\n @Input() width: string;\n\n @Input() height: string;\n\n @Input() responsive: boolean = true;\n\n @Output() onDataSelect: EventEmitter = new EventEmitter();\n\n isBrowser: boolean = false;\n\n initialized: boolean;\n\n _data: any;\n\n _options: any = {};\n\n chart: any;\n\n constructor(@Inject(PLATFORM_ID) private platformId: any, public el: ElementRef) {}\n\n @Input() get data(): any {\n return this._data;\n }\n\n set data(val: any) {\n this._data = val;\n this.reinit();\n }\n\n @Input() get options(): any {\n return this._options;\n }\n\n set options(val: any) {\n this._options = val;\n this.reinit();\n }\n\n ngAfterViewInit() {\n this.initChart();\n this.initialized = true;\n\n LicenseManager.check();\n }\n\n onCanvasClick(event) {\n if (this.chart) {\n const element = this.chart.getElementsAtEventForMode(event, 'nearest', { intersect: true }, false);\n const dataset = this.chart.getElementsAtEventForMode(event, 'dataset', { intersect: true }, false);\n\n if (element && element[0] && dataset) {\n this.onDataSelect.emit({ originalEvent: event, element: element[0], dataset: dataset });\n }\n }\n }\n\n initChart() {\n if (isPlatformBrowser(this.platformId)) {\n let opts = this.options || {};\n opts.responsive = this.responsive;\n\n // allows chart to resize in responsive mode\n if (opts.responsive && (this.height || this.width)) {\n opts.maintainAspectRatio = false;\n }\n\n this.chart = new Chart(this.el.nativeElement.children[0].children[0], {\n type: this.type,\n data: this.data,\n options: this.options,\n plugins: this.plugins\n });\n }\n }\n\n getCanvas() {\n return this.el.nativeElement.children[0].children[0];\n }\n\n getBase64Image() {\n return this.chart.toBase64Image();\n }\n\n generateLegend() {\n if (this.chart) {\n return this.chart.generateLegend();\n }\n }\n\n refresh() {\n if (this.chart) {\n this.chart.update();\n }\n }\n\n reinit() {\n if (this.chart) {\n this.chart.destroy();\n this.initChart();\n }\n }\n\n ngOnDestroy() {\n if (this.chart) {\n this.chart.destroy();\n this.initialized = false;\n this.chart = null;\n }\n }\n}\n\n@NgModule({\n imports: [CommonModule],\n exports: [UIChart],\n declarations: [UIChart]\n})\nexport class ChartModule {}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":[],"mappings":";;;;;;MAkBa,OAAO,CAAA;IAuBhB,WAAyC,CAAA,UAAe,EAAS,EAAc,EAAA;AAAtC,QAAA,IAAU,CAAA,UAAA,GAAV,UAAU,CAAK;AAAS,QAAA,IAAE,CAAA,EAAA,GAAF,EAAE,CAAY;AApBtE,QAAA,IAAO,CAAA,OAAA,GAAU,EAAE,CAAC;AAMpB,QAAA,IAAU,CAAA,UAAA,GAAY,IAAI,CAAC;AAE1B,QAAA,IAAA,CAAA,YAAY,GAAsB,IAAI,YAAY,EAAE,CAAC;AAE/D,QAAA,IAAS,CAAA,SAAA,GAAY,KAAK,CAAC;AAM3B,QAAA,IAAQ,CAAA,QAAA,GAAQ,EAAE,CAAC;KAIgE;AAEnF,IAAA,IAAa,IAAI,GAAA;QACb,OAAO,IAAI,CAAC,KAAK,CAAC;KACrB;IAED,IAAI,IAAI,CAAC,GAAQ,EAAA;AACb,QAAA,IAAI,CAAC,KAAK,GAAG,GAAG,CAAC;QACjB,IAAI,CAAC,MAAM,EAAE,CAAC;KACjB;AAED,IAAA,IAAa,OAAO,GAAA;QAChB,OAAO,IAAI,CAAC,QAAQ,CAAC;KACxB;IAED,IAAI,OAAO,CAA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