discreteBarGraph

This commit is contained in:
Gwenhael Le Moine 2017-11-22 23:13:29 +01:00
parent a2615407de
commit c9140a6aa9
No known key found for this signature in database
GPG key ID: FDFE3669426707A7
3 changed files with 114 additions and 104 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -75,17 +75,17 @@ app.component('dashboard',
ctrl.filter_data = function() { ctrl.filter_data = function() {
_(ctrl.balance.buckets).each(function(bucket) { _(ctrl.balance.buckets).each(function(bucket) {
bucket.data = []; bucket.data = [{ key: 'accounts', values: [] }];
if (_(bucket.accounts_selected).isEmpty() && bucket.score_threshold === 0) { if (_(bucket.accounts_selected).isEmpty() && bucket.score_threshold === 0) {
bucket.data = bucket.raw_data; bucket.data[0].values = bucket.raw_data;
} else { } else {
_(bucket.accounts_selected).each(function(account_selected) { _(bucket.accounts_selected).each(function(account_selected) {
bucket.data = bucket.data.concat($filter('filter')(bucket.raw_data, account_selected, true)); bucket.data[0].values = bucket.data[0].values.concat($filter('filter')(bucket.raw_data, account_selected, true));
}); });
} }
bucket.total_detailed = _.chain(bucket.data) bucket.total_detailed = _.chain(bucket.data[0].values)
.groupBy(function(account) { .groupBy(function(account) {
return account.account.split(':')[0]; return account.account.split(':')[0];
}) })
@ -123,17 +123,22 @@ app.component('dashboard',
} }
}; };
this.pie_graph_options = { this.graph_options = {
chart: { chart: {
type: 'pieChart', type: 'discreteBarChart',
donut: true, height: 600,
donutRatio: 0.25, margin: {
height: 300, "top": 20,
"right": 20,
"bottom": 200,
"left": 55
},
x: function(d) { return d.account; }, x: function(d) { return d.account; },
y: function(d) { return d.amount; }, y: function(d) { return d.amount; },
showLabels: false, valueFormat: function(d) { return `${d}`; },
showLegend: true, showYAxis: false,
legendPosition: 'right', showValues: true,
rotateLabels: -67,
showTooltipPercent: true, showTooltipPercent: true,
duration: 500, duration: 500,
labelThreshold: 0.01, labelThreshold: 0.01,
@ -146,10 +151,9 @@ app.component('dashboard',
ctrl.depth = 99; ctrl.depth = 99;
let retrieve_period_detailed_data = function() { let retrieve_period_detailed_data = function() {
console.log(ctrl.period)
ctrl.balance = { ctrl.balance = {
buckets: [new Bucket('Expenses Liabilities Equity Income', ctrl.period), buckets: [new Bucket('Expenses Liabilities Equity Income', ctrl.period)],// ,
new Bucket('Assets', null)], // new Bucket('Assets', null)],
details: {} details: {}
}; };
@ -162,7 +166,6 @@ app.component('dashboard',
.then(function(response) { .then(function(response) {
bucket.raw_data = _.chain(response.data) bucket.raw_data = _.chain(response.data)
.map(function(account) { .map(function(account) {
account.amount = (account.amount < 0) ? account.amount * -1 : account.amount;
account.score = score_account(account.account); account.score = score_account(account.account);
return account; return account;
}) })
@ -233,7 +236,7 @@ app.component('dashboard',
stacked: false, stacked: false,
duration: 500, duration: 500,
reduceXTicks: false, reduceXTicks: false,
rotateLabels: 67, rotateLabels: -67,
labelSunbeamLayout: true, labelSunbeamLayout: true,
useInteractiveGuideline: false, useInteractiveGuideline: false,
multibar: { multibar: {
@ -292,14 +295,14 @@ app.component('dashboard',
], ],
template: ` template: `
<md-content flex="100" layout="column"> <md-content flex="100" layout="column">
<md-card flex="100" layout="row"> <md-card flex="100" layout="row">
<md-card flex="20"> <md-card flex="20">
<select style="height: 100%;" multiple ng:model="$ctrl.graphed_accounts"> <select style="height: 100%;" multiple ng:model="$ctrl.graphed_accounts">
<option ng:repeat="account in $ctrl.accounts">{{account}}</option> <option ng:repeat="account in $ctrl.accounts">{{account}}</option>
</select> </select>
</md-card> </md-card>
<md-card flex="81"> <md-card flex="81">
<nvd3 data="$ctrl.graphiques.monthly_values.data" <nvd3 data="$ctrl.graphiques.monthly_values.data"
options="$ctrl.graphiques.monthly_values.options"></nvd3> options="$ctrl.graphiques.monthly_values.options"></nvd3>
</md-card> </md-card>
</md-card> </md-card>
@ -310,6 +313,7 @@ app.component('dashboard',
<span ng:repeat="account in bucket.total_detailed">{{account.account}} = {{account.amount | number:2}} </span> <span ng:repeat="account in bucket.total_detailed">{{account.account}} = {{account.amount | number:2}} </span>
</md-toolbar> </md-toolbar>
<md-content layout="row"> <md-content layout="row">
<!--
<md-card flex="20"> <md-card flex="20">
<select style="height: 100%;" multiple <select style="height: 100%;" multiple
ng:model="bucket.accounts_selected" ng:model="bucket.accounts_selected"
@ -318,12 +322,14 @@ app.component('dashboard',
<option value=''>...</option> <option value=''>...</option>
</select> </select>
</md-card> </md-card>
-->
<md-card flex="78"> <md-card flex="78">
<nvd3 data="bucket.data" <nvd3 data="bucket.data"
options="bucket.pie_graph_options" > options="bucket.graph_options" >
</nvd3> </nvd3>
</md-card> </md-card>
<!-- <md-card flex="56"> <!--
<md-card flex="56">
<table class="table"> <table class="table">
<thead> <thead>
<tr> <tr>
@ -348,9 +354,10 @@ app.component('dashboard',
</tr> </tr>
</tbody> </tbody>
</table> </table>
</md-card> --> </md-card>
-->
</md-content> </md-content>
</md-card> </md-card>
</md-content> </md-content>
` `
}); });