diff --git a/public/app/js/app.js b/public/app/js/app.js index 1771ee3b..725c8088 100644 --- a/public/app/js/app.js +++ b/public/app/js/app.js @@ -94,16 +94,16 @@ app.component('dashboard', { }; ctrl.filter_data = function () { _(ctrl.balance.buckets).each(function (bucket) { - bucket.data = []; + bucket.data = [{ key: 'accounts', values: [] }]; if (_(bucket.accounts_selected).isEmpty() && bucket.score_threshold === 0) { - bucket.data = bucket.raw_data; + bucket.data[0].values = bucket.raw_data; } else { _(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) { return account.account.split(':')[0]; }) @@ -139,17 +139,22 @@ app.component('dashboard', { _this.orderBy = field; } }; - this.pie_graph_options = { + this.graph_options = { chart: { - type: 'pieChart', - donut: true, - donutRatio: 0.25, - height: 300, + type: 'discreteBarChart', + height: 600, + margin: { + "top": 20, + "right": 20, + "bottom": 200, + "left": 55 + }, x: function (d) { return d.account; }, y: function (d) { return d.amount; }, - showLabels: false, - showLegend: true, - legendPosition: 'right', + valueFormat: function (d) { return d + " \u20AC"; }, + showYAxis: false, + showValues: true, + rotateLabels: -67, showTooltipPercent: true, duration: 500, labelThreshold: 0.01, @@ -160,10 +165,8 @@ app.component('dashboard', { }; ctrl.depth = 99; var retrieve_period_detailed_data = function () { - console.log(ctrl.period); ctrl.balance = { - buckets: [new Bucket('Expenses Liabilities Equity Income', ctrl.period), - new Bucket('Assets', null)], + buckets: [new Bucket('Expenses Liabilities Equity Income', ctrl.period)], details: {} }; return $q.all(_(ctrl.balance.buckets).map(function (bucket) { @@ -175,7 +178,6 @@ app.component('dashboard', { .then(function (response) { bucket.raw_data = _.chain(response.data) .map(function (account) { - account.amount = (account.amount < 0) ? account.amount * -1 : account.amount; account.score = score_account(account.account); return account; }) @@ -241,7 +243,7 @@ app.component('dashboard', { stacked: false, duration: 500, reduceXTicks: false, - rotateLabels: 67, + rotateLabels: -67, labelSunbeamLayout: true, useInteractiveGuideline: false, multibar: { @@ -293,7 +295,7 @@ app.component('dashboard', { }); } ], - template: "\n\n \n \n \n \n \n \n \n \n

{{$ctrl.period | amDateFormat:'MMMM YYYY'}}

\n \n \n {{account.account}} = {{account.amount | number:2}} \u20AC\n \n \n \n \n \n \n \n \n \n \n \n \n
\n" + template: "\n\n\n\n\n\n\n\n \n \n

{{$ctrl.period | amDateFormat:'MMMM YYYY'}}

\n \n \n {{account.account}} = {{account.amount | number:2}} \u20AC\n \n \n \n \n \n \n \n \n \n \n
\n" }); app.service('API', ['$http', function ($http) { diff --git a/public/app/js/app.min.js b/public/app/js/app.min.js index 19dbff00..d4ec67e8 100644 --- a/public/app/js/app.min.js +++ b/public/app/js/app.min.js @@ -2,16 +2,17 @@ var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.ASSUME_ES5=!1;$jscomp.ASSUME_NO $jscomp.initSymbol=function(){$jscomp.initSymbol=function(){};$jscomp.global.Symbol||($jscomp.global.Symbol=$jscomp.Symbol)};$jscomp.Symbol=function(){var a=0;return function(c){return $jscomp.SYMBOL_PREFIX+(c||"")+a++}}(); $jscomp.initSymbolIterator=function(){$jscomp.initSymbol();var a=$jscomp.global.Symbol.iterator;a||(a=$jscomp.global.Symbol.iterator=$jscomp.global.Symbol("iterator"));"function"!=typeof Array.prototype[a]&&$jscomp.defineProperty(Array.prototype,a,{configurable:!0,writable:!0,value:function(){return $jscomp.arrayIterator(this)}});$jscomp.initSymbolIterator=function(){}};$jscomp.arrayIterator=function(a){var c=0;return $jscomp.iteratorPrototype(function(){return c=a?(b=-1*a-100,f=["#f0f"]):-10>=a&&(b=-1*a-10,f=["#360"]);return f[b]};b.color=function(){return function(a,c){return b.coloring_score(e(a.data.account))}};b.filter_data=function(){_(b.balance.buckets).each(function(b){b.data=[];_(b.accounts_selected).isEmpty()&&0===b.score_threshold?b.data=b.raw_data:_(b.accounts_selected).each(function(c){b.data=b.data.concat(a("filter")(b.raw_data, -c,!0))});b.total_detailed=_.chain(b.data).groupBy(function(a){return a.account.split(":")[0]}).each(function(a){a.total=_(a).reduce(function(a,b){return a+b.amount},0)}).value();b.total_detailed=_.chain(b.total_detailed).keys().map(function(a){return{account:a,amount:b.total_detailed[a].total}}).value()})};var g=function(a,b){var c=this;this.categories=a;this.period=b;this.score_threshold=0;this.orderBy="amount";this.orderDesc=!1;this.order_by=function(a){c.orderBy==a?c.orderDesc=!c.orderDesc:c.orderBy= -a};this.pie_graph_options={chart:{type:"pieChart",donut:!0,donutRatio:.25,height:300,x:function(a){return a.account},y:function(a){return a.amount},showLabels:!1,showLegend:!0,legendPosition:"right",showTooltipPercent:!0,duration:500,labelThreshold:.01,labelSunbeamLayout:!0,labelsOutside:!0}}};b.depth=99;var h=function(){console.log(b.period);b.balance={buckets:[new g("Expenses Liabilities Equity Income",b.period),new g("Assets",null)],details:{}};return c.all(_(b.balance.buckets).map(function(a){return d.balance({period:a.period, -categories:a.categories,depth:b.depth}).then(function(c){a.raw_data=_.chain(c.data).map(function(a){a.amount=0>a.amount?-1*a.amount:a.amount;a.score=e(a.account);return a}).sortBy(function(a){return 1/a.amount}).sortBy(function(a){return a.account.split(":")[0]}).value().reverse();a.raw_total=_(c.data).reduce(function(a,b){return a+b.amount},0);a.accounts_selected=a.raw_data;b.filter_data()})}))},k=function(a){return c.when(d.graph_values(a).then(function(a){b.periods=[];var c=_(a.data).reduce(function(a, -b){return b.length>a.length?b:a},[]);_.chain(c).pluck("date").each(function(b){_(a.data).each(function(a){var c=_(a).find({date:b});_(c).isUndefined()&&a.push({date:b,amount:0,currency:_(a).first().currency})})});_(a.data).each(function(a){a=_(a).sortBy(function(a){return a.date})});b.graphiques={monthly_values:{options:{chart:{type:"multiBarChart",height:300,showControls:!1,showLegend:!0,showLabels:!0,stacked:!1,duration:500,reduceXTicks:!1,rotateLabels:67,labelSunbeamLayout:!0,useInteractiveGuideline:!1, -multibar:{dispatch:{elementClick:function(a){b.period=a.data.x;h()}}}}},data:_.chain(a.data).keys().reverse().map(function(c){var d="Income"==c?-1:1;return{key:c,values:_.chain(a.data[c]).map(function(a){var e=new Date(a.date);e=e.getFullYear()+"-"+(9>e.getMonth()?"0":"")+(e.getMonth()+1);b.periods.push(e);return{key:c,x:e,y:parseInt(a.amount)*d}}).sortBy(function(a){return a.x}).value()}}).value()}};b.periods=_.chain(b.periods).uniq().sort().reverse().value();b.period=_(b.periods).first()}))};b.graphed_accounts= -["Expenses","Income"];(function(){return c.when(d.accounts().then(function(a){b.accounts=a.data.map(function(a){return a.join(":")})}))})().then(function(a){k({period:"",categories:b.graphed_accounts.join(" ")}).then(function(a){h()})})}],template:'\n\x3cmd-content flex\x3d"100" layout\x3d"column"\x3e\n \x3cmd-card flex\x3d"100" layout\x3d"row"\x3e\n \x3cmd-card flex\x3d"20"\x3e\n \x3cselect style\x3d"height: 100%;" multiple ng:model\x3d"$ctrl.graphed_accounts"\x3e\n \x3coption ng:repeat\x3d"account in $ctrl.accounts"\x3e{{account}}\x3c/option\x3e\n \x3c/select\x3e\n \x3c/md-card\x3e\n \x3cmd-card flex\x3d"81"\x3e\n \x3cnvd3 data\x3d"$ctrl.graphiques.monthly_values.data"\n options\x3d"$ctrl.graphiques.monthly_values.options"\x3e\x3c/nvd3\x3e\n \x3c/md-card\x3e\n \x3c/md-card\x3e\n \x3ch1 style\x3d"text-align: center;"\x3e{{$ctrl.period | amDateFormat:\'MMMM YYYY\'}}\x3c/h1\x3e\n \x3cmd-card flex\x3d"100" layout\x3d"column"\n ng:repeat\x3d"bucket in $ctrl.balance.buckets"\x3e\n \x3cmd-toolbar\x3e\n \x3cspan ng:repeat\x3d"account in bucket.total_detailed"\x3e{{account.account}} \x3d {{account.amount | number:2}} \u20ac\x3c/span\x3e\n \x3c/md-toolbar\x3e\n \x3cmd-content layout\x3d"row"\x3e\n \x3cmd-card flex\x3d"20"\x3e\n \x3cselect style\x3d"height: 100%;" multiple\n ng:model\x3d"bucket.accounts_selected"\n ng:options\x3d"account.account for account in bucket.raw_data | orderBy:\'account\'"\n ng:change\x3d"filter_data()"\x3e\n \x3coption value\x3d\'\'\x3e...\x3c/option\x3e\n \x3c/select\x3e\n \x3c/md-card\x3e\n \x3cmd-card flex\x3d"78"\x3e\n \x3cnvd3 data\x3d"bucket.data"\n options\x3d"bucket.pie_graph_options" \x3e\n \x3c/nvd3\x3e\n \x3c/md-card\x3e\n \x3c!-- \x3cmd-card flex\x3d"56"\x3e\n \x3ctable class\x3d"table"\x3e\n \x3cthead\x3e\n \x3ctr\x3e\n \x3cth\x3e\x3cmd-buton ng:click\x3d"bucket.order_by( \'account\' )"\x3eaccount\x3c/md-buton\x3e\x3c/th\x3e\n \x3cth\x3e\x3cmd-buton ng:click\x3d"bucket.order_by( \'amount\' )"\x3eamount\x3c/md-buton\x3e\x3c/th\x3e\n \x3cth\x3e\x3cmd-buton ng:click\x3d"bucket.order_by( \'score\' )"\x3escore\x3c/md-buton\x3e\x3c/th\x3e\n \x3c/tr\x3e\n \x3c/thead\x3e\n \x3ctbody\x3e\n \x3ctr ng:repeat\x3d"account in bucket.data | orderBy:bucket.orderBy:bucket.orderDesc"\n ng:class\x3d"{\'even\': $even, \'odd\': $odd}"\n style\x3d"border-left:10px solid {{coloring_score( account.score )}};border-right:10px solid {{coloring_score( account.score )}}"\x3e\n \x3ctd style\x3d"border-bottom:1px solid {{coloring_score( account.score )}}"\x3e\n {{account.account}}\n \x3c/td\x3e\n \x3ctd style\x3d"text-align:right;border-bottom:1px solid {{coloring_score( account.score )}}"\x3e\n {{account.amount | number:2}} \u20ac\n \x3c/td\x3e\n \x3ctd style\x3d"text-align:right;border-bottom:1px solid {{coloring_score( account.score )}}"\x3e\n {{account.score}}\n \x3c/td\x3e\n \x3c/tr\x3e\n \x3c/tbody\x3e\n \x3c/table\x3e\n \x3c/md-card\x3e --\x3e\n \x3c/md-content\x3e\n \x3c/md-card\x3e\n\x3c/md-content\x3e\n'}); +0:a.match(/^Assets/)?-100:0};b.coloring_score=function(a){var b=a,f="#99f #0f0 #3f0 #6f0 #9f0 #cf0 #fc0 #f90 #f60 #f30 #f00".split(" ");-100>=a?(b=-1*a-100,f=["#f0f"]):-10>=a&&(b=-1*a-10,f=["#360"]);return f[b]};b.color=function(){return function(a,c){return b.coloring_score(e(a.data.account))}};b.filter_data=function(){_(b.balance.buckets).each(function(b){b.data=[{key:"accounts",values:[]}];_(b.accounts_selected).isEmpty()&&0===b.score_threshold?b.data[0].values=b.raw_data:_(b.accounts_selected).each(function(c){b.data[0].values= +b.data[0].values.concat(a("filter")(b.raw_data,c,!0))});b.total_detailed=_.chain(b.data[0].values).groupBy(function(a){return a.account.split(":")[0]}).each(function(a){a.total=_(a).reduce(function(a,b){return a+b.amount},0)}).value();b.total_detailed=_.chain(b.total_detailed).keys().map(function(a){return{account:a,amount:b.total_detailed[a].total}}).value()})};var g=function(a,b){var c=this;this.categories=a;this.period=b;this.score_threshold=0;this.orderBy="amount";this.orderDesc=!1;this.order_by= +function(a){c.orderBy==a?c.orderDesc=!c.orderDesc:c.orderBy=a};this.graph_options={chart:{type:"discreteBarChart",height:600,margin:{top:20,right:20,bottom:200,left:55},x:function(a){return a.account},y:function(a){return a.amount},valueFormat:function(a){return a+" \u20ac"},showYAxis:!1,showValues:!0,rotateLabels:-67,showTooltipPercent:!0,duration:500,labelThreshold:.01,labelSunbeamLayout:!0,labelsOutside:!0}}};b.depth=99;var h=function(){b.balance={buckets:[new g("Expenses Liabilities Equity Income", +b.period)],details:{}};return c.all(_(b.balance.buckets).map(function(a){return d.balance({period:a.period,categories:a.categories,depth:b.depth}).then(function(c){a.raw_data=_.chain(c.data).map(function(a){a.score=e(a.account);return a}).sortBy(function(a){return 1/a.amount}).sortBy(function(a){return a.account.split(":")[0]}).value().reverse();a.raw_total=_(c.data).reduce(function(a,b){return a+b.amount},0);a.accounts_selected=a.raw_data;b.filter_data()})}))},k=function(a){return c.when(d.graph_values(a).then(function(a){b.periods= +[];var c=_(a.data).reduce(function(a,b){return b.length>a.length?b:a},[]);_.chain(c).pluck("date").each(function(b){_(a.data).each(function(a){var c=_(a).find({date:b});_(c).isUndefined()&&a.push({date:b,amount:0,currency:_(a).first().currency})})});_(a.data).each(function(a){a=_(a).sortBy(function(a){return a.date})});b.graphiques={monthly_values:{options:{chart:{type:"multiBarChart",height:300,showControls:!1,showLegend:!0,showLabels:!0,stacked:!1,duration:500,reduceXTicks:!1,rotateLabels:-67,labelSunbeamLayout:!0, +useInteractiveGuideline:!1,multibar:{dispatch:{elementClick:function(a){b.period=a.data.x;h()}}}}},data:_.chain(a.data).keys().reverse().map(function(c){var d="Income"==c?-1:1;return{key:c,values:_.chain(a.data[c]).map(function(a){var e=new Date(a.date);e=e.getFullYear()+"-"+(9>e.getMonth()?"0":"")+(e.getMonth()+1);b.periods.push(e);return{key:c,x:e,y:parseInt(a.amount)*d}}).sortBy(function(a){return a.x}).value()}}).value()}};b.periods=_.chain(b.periods).uniq().sort().reverse().value();b.period= +_(b.periods).first()}))};b.graphed_accounts=["Expenses","Income"];(function(){return c.when(d.accounts().then(function(a){b.accounts=a.data.map(function(a){return a.join(":")})}))})().then(function(a){k({period:"",categories:b.graphed_accounts.join(" ")}).then(function(a){h()})})}],template:'\n\x3cmd-content flex\x3d"100" layout\x3d"column"\x3e\n\x3cmd-card flex\x3d"100" layout\x3d"row"\x3e\n\x3cmd-card flex\x3d"20"\x3e\n\x3cselect style\x3d"height: 100%;" multiple ng:model\x3d"$ctrl.graphed_accounts"\x3e\n\x3coption ng:repeat\x3d"account in $ctrl.accounts"\x3e{{account}}\x3c/option\x3e\n\x3c/select\x3e\n\x3c/md-card\x3e\n\x3cmd-card flex\x3d"81"\x3e\n\x3cnvd3 data\x3d"$ctrl.graphiques.monthly_values.data"\n options\x3d"$ctrl.graphiques.monthly_values.options"\x3e\x3c/nvd3\x3e\n \x3c/md-card\x3e\n \x3c/md-card\x3e\n \x3ch1 style\x3d"text-align: center;"\x3e{{$ctrl.period | amDateFormat:\'MMMM YYYY\'}}\x3c/h1\x3e\n \x3cmd-card flex\x3d"100" layout\x3d"column"\n ng:repeat\x3d"bucket in $ctrl.balance.buckets"\x3e\n \x3cmd-toolbar\x3e\n \x3cspan ng:repeat\x3d"account in bucket.total_detailed"\x3e{{account.account}} \x3d {{account.amount | number:2}} \u20ac\x3c/span\x3e\n \x3c/md-toolbar\x3e\n \x3cmd-content layout\x3d"row"\x3e\n \x3c!--\n \x3cmd-card flex\x3d"20"\x3e\n \x3cselect style\x3d"height: 100%;" multiple\n ng:model\x3d"bucket.accounts_selected"\n ng:options\x3d"account.account for account in bucket.raw_data | orderBy:\'account\'"\n ng:change\x3d"filter_data()"\x3e\n \x3coption value\x3d\'\'\x3e...\x3c/option\x3e\n \x3c/select\x3e\n \x3c/md-card\x3e\n --\x3e\n \x3cmd-card flex\x3d"78"\x3e\n \x3cnvd3 data\x3d"bucket.data"\n options\x3d"bucket.graph_options" \x3e\n \x3c/nvd3\x3e\n \x3c/md-card\x3e\n \x3c!--\n \x3cmd-card flex\x3d"56"\x3e\n \x3ctable class\x3d"table"\x3e\n \x3cthead\x3e\n \x3ctr\x3e\n \x3cth\x3e\x3cmd-buton ng:click\x3d"bucket.order_by( \'account\' )"\x3eaccount\x3c/md-buton\x3e\x3c/th\x3e\n \x3cth\x3e\x3cmd-buton ng:click\x3d"bucket.order_by( \'amount\' )"\x3eamount\x3c/md-buton\x3e\x3c/th\x3e\n \x3cth\x3e\x3cmd-buton ng:click\x3d"bucket.order_by( \'score\' )"\x3escore\x3c/md-buton\x3e\x3c/th\x3e\n \x3c/tr\x3e\n \x3c/thead\x3e\n \x3ctbody\x3e\n \x3ctr ng:repeat\x3d"account in bucket.data | orderBy:bucket.orderBy:bucket.orderDesc"\n ng:class\x3d"{\'even\': $even, \'odd\': $odd}"\n style\x3d"border-left:10px solid {{coloring_score( account.score )}};border-right:10px solid {{coloring_score( account.score )}}"\x3e\n \x3ctd style\x3d"border-bottom:1px solid {{coloring_score( account.score )}}"\x3e\n {{account.account}}\n \x3c/td\x3e\n \x3ctd style\x3d"text-align:right;border-bottom:1px solid {{coloring_score( account.score )}}"\x3e\n {{account.amount | number:2}} \u20ac\n \x3c/td\x3e\n \x3ctd style\x3d"text-align:right;border-bottom:1px solid {{coloring_score( account.score )}}"\x3e\n {{account.score}}\n \x3c/td\x3e\n \x3c/tr\x3e\n \x3c/tbody\x3e\n \x3c/table\x3e\n \x3c/md-card\x3e\n --\x3e\n \x3c/md-content\x3e\n \x3c/md-card\x3e\n \x3c/md-content\x3e\n'}); app.service("API",["$http",function(a){this.balance=function(c){return a.get("/api/ledger/balance",{params:{period:c.period,categories:c.categories,depth:c.depth}})};this.register=function(c){return a.get("/api/ledger/register",{params:{period:c.period,categories:c.categories}})};this.graph_values=function(c){return a.get("/api/ledger/graph_values",{params:{period:c.period,categories:c.categories}})};this.budget=function(c){return a.get("/api/ledger/budget",{params:{period:c.period,categories:c.categories}})}; this.dates_salaries=function(){return a.get("/api/ledger/dates_salaries")};this.accounts=function(){return a.get("/api/ledger/accounts")};this.cleared=function(){return a.get("/api/ledger/cleared")}}]); diff --git a/public/app/ts/components/dashboard.ts b/public/app/ts/components/dashboard.ts index f6b60adf..2c58f982 100644 --- a/public/app/ts/components/dashboard.ts +++ b/public/app/ts/components/dashboard.ts @@ -75,17 +75,17 @@ app.component('dashboard', ctrl.filter_data = function() { _(ctrl.balance.buckets).each(function(bucket) { - bucket.data = []; + bucket.data = [{ key: 'accounts', values: [] }]; if (_(bucket.accounts_selected).isEmpty() && bucket.score_threshold === 0) { - bucket.data = bucket.raw_data; + bucket.data[0].values = bucket.raw_data; } else { _(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) { return account.account.split(':')[0]; }) @@ -123,17 +123,22 @@ app.component('dashboard', } }; - this.pie_graph_options = { + this.graph_options = { chart: { - type: 'pieChart', - donut: true, - donutRatio: 0.25, - height: 300, + type: 'discreteBarChart', + height: 600, + margin: { + "top": 20, + "right": 20, + "bottom": 200, + "left": 55 + }, x: function(d) { return d.account; }, y: function(d) { return d.amount; }, - showLabels: false, - showLegend: true, - legendPosition: 'right', + valueFormat: function(d) { return `${d} €`; }, + showYAxis: false, + showValues: true, + rotateLabels: -67, showTooltipPercent: true, duration: 500, labelThreshold: 0.01, @@ -146,10 +151,9 @@ app.component('dashboard', ctrl.depth = 99; let retrieve_period_detailed_data = function() { - console.log(ctrl.period) ctrl.balance = { - buckets: [new Bucket('Expenses Liabilities Equity Income', ctrl.period), - new Bucket('Assets', null)], + buckets: [new Bucket('Expenses Liabilities Equity Income', ctrl.period)],// , + // new Bucket('Assets', null)], details: {} }; @@ -162,7 +166,6 @@ app.component('dashboard', .then(function(response) { bucket.raw_data = _.chain(response.data) .map(function(account) { - account.amount = (account.amount < 0) ? account.amount * -1 : account.amount; account.score = score_account(account.account); return account; }) @@ -233,7 +236,7 @@ app.component('dashboard', stacked: false, duration: 500, reduceXTicks: false, - rotateLabels: 67, + rotateLabels: -67, labelSunbeamLayout: true, useInteractiveGuideline: false, multibar: { @@ -292,65 +295,69 @@ app.component('dashboard', ], template: ` - - - - - - - - -

{{$ctrl.period | amDateFormat:'MMMM YYYY'}}

- - - {{account.account}} = {{account.amount | number:2}} € - - - - - - - - - - - - -
+ + + + + + + + +

{{$ctrl.period | amDateFormat:'MMMM YYYY'}}

+ + + {{account.account}} = {{account.amount | number:2}} € + + + + + + + + + + + ` });