ngx-admin/src/app/pages/dashboard/pieChart/pieChart.component.ts

58 lines
1.4 KiB
TypeScript
Raw Normal View History

2016-05-11 17:38:01 +03:00
import {Component, ViewEncapsulation} from '@angular/core';
2016-05-04 16:04:14 +03:00
2016-05-04 18:01:33 +03:00
import {PieChartService} from './pieChart.service';
2016-05-04 17:57:34 +03:00
import './pieChart.loader.ts';
import 'style!./pieChart.scss';
2016-05-04 16:04:14 +03:00
@Component({
selector: 'pie-chart',
templateUrl: './pieChart.html'
2016-05-04 16:04:14 +03:00
})
2016-05-13 10:43:29 +03:00
// TODO: move easypiechart to component
2016-05-04 16:04:14 +03:00
export class PieChart {
2016-05-04 18:01:33 +03:00
public charts: Array<Object>;
2016-05-04 17:57:34 +03:00
private _init = false;
2016-05-04 16:04:14 +03:00
2016-05-04 18:01:33 +03:00
constructor(private _pieChartService: PieChartService) {
this.charts = this._pieChartService.getData();
2016-05-04 16:04:14 +03:00
}
ngAfterViewInit() {
2016-05-04 17:57:34 +03:00
if (!this._init) {
this._loadPieCharts();
this._updatePieCharts();
this._init = true;
2016-05-04 16:04:14 +03:00
}
}
2016-05-04 17:57:34 +03:00
private _loadPieCharts() {
2016-05-04 16:04:14 +03:00
jQuery('.chart').each(function () {
let chart = jQuery(this);
2016-05-04 17:57:34 +03:00
chart.easyPieChart({
2016-05-04 16:04:14 +03:00
easing: 'easeOutBounce',
onStep: function (from, to, percent) {
jQuery(this.el).find('.percent').text(Math.round(percent));
2016-05-04 16:04:14 +03:00
},
barColor: jQuery(this).attr('data-rel'),
2016-05-04 16:04:14 +03:00
trackColor: 'rgba(0,0,0,0)',
size: 84,
scaleLength: 0,
animation: 2000,
lineWidth: 9,
lineCap: 'round',
});
});
}
2016-05-04 17:57:34 +03:00
private _updatePieCharts() {
2016-09-19 14:30:30 +03:00
let getRandomArbitrary = (min, max) => { return Math.random() * (max - min) + min; };
2016-05-04 16:04:14 +03:00
jQuery('.pie-charts .chart').each(function(index, chart) {
jQuery(chart).data('easyPieChart').update(getRandomArbitrary(55, 90));
2016-05-04 16:04:14 +03:00
});
}
}