{"version":3,"sources":["../../src/app/components/chart/chart.ts"],"names":["UIChart","el","this","plugins","responsive","onDataSelect","EventEmitter","_options","Object","defineProperty","prototype","_data","val","reinit","ngAfterViewInit","initChart","initialized","onCanvasClick","event","chart","element","getElementAtEvent","dataset","getDatasetAtEvent","emit","originalEvent","opts","options","height","width","maintainAspectRatio","Chart","nativeElement","children","type","data","getCanvas","getBase64Image","toBase64Image","generateLegend","refresh","update","destroy","ngOnDestroy","Component","args","selector","template","changeDetection","ChangeDetectionStrategy","OnPush","encapsulation","ViewEncapsulation","None","ElementRef","Input","Output","NgModule","imports","CommonModule","exports","declarations"],"mappings":"+uBAoCI,SAAAA,EAAmBC,GAAAC,KAAAD,GAAAA,EAlBVC,KAAAC,QAAiB,GAMjBD,KAAAE,YAAsB,EAErBF,KAAAG,aAAkC,IAAIC,EAAAA,aAMhDJ,KAAAK,SAAgB,UAMhBC,OAAAC,eAAaT,EAAAU,UAAA,OAAI,KAAjB,WACI,OAAOR,KAAKS,WAGhB,SAASC,GACLV,KAAKS,MAAQC,EACbV,KAAKW,0CAGTL,OAAAC,eAAaT,EAAAU,UAAA,UAAO,KAApB,WACI,OAAOR,KAAKK,cAGhB,SAAYK,GACRV,KAAKK,SAAWK,EAChBV,KAAKW,0CAGTb,EAAAU,UAAAI,gBAAA,WACIZ,KAAKa,YACLb,KAAKc,aAAc,GAGvBhB,EAAAU,UAAAO,cAAA,SAAcC,GACV,GAAIhB,KAAKiB,MAAO,CACZ,IAAIC,EAAUlB,KAAKiB,MAAME,kBAAkBH,GACvCI,EAAUpB,KAAKiB,MAAMI,kBAAkBL,GACvCE,GAAWA,EAAQ,IAAME,GACzBpB,KAAKG,aAAamB,KAAK,CAACC,cAAeP,EAAOE,QAASA,EAAQ,GAAIE,QAASA,MAKxFtB,EAAAU,UAAAK,UAAA,WACI,IAAIW,EAAOxB,KAAKyB,SAAS,GACzBD,EAAKtB,WAAaF,KAAKE,WAGnBsB,EAAKtB,aAAaF,KAAK0B,QAAQ1B,KAAK2B,SACpCH,EAAKI,qBAAsB,GAG/B5B,KAAKiB,MAAQ,IAAIY,EAAM7B,KAAKD,GAAG+B,cAAcC,SAAS,GAAGA,SAAS,GAAI,CAClEC,KAAMhC,KAAKgC,KACXC,KAAMjC,KAAKiC,KACXR,QAASzB,KAAKyB,QACdxB,QAASD,KAAKC,WAItBH,EAAAU,UAAA0B,UAAA,WACI,OAAOlC,KAAKD,GAAG+B,cAAcC,SAAS,GAAGA,SAAS,IAGtDjC,EAAAU,UAAA2B,eAAA,WACI,OAAOnC,KAAKiB,MAAMmB,iBAGtBtC,EAAAU,UAAA6B,eAAA,WACI,GAAIrC,KAAKiB,MACL,OAAOjB,KAAKiB,MAAMoB,kBAI1BvC,EAAAU,UAAA8B,QAAA,WACQtC,KAAKiB,OACLjB,KAAKiB,MAAMsB,UAInBzC,EAAAU,UAAAG,OAAA,WACQX,KAAKiB,QACLjB,KAAKiB,MAAMuB,UACXxC,KAAKa,cAIbf,EAAAU,UAAAiC,YAAA,WACQzC,KAAKiB,QACLjB,KAAKiB,MAAMuB,UACXxC,KAAKc,aAAc,EACnBd,KAAKiB,MAAQ,gCAnHxByB,EAAAA,UAASC,KAAA,CAAC,CACPC,SAAU,UACVC,SAAU,qVAKVC,gBAAiBC,EAAAA,wBAAwBC,OACzCC,cAAeC,EAAAA,kBAAkBC,kDAZVC,EAAAA,4CAgBtBC,EAAAA,uBAEAA,EAAAA,qBAEAA,EAAAA,sBAEAA,EAAAA,0BAEAA,EAAAA,4BAEAC,EAAAA,qBAYAD,EAAAA,uBASAA,EAAAA,eAkFL,iCALCE,EAAAA,SAAQZ,KAAA,CAAC,CACNa,QAAS,CAACC,EAAAA,cACVC,QAAS,CAAC5D,GACV6D,aAAc,CAAC7D","sourcesContent":["import {NgModule,Component,ElementRef,AfterViewInit,OnDestroy,Input,Output,EventEmitter,ChangeDetectionStrategy, ViewEncapsulation} from '@angular/core';\nimport {CommonModule} from '@angular/common';\nimport * as Chart from 'chart.js';\n\n@Component({\n selector: 'p-chart',\n template: `\n
\n \n
\n `,\n changeDetection: ChangeDetectionStrategy.OnPush,\n encapsulation: ViewEncapsulation.None\n})\nexport class UIChart implements AfterViewInit, OnDestroy {\n\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 initialized: boolean;\n \n _data: any;\n\n _options: any = {};\n\n chart: any;\n\n constructor(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\n onCanvasClick(event) {\n if (this.chart) {\n let element = this.chart.getElementAtEvent(event);\n let dataset = this.chart.getDatasetAtEvent(event);\n if (element && element[0] && dataset) {\n this.onDataSelect.emit({originalEvent: event, element: element[0], dataset: dataset});\n }\n }\n }\n\n initChart() {\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 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"]}