2017-01-21 16:46:34 +03:00
|
|
|
import {Component, ViewChild, Input, Output, ElementRef, EventEmitter} from '@angular/core';
|
2016-05-06 13:28:11 +03:00
|
|
|
|
2016-05-24 16:40:17 +03:00
|
|
|
import {BaThemePreloader} from '../../../theme/services';
|
|
|
|
|
|
2016-05-06 13:28:11 +03:00
|
|
|
import './baAmChart.loader.ts';
|
2016-05-06 16:10:51 +03:00
|
|
|
import {BaAmChartThemeService} from './baAmChartTheme.service';
|
2016-05-06 13:28:11 +03:00
|
|
|
|
2017-01-21 16:46:34 +03:00
|
|
|
import 'style-loader!./baAmChart.scss';
|
|
|
|
|
|
2016-05-06 13:28:11 +03:00
|
|
|
@Component({
|
|
|
|
|
selector: 'ba-am-chart',
|
2017-01-09 11:37:57 +03:00
|
|
|
templateUrl: './baAmChart.html',
|
2016-05-06 16:10:51 +03:00
|
|
|
providers: [BaAmChartThemeService],
|
2016-05-06 13:28:11 +03:00
|
|
|
})
|
|
|
|
|
export class BaAmChart {
|
|
|
|
|
|
|
|
|
|
@Input() baAmChartConfiguration:Object;
|
|
|
|
|
@Input() baAmChartClass:string;
|
|
|
|
|
@Output() onChartReady = new EventEmitter<any>();
|
|
|
|
|
|
2017-01-10 11:32:26 +03:00
|
|
|
@ViewChild('baAmChart') public _selector:ElementRef;
|
2016-05-20 19:46:37 +03:00
|
|
|
|
|
|
|
|
constructor (private _baAmChartThemeService:BaAmChartThemeService) {
|
2016-05-24 16:40:17 +03:00
|
|
|
this._loadChartsLib();
|
2016-05-06 16:10:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
|
AmCharts.themes.blur = this._baAmChartThemeService.getTheme();
|
2016-05-06 13:28:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngAfterViewInit() {
|
2016-05-20 19:46:37 +03:00
|
|
|
let chart = AmCharts.makeChart(this._selector.nativeElement, this.baAmChartConfiguration);
|
2016-05-06 13:28:11 +03:00
|
|
|
this.onChartReady.emit(chart);
|
|
|
|
|
}
|
2016-05-24 16:40:17 +03:00
|
|
|
|
|
|
|
|
private _loadChartsLib():void {
|
|
|
|
|
BaThemePreloader.registerLoader(new Promise((resolve, reject) => {
|
2016-08-29 17:33:12 +03:00
|
|
|
let amChartsReadyMsg = 'AmCharts ready';
|
|
|
|
|
|
|
|
|
|
if (AmCharts.isReady) {
|
|
|
|
|
resolve(amChartsReadyMsg);
|
|
|
|
|
} else {
|
|
|
|
|
AmCharts.ready(function () {
|
|
|
|
|
resolve(amChartsReadyMsg);
|
|
|
|
|
});
|
|
|
|
|
}
|
2016-05-24 16:40:17 +03:00
|
|
|
}));
|
|
|
|
|
}
|
2016-05-06 13:28:11 +03:00
|
|
|
}
|