import * as i0 from '@angular/core'; import { EventEmitter, Component, ChangeDetectionStrategy, ViewEncapsulation, Input, Output, NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import Chart from 'chart.js/auto'; class UIChart { constructor(el) { this.el = el; this.plugins = []; this.responsive = true; this.onDataSelect = new EventEmitter(); this._options = {}; } get data() { return this._data; } set data(val) { this._data = val; this.reinit(); } get options() { return this._options; } set options(val) { this._options = val; this.reinit(); } ngAfterViewInit() { this.initChart(); this.initialized = true; } onCanvasClick(event) { if (this.chart) { const element = this.chart.getElementsAtEventForMode(event, 'nearest', { intersect: true }, false); const dataset = this.chart.getElementsAtEventForMode(event, 'dataset', { intersect: true }, false); if (element && element[0] && dataset) { this.onDataSelect.emit({ originalEvent: event, element: element[0], dataset: dataset }); } } } initChart() { let opts = this.options || {}; opts.responsive = this.responsive; // allows chart to resize in responsive mode if (opts.responsive && (this.height || this.width)) { opts.maintainAspectRatio = false; } this.chart = new Chart(this.el.nativeElement.children[0].children[0], { type: this.type, data: this.data, options: this.options, plugins: this.plugins }); } getCanvas() { return this.el.nativeElement.children[0].children[0]; } getBase64Image() { return this.chart.toBase64Image(); } generateLegend() { if (this.chart) { return this.chart.generateLegend(); } } refresh() { if (this.chart) { this.chart.update(); } } reinit() { if (this.chart) { this.chart.destroy(); this.initChart(); } } ngOnDestroy() { if (this.chart) { this.chart.destroy(); this.initialized = false; this.chart = null; } } } UIChart.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: UIChart, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Component }); UIChart.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.0.0", type: UIChart, selector: "p-chart", inputs: { type: "type", plugins: "plugins", width: "width", height: "height", responsive: "responsive", data: "data", options: "options" }, outputs: { onDataSelect: "onDataSelect" }, host: { classAttribute: "p-element" }, ngImport: i0, template: `