2018-10-09 10:42:28 +02:00
|
|
|
import {Component, OnInit} from '@angular/core';
|
2018-03-07 11:56:50 +01:00
|
|
|
import {ActivatedRoute} from '@angular/router';
|
2018-04-29 10:07:20 +02:00
|
|
|
import {CampaignService} from '../../../services/logs/campaign.service';
|
|
|
|
import {ChartUtils} from '../../../utils/chart-utils';
|
|
|
|
import {Fraction} from '../../../utils/fraction.enum';
|
2018-10-09 10:42:28 +02:00
|
|
|
import {WarService} from '../../../services/logs/war.service';
|
2017-07-29 12:59:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
@Component({
|
2018-08-04 12:54:37 +02:00
|
|
|
selector: 'cc-campaign-overview',
|
|
|
|
templateUrl: './campaign-overview.component.html',
|
2019-02-25 14:32:29 +01:00
|
|
|
styleUrls: ['./campaign-overview.component.scss']
|
2017-07-29 12:59:51 +02:00
|
|
|
})
|
2018-03-08 09:44:35 +01:00
|
|
|
export class StatisticOverviewComponent implements OnInit {
|
2017-07-29 12:59:51 +02:00
|
|
|
|
2018-10-09 10:42:28 +02:00
|
|
|
id: string;
|
2018-03-07 11:56:50 +01:00
|
|
|
|
2018-10-09 10:42:28 +02:00
|
|
|
initialized = false;
|
2017-08-12 23:13:39 +02:00
|
|
|
|
2017-07-30 08:55:14 +02:00
|
|
|
pointData: any[] = [];
|
2017-09-02 10:43:23 +02:00
|
|
|
pointSumData: any[] = [];
|
2017-07-30 08:55:14 +02:00
|
|
|
playerData: any[] = [];
|
2017-10-06 21:41:59 +02:00
|
|
|
currentData: any[] = [];
|
2017-07-29 12:59:51 +02:00
|
|
|
|
|
|
|
colorScheme = {
|
2017-11-07 14:02:49 +01:00
|
|
|
domain: [Fraction.COLOR_BLUFOR, Fraction.COLOR_OPFOR]
|
2017-07-29 12:59:51 +02:00
|
|
|
};
|
2017-09-24 12:04:48 +02:00
|
|
|
gradient = false;
|
|
|
|
xAxis = true;
|
|
|
|
yAxis = true;
|
|
|
|
roundDomains = true;
|
|
|
|
legend = true;
|
|
|
|
legendTitle = '';
|
|
|
|
showXAxisLabel = true;
|
|
|
|
showYAxisLabel = true;
|
2018-03-07 11:56:50 +01:00
|
|
|
yAxisLabel = '';
|
2017-09-24 12:04:48 +02:00
|
|
|
autoscale = true;
|
2018-07-18 20:05:06 +02:00
|
|
|
timeline = false;
|
2017-07-29 12:59:51 +02:00
|
|
|
|
2017-08-12 21:37:31 +02:00
|
|
|
constructor(private route: ActivatedRoute,
|
2018-10-09 10:42:28 +02:00
|
|
|
private campaignService: CampaignService,
|
|
|
|
private warService: WarService) {
|
2017-07-29 12:59:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
2017-08-12 21:37:31 +02:00
|
|
|
this.route.params
|
2018-02-26 09:04:27 +01:00
|
|
|
.map(params => params['id'])
|
|
|
|
.subscribe((id) => {
|
|
|
|
this.id = id;
|
2018-10-09 10:42:28 +02:00
|
|
|
this.initWars();
|
2018-02-26 09:04:27 +01:00
|
|
|
});
|
2017-08-12 21:37:31 +02:00
|
|
|
}
|
|
|
|
|
2018-10-09 10:42:28 +02:00
|
|
|
initWars() {
|
|
|
|
if (this.id === 'all') {
|
|
|
|
this.warService.getAllWars().subscribe((wars) => {
|
2017-08-12 22:27:23 +02:00
|
|
|
this.initChart(wars);
|
2018-10-09 10:42:28 +02:00
|
|
|
});
|
|
|
|
this.timeline = true;
|
|
|
|
} else {
|
|
|
|
this.warService.wars$.subscribe((wars) => {
|
|
|
|
this.initChart(wars);
|
|
|
|
})
|
|
|
|
}
|
2017-07-29 18:00:21 +02:00
|
|
|
}
|
|
|
|
|
2018-08-04 12:54:37 +02:00
|
|
|
goToSlide(index) {
|
|
|
|
switch (parseInt(index, 10)) {
|
2017-10-06 21:41:59 +02:00
|
|
|
case 0:
|
|
|
|
this.currentData = this.pointSumData;
|
2018-10-05 10:29:57 +02:00
|
|
|
this.yAxisLabel = 'stats.graph.select.sum.points';
|
2017-10-06 21:41:59 +02:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
this.currentData = this.pointData;
|
2018-10-05 10:29:57 +02:00
|
|
|
this.yAxisLabel = 'stats.graph.select.battle.points';
|
2017-10-06 21:41:59 +02:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
this.currentData = this.playerData;
|
2018-10-05 10:29:57 +02:00
|
|
|
this.yAxisLabel = 'stats.graph.select.player.count';
|
2017-10-06 21:41:59 +02:00
|
|
|
break;
|
2017-10-06 20:52:52 +02:00
|
|
|
}
|
2017-09-02 13:08:54 +02:00
|
|
|
}
|
|
|
|
|
2017-07-29 18:00:21 +02:00
|
|
|
initChart(wars: any[]) {
|
2017-11-07 14:02:49 +01:00
|
|
|
const pointsObj = ChartUtils.getMultiDataArray(Fraction.BLUFOR, Fraction.OPFOR);
|
|
|
|
const pointsSumObj = ChartUtils.getMultiDataArray(Fraction.BLUFOR, Fraction.OPFOR);
|
|
|
|
const playersObj = ChartUtils.getMultiDataArray(Fraction.BLUFOR, Fraction.OPFOR);
|
2017-09-24 12:38:57 +02:00
|
|
|
|
2017-07-29 18:00:21 +02:00
|
|
|
for (let i = wars.length - 1; i >= 0; i--) {
|
2018-10-08 00:03:01 +02:00
|
|
|
const war = wars[i];
|
|
|
|
if (!war) {
|
|
|
|
continue;
|
|
|
|
}
|
2017-11-07 14:02:49 +01:00
|
|
|
const j = wars.length - i - 1;
|
2018-10-08 00:03:01 +02:00
|
|
|
const warDate = (this.id === 'all') ? new Date(war.date) : ChartUtils.getShortDateString(war.date);
|
2017-07-30 08:55:14 +02:00
|
|
|
|
2017-09-02 10:43:23 +02:00
|
|
|
pointsObj[0].series.push({
|
2018-07-18 19:55:22 +02:00
|
|
|
name: warDate,
|
2018-10-08 00:03:01 +02:00
|
|
|
value: war.ptBlufor
|
2017-09-02 10:43:23 +02:00
|
|
|
});
|
|
|
|
pointsObj[1].series.push({
|
2018-07-18 19:55:22 +02:00
|
|
|
name: warDate,
|
2018-10-08 00:03:01 +02:00
|
|
|
value: war.ptOpfor
|
2017-09-02 10:43:23 +02:00
|
|
|
});
|
|
|
|
pointsSumObj[0].series.push({
|
2018-07-18 19:55:22 +02:00
|
|
|
name: warDate,
|
2017-09-02 10:43:23 +02:00
|
|
|
value: pointsSumObj[0].series[j - 1] ?
|
2018-10-08 00:03:01 +02:00
|
|
|
pointsSumObj[0].series[j - 1].value + war.ptBlufor :
|
|
|
|
war.ptBlufor
|
2017-09-02 10:43:23 +02:00
|
|
|
});
|
|
|
|
pointsSumObj[1].series.push({
|
2018-07-18 19:55:22 +02:00
|
|
|
name: warDate,
|
2017-09-02 10:43:23 +02:00
|
|
|
value: pointsSumObj[1].series[j - 1]
|
2018-10-08 00:03:01 +02:00
|
|
|
? pointsSumObj[1].series[j - 1].value + war.ptOpfor :
|
|
|
|
war.ptOpfor
|
2017-09-02 10:43:23 +02:00
|
|
|
});
|
|
|
|
playersObj[0].series.push({
|
2018-07-18 19:55:22 +02:00
|
|
|
name: warDate,
|
2018-10-08 00:03:01 +02:00
|
|
|
value: war.playersBlufor
|
2017-09-02 10:43:23 +02:00
|
|
|
});
|
|
|
|
playersObj[1].series.push({
|
2018-07-18 19:55:22 +02:00
|
|
|
name: warDate,
|
2018-10-08 00:03:01 +02:00
|
|
|
value: war.playersOpfor
|
2017-09-02 10:43:23 +02:00
|
|
|
});
|
2017-07-29 18:00:21 +02:00
|
|
|
}
|
2017-07-30 08:55:14 +02:00
|
|
|
|
|
|
|
this.pointData = pointsObj;
|
2017-09-02 10:43:23 +02:00
|
|
|
this.pointSumData = pointsSumObj;
|
2017-07-30 08:55:14 +02:00
|
|
|
this.playerData = playersObj;
|
2018-03-07 11:56:50 +01:00
|
|
|
if (this.id !== 'all') {
|
2017-10-06 20:52:52 +02:00
|
|
|
this.goToSlide(0);
|
|
|
|
} else {
|
|
|
|
this.goToSlide(1);
|
|
|
|
}
|
|
|
|
Object.assign(this, this.currentData);
|
2018-10-09 10:42:28 +02:00
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
this.initialized = true;
|
|
|
|
}, 250);
|
2017-07-29 18:00:21 +02:00
|
|
|
}
|
2017-07-29 12:59:51 +02:00
|
|
|
}
|