import { Directive, ElementRef, EventEmitter, Input, NgZone, Output, } from '@angular/core'; import { Chart, } from 'chart.js'; import { ThemeService } from './theme.service'; import { distinctUntilChanged } from 'rxjs/operators'; import { merge } from 'lodash-es'; import * as i0 from "@angular/core"; import * as i1 from "./theme.service"; export class BaseChartDirective { constructor(element, zone, themeService) { this.zone = zone; this.themeService = themeService; this.type = 'bar'; this.plugins = []; this.chartClick = new EventEmitter(); this.chartHover = new EventEmitter(); this.subs = []; this.themeOverrides = {}; this.ctx = element.nativeElement.getContext('2d'); this.subs.push(this.themeService.colorschemesOptions .pipe(distinctUntilChanged()) .subscribe((r) => this.themeChanged(r))); } ngOnChanges(changes) { const requireRender = ['type']; const propertyNames = Object.getOwnPropertyNames(changes); if (propertyNames.some((key) => requireRender.includes(key)) || propertyNames.every((key) => changes[key].isFirstChange())) { this.render(); } else { const config = this.getChartConfiguration(); // Using assign to avoid changing the original object reference if (this.chart) { Object.assign(this.chart.config.data, config.data); if (this.chart.config.plugins) { Object.assign(this.chart.config.plugins, config.plugins); } if (this.chart.config.options) { Object.assign(this.chart.config.options, config.options); } } this.update(); } } ngOnDestroy() { if (this.chart) { this.chart.destroy(); this.chart = void 0; } this.subs.forEach((s) => s.unsubscribe()); } render() { if (this.chart) { this.chart.destroy(); } return this.zone.runOutsideAngular(() => (this.chart = new Chart(this.ctx, this.getChartConfiguration()))); } update(duration) { if (this.chart) { this.zone.runOutsideAngular(() => this.chart?.update(duration)); } } hideDataset(index, hidden) { if (this.chart) { this.chart.getDatasetMeta(index).hidden = hidden; this.update(); } } isDatasetHidden(index) { return this.chart?.getDatasetMeta(index)?.hidden; } toBase64Image() { return this.chart?.toBase64Image(); } themeChanged(options) { this.themeOverrides = options; if (this.chart) { if (this.chart.config.options) { Object.assign(this.chart.config.options, this.getChartOptions()); } this.update(); } } getChartOptions() { return merge({ onHover: (event, active) => { if (!this.chartHover.observed && !this.chartHover.observers?.length) { return; } this.zone.run(() => this.chartHover.emit({ event, active })); }, onClick: (event, active) => { if (!this.chartClick.observed && !this.chartClick.observers?.length) { return; } this.zone.run(() => this.chartClick.emit({ event, active })); }, }, this.themeOverrides, this.options, { plugins: { legend: { display: this.legend, }, }, }); } getChartConfiguration() { return { type: this.type, data: this.getChartData(), options: this.getChartOptions(), plugins: this.plugins, }; } getChartData() { return this.data ? this.data : { labels: this.labels || [], datasets: this.datasets || [], }; } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.3", ngImport: i0, type: BaseChartDirective, deps: [{ token: i0.ElementRef }, { token: i0.NgZone }, { token: i1.ThemeService }], target: i0.ɵɵFactoryTarget.Directive }); } static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.3", type: BaseChartDirective, selector: "canvas[baseChart]", inputs: { type: "type", legend: "legend", data: "data", options: "options", plugins: "plugins", labels: "labels", datasets: "datasets" }, outputs: { chartClick: "chartClick", chartHover: "chartHover" }, exportAs: ["base-chart"], usesOnChanges: true, ngImport: i0 }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.3", ngImport: i0, type: BaseChartDirective, decorators: [{ type: Directive, args: [{ // eslint-disable-next-line @angular-eslint/directive-selector selector: 'canvas[baseChart]', exportAs: 'base-chart', }] }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.NgZone }, { type: i1.ThemeService }]; }, propDecorators: { type: [{ type: Input }], legend: [{ type: Input }], data: [{ type: Input }], options: [{ type: Input }], plugins: [{ type: Input }], labels: [{ type: Input }], datasets: [{ type: Input }], chartClick: [{ type: Output }], chartHover: [{ type: Output }] } }); //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmFzZS1jaGFydC5kaXJlY3RpdmUuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi9saWJzL25nMi1jaGFydHMvc3JjL2xpYi9iYXNlLWNoYXJ0LmRpcmVjdGl2ZS50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