2017-07-29 17:21:45 +02:00
|
|
|
// vim: set tw=80 ts=2 sw=2 sts=2 :
|
|
|
|
|
2018-06-10 17:26:26 +02:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
|
|
|
import { ActivatedRoute, ParamMap } from '@angular/router';
|
2017-07-29 17:18:36 +02:00
|
|
|
|
2018-06-09 23:34:03 +02:00
|
|
|
import { Logger } from '@nsalaun/ng-logger';
|
|
|
|
|
|
|
|
import * as _ from 'underscore';
|
|
|
|
|
|
|
|
import { Category } from './category';
|
2017-07-29 17:18:36 +02:00
|
|
|
import { CategoryService } from './category.service';
|
|
|
|
|
2018-06-09 23:34:03 +02:00
|
|
|
|
2017-07-29 17:18:36 +02:00
|
|
|
@Component({
|
2017-07-29 17:21:45 +02:00
|
|
|
selector: 'category-chart',
|
2018-06-09 23:34:03 +02:00
|
|
|
template: `<ngx-charts-bar-horizontal-2d
|
|
|
|
[results]="data"
|
|
|
|
[xAxis]="showXAxis"
|
|
|
|
[yAxis]="showYAxis"
|
|
|
|
[showXAxisLabel]="showXAxisLabel"
|
|
|
|
[showYAxisLabel]="showYAxisLabel"
|
|
|
|
barPadding="1">
|
|
|
|
</ngx-charts-bar-horizontal-2d>`
|
2017-07-29 17:18:36 +02:00
|
|
|
})
|
2018-06-10 17:26:26 +02:00
|
|
|
export class CategoryChartComponent implements OnInit {
|
2018-06-09 23:34:03 +02:00
|
|
|
public data;
|
|
|
|
|
|
|
|
public showXAxis = true;
|
|
|
|
public showYAxis = true;
|
|
|
|
public showXAxisLabel = false;
|
|
|
|
public showYAxisLabel = false;
|
2017-07-29 17:21:45 +02:00
|
|
|
|
|
|
|
constructor(
|
2018-06-10 17:26:26 +02:00
|
|
|
private activatedRoute: ActivatedRoute,
|
|
|
|
private logger: Logger,
|
2017-07-29 17:21:45 +02:00
|
|
|
private categoryService: CategoryService,
|
2018-06-09 23:34:03 +02:00
|
|
|
) {
|
|
|
|
this.data = [];
|
|
|
|
}
|
2017-07-29 17:21:45 +02:00
|
|
|
|
2018-06-10 17:26:26 +02:00
|
|
|
loadData() {
|
|
|
|
let accountId = this.activatedRoute.snapshot.paramMap.get('accountId');
|
|
|
|
let fromDay = this.activatedRoute.snapshot.queryParamMap.get('from');
|
|
|
|
let toDay = this.activatedRoute.snapshot.queryParamMap.get('to');
|
|
|
|
|
2017-07-29 17:21:45 +02:00
|
|
|
this.categoryService.query(
|
2018-06-10 17:26:26 +02:00
|
|
|
+accountId,
|
|
|
|
fromDay,
|
|
|
|
toDay
|
2018-06-09 23:34:03 +02:00
|
|
|
).map((results: Category[]) => {
|
|
|
|
return _.sortBy(results, 'income').reverse();
|
|
|
|
}).map((results: Category[]) => {
|
|
|
|
return results.map((result: Category) => {
|
|
|
|
return {
|
|
|
|
'name': result.category,
|
|
|
|
'series': [{
|
|
|
|
'name': 'expenses',
|
|
|
|
'value': -Number(result.expenses)
|
|
|
|
}, {
|
|
|
|
'name': 'revenues',
|
|
|
|
'value': Number(result.revenues)
|
|
|
|
}]
|
|
|
|
};
|
2017-07-29 17:21:45 +02:00
|
|
|
});
|
2018-06-09 23:34:03 +02:00
|
|
|
}).subscribe((results) => {
|
|
|
|
this.data = results;
|
2017-07-29 17:21:45 +02:00
|
|
|
});
|
2018-06-09 23:34:03 +02:00
|
|
|
}
|
2017-07-29 17:21:45 +02:00
|
|
|
|
2018-06-10 17:26:26 +02:00
|
|
|
ngOnInit() {
|
|
|
|
this.activatedRoute.queryParamMap.subscribe(() => {this.loadData();});
|
2018-06-09 23:56:16 +02:00
|
|
|
}
|
2017-07-29 17:18:36 +02:00
|
|
|
}
|