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

80 lines
1.8 KiB
TypeScript
Raw Normal View History

2016-05-04 16:04:14 +03:00
import {Component, ViewEncapsulation} from 'angular2/core';
2016-05-04 17:57:34 +03:00
import {BaCard} from '../../../theme/components';
import './pieChart.loader.ts';
2016-05-04 16:04:14 +03:00
@Component({
selector: 'pie-chart',
encapsulation: ViewEncapsulation.None,
directives: [BaCard],
styles: [require('./pieChart.scss')],
template: require('./pieChart.html')
})
export class PieChart {
charts = [
{
color: 'rgba(255,255,255,0.4)',
description: 'New Visits',
stats: '57,820',
icon: 'person',
}, {
color: 'rgba(255,255,255,0.4)',
description: 'Purchases',
stats: '$ 89,745',
icon: 'money',
}, {
color: 'rgba(255,255,255,0.4)',
description: 'Active Users',
stats: '178,391',
icon: 'face',
}, {
color: 'rgba(255,255,255,0.4)',
description: 'Returned',
stats: '32,592',
icon: 'refresh',
}
];
2016-05-04 17:57:34 +03:00
private _init = false;
2016-05-04 16:04:14 +03:00
constructor() {
}
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
$('.chart').each(function () {
2016-05-04 17:57:34 +03:00
let chart = $(this);
chart.easyPieChart({
2016-05-04 16:04:14 +03:00
easing: 'easeOutBounce',
onStep: function (from, to, percent) {
2016-05-04 17:57:34 +03:00
$(this.el).find('.percent').text(Math.round(percent));
2016-05-04 16:04:14 +03:00
},
barColor: $(this).attr('data-rel'),
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-05-04 16:04:14 +03:00
let getRandomArbitrary = (min, max) => { return Math.random() * (max - min) + min };
$('.pie-charts .chart').each(function(index, chart) {
$(chart).data('easyPieChart').update(getRandomArbitrary(55, 90));
});
}
}