opt-cc/static/src/app/statistic/statistic.component.ts

86 lines
2.0 KiB
TypeScript
Raw Normal View History

2017-07-29 12:59:51 +02:00
import {Component} from "@angular/core";
2017-07-29 18:00:21 +02:00
import {AppComponent} from "../app.component";
2017-07-29 12:59:51 +02:00
import {WarService} from "../services/war-service/war.service";
@Component({
selector: 'statistic',
templateUrl: './statistic.component.html',
styleUrls: ['./statistic.component.css']
})
export class StatisticComponent {
chartData: any[] = [];
colorScheme = {
2017-07-29 18:00:21 +02:00
domain: ['#0000FF', '#B22222', '#595DC7', '#B25D62']
2017-07-29 12:59:51 +02:00
};
2017-07-29 18:00:21 +02:00
constructor(private appComponent: AppComponent,
private warService: WarService) {
2017-07-29 12:59:51 +02:00
}
ngOnInit() {
2017-07-29 18:00:21 +02:00
let wars = this.appComponent.wars;
if (wars.length === 0) {
this.warService.getAllWars().subscribe(items => {
this.initChart(items);
2017-07-29 12:59:51 +02:00
})
2017-07-29 18:00:21 +02:00
}
this.initChart(wars);
}
initChart(wars: any[]) {
let updateObj = [
{
"name": "NATO",
"series": []
},
{
"name": "CSAT",
"series": []
},
{
"name": "Anz. Spieler NATO",
"series": []
},
{
"name": "Anz. Spieler CSAT",
"series": []
}];
for (let i = wars.length - 1; i >= 0; i--) {
let isoDate = wars[i].date.slice(0, 10);
let dayDate = parseInt(isoDate.slice(8, 10)) + 1;
let warDateString = (dayDate < 10 ? "0" + dayDate : dayDate) + '.'
+ isoDate.slice(5, 7) + '.' + isoDate.slice(0, 4);
let bluforData = {
name: warDateString,
value: wars[i].ptBlufor
};
updateObj[0].series.push(bluforData);
let opforData = {
name: warDateString,
value: wars[i].ptOpfor
};
updateObj[1].series.push(opforData);
let bluforPlayers = {
name: warDateString,
value: 13
};
updateObj[2].series.push(bluforPlayers);
let opforPlayers = {
name: warDateString,
value: 13
};
updateObj[3].series.push(opforPlayers);
}
this.chartData = updateObj;
Object.assign(this, this.chartData)
}
2017-07-29 12:59:51 +02:00
onSelect(event) {
console.log(event);
}
}