2017-12-13 12:37:11 +00:00
import { Component , OnInit , Input , Output , EventEmitter } from '@angular/core' ;
2017-12-14 16:44:23 +00:00
import { CustPiesService } from '../providers/cust-pies.service' ;
2017-12-13 12:37:11 +00:00
import { DataType } from '../shared/data-types.enum' ;
import { ChartData } from '../_interfaces/chart-data' ;
@Component ( {
selector : 'panel-pie' ,
templateUrl : 'pie-panel.component.html' ,
} )
export class PiePanel implements OnInit {
public chartType = 'doughnut' ;
public chartLegend = true ;
2017-12-14 16:44:23 +00:00
public doughnutChartLabels : string [ ] = [ ] ;
public doughnutChartData : number [ ] = [ ] ;
2017-12-13 12:37:11 +00:00
2017-12-14 16:44:23 +00:00
//Old
2017-12-13 12:37:11 +00:00
// public mainChartElements = 7;
constructor (
2017-12-14 16:44:23 +00:00
private pieService : CustPiesService ,
2017-12-13 12:37:11 +00:00
) { }
public ngOnInit ( ) : void {
2017-12-14 16:44:23 +00:00
this . pieService . getPie ( )
. subscribe ( result = > this . setData ( result . pie ) ) ;
2017-12-13 12:37:11 +00:00
}
2017-12-14 16:44:23 +00:00
private setData ( data : any ) {
this . doughnutChartData = Object . values ( data ) ;
// setTimeout is currently a workaround for ng2-charts labels
setTimeout ( ( ) = > this . doughnutChartLabels = Object . keys ( data ) , 0 ) ;
}
2017-12-13 12:37:11 +00:00
// convert Hex to RGBA
public convertHex ( hex : string , opacity : number ) {
hex = hex . replace ( '#' , '' ) ;
const r = parseInt ( hex . substring ( 0 , 2 ) , 16 ) ;
const g = parseInt ( hex . substring ( 2 , 4 ) , 16 ) ;
const b = parseInt ( hex . substring ( 4 , 6 ) , 16 ) ;
const rgba = 'rgba(' + r + ', ' + g + ', ' + b + ', ' + opacity / 100 + ')' ;
return rgba ;
}
// events
public chartClicked ( e : any ) : void {
console . log ( e ) ;
}
public chartHovered ( e : any ) : void {
console . log ( e ) ;
}
}