Indent and cleanup.
This commit is contained in:
parent
02f447d63c
commit
20437ba548
@ -1,24 +1,5 @@
|
|||||||
// vim: set tw=80 ts=4 sw=4 sts=4:
|
// vim: set tw=80 ts=2 sw=2 sts=2 :
|
||||||
/*
|
|
||||||
This file is part of Accountant.
|
|
||||||
|
|
||||||
Accountant is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU Affero General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
Accountant is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU Affero General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Affero General Public License
|
|
||||||
along with Accountant. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
/* jshint node: true */
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
import * as moment from 'moment';
|
|
||||||
import * as c3 from 'c3';
|
import * as c3 from 'c3';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@ -27,101 +8,103 @@ import {
|
|||||||
OnInit, OnChanges
|
OnInit, OnChanges
|
||||||
} from '@angular/core';
|
} from '@angular/core';
|
||||||
|
|
||||||
|
import { Logger } from '@nsalaun/ng-logger';
|
||||||
|
|
||||||
import { Account } from '../accounts/account';
|
import { Account } from '../accounts/account';
|
||||||
import { CategoryService } from './category.service';
|
import { CategoryService } from './category.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'category-chart',
|
selector: 'category-chart',
|
||||||
template: '<div></div>'
|
template: '<div></div>'
|
||||||
})
|
})
|
||||||
export class CategoryChartComponent implements OnInit, OnChanges {
|
export class CategoryChartComponent implements OnInit, OnChanges {
|
||||||
@Input() minDate: Date;
|
@Input() minDate: Date;
|
||||||
@Input() maxDate: Date;
|
@Input() maxDate: Date;
|
||||||
@Input() account: Account;
|
@Input() account: Account;
|
||||||
|
|
||||||
chart: c3.ChartAPI;
|
chart: c3.ChartAPI;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private elementRef: ElementRef,
|
private elementRef: ElementRef,
|
||||||
private categoryService: CategoryService,
|
private categoryService: CategoryService,
|
||||||
) {}
|
private logger: Logger,
|
||||||
|
) {}
|
||||||
|
|
||||||
loadData(account: Account) {
|
loadData(account: Account) {
|
||||||
this.categoryService.query(
|
this.categoryService.query(
|
||||||
account.id,
|
account.id,
|
||||||
this.minDate,
|
this.minDate,
|
||||||
this.maxDate
|
this.maxDate
|
||||||
).subscribe((results) => {
|
).subscribe((results) => {
|
||||||
var expenses=[],
|
var expenses=[],
|
||||||
revenues=[],
|
revenues=[],
|
||||||
colors={},
|
colors={},
|
||||||
names={};
|
names={};
|
||||||
|
|
||||||
var revenuesColor = 'green',
|
var revenuesColor = 'green',
|
||||||
expensesColor = 'orange';
|
expensesColor = 'orange';
|
||||||
|
|
||||||
for(let result of results) {
|
for(let result of results) {
|
||||||
|
if(result.revenues > 0) {
|
||||||
|
var revenuesName = 'revenues-' + result.category;
|
||||||
|
|
||||||
if(result.revenues > 0) {
|
revenues.push([revenuesName, result.revenues]);
|
||||||
var revenuesName = 'revenues-' + result.category;
|
names[revenuesName] = result.category;
|
||||||
|
colors[revenuesName] = revenuesColor;
|
||||||
|
}
|
||||||
|
|
||||||
revenues.push([revenuesName, result.revenues]);
|
if(result.expenses < 0) {
|
||||||
names[revenuesName] = result.category;
|
var expensesName = 'expenses-' + result.category;
|
||||||
colors[revenuesName] = revenuesColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(result.expenses < 0) {
|
expenses.splice(0, 0, [expensesName, -result.expenses]);
|
||||||
var expensesName = 'expenses-' + result.category;
|
names[expensesName] = result.category;
|
||||||
|
colors[expensesName] = expensesColor;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
expenses.splice(0, 0, [expensesName, -result.expenses]);
|
this.chart.unload();
|
||||||
names[expensesName] = result.category;
|
|
||||||
colors[expensesName] = expensesColor;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
this.chart.unload();
|
this.chart.load({
|
||||||
|
columns: revenues.concat(expenses),
|
||||||
|
names: names,
|
||||||
|
colors: colors
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
this.chart.load({
|
ngOnInit() {
|
||||||
columns: revenues.concat(expenses),
|
this.chart = c3.generate({
|
||||||
names: names,
|
bindto: this.elementRef.nativeElement.children[0],
|
||||||
colors: colors
|
data: {
|
||||||
});
|
columns: [],
|
||||||
});
|
type: 'donut',
|
||||||
};
|
order: null,
|
||||||
|
},
|
||||||
|
tooltip: {
|
||||||
|
format: {
|
||||||
|
value: function(value, ratio, id, index) {
|
||||||
|
return value + '€';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
donut: {
|
||||||
|
label: {
|
||||||
|
format: function(value) {
|
||||||
|
return value + '€';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
legend: {
|
||||||
|
show: false
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnChanges(changes) {
|
||||||
this.chart = c3.generate({
|
if('account' in changes && changes.account.currentValue) {
|
||||||
bindto: this.elementRef.nativeElement.children[0],
|
this.loadData(changes.account.currentValue);
|
||||||
data: {
|
} else if (this.account) {
|
||||||
columns: [],
|
this.loadData(this.account);
|
||||||
type: 'donut',
|
}
|
||||||
order: null,
|
};
|
||||||
},
|
|
||||||
tooltip: {
|
|
||||||
format: {
|
|
||||||
value: function(value, ratio, id, index) {
|
|
||||||
return value + '€';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
donut: {
|
|
||||||
label: {
|
|
||||||
format: function(value) {
|
|
||||||
return value + '€';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
legend: {
|
|
||||||
show: false
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
ngOnChanges(changes) {
|
|
||||||
if('account' in changes && changes.account.currentValue) {
|
|
||||||
this.loadData(changes.account.currentValue);
|
|
||||||
} else if (this.account) {
|
|
||||||
this.loadData(this.account);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user