diff --git a/credger.cr b/credger.cr index e666bd2..48f805d 100644 --- a/credger.cr +++ b/credger.cr @@ -46,6 +46,7 @@ get "/api/ledger/graph_values" do |env| env.response.content_type = "application/json" ledger.graph_values( env.params.query["period"], + "--#{env.params.query["granularity"]}", env.params.query["categories"].split(" ") ).to_json end diff --git a/ledger.cr b/ledger.cr index 1ccea00..f88df1f 100644 --- a/ledger.cr +++ b/ledger.cr @@ -59,13 +59,14 @@ class Ledger end def graph_values( period : String = "", + granularity : String = "", categories : Array(String) = ["Expenses"] ) : Hash( String, Array( NamedTuple( date: String, amount: String, currency: String ) ) ) period = period == "" ? "" : "-p '#{period}'" result = {} of String => Array(NamedTuple(date: String, amount: String, currency: String)) categories.map do |category| result[category] = CSV - .parse( run( "-MAn --exchange '#{CURRENCY}' #{period}", "csv --no-revalued", category ) ) + .parse( run( "-MAn --exchange '#{CURRENCY}' #{period} #{granularity}", "csv --no-revalued", category ) ) .map do |row| { date: row[ 0 ], amount: row[ 5 ], diff --git a/public/ts/components/dashboard.ts b/public/ts/components/dashboard.ts index b390c9c..1be580a 100644 --- a/public/ts/components/dashboard.ts +++ b/public/ts/components/dashboard.ts @@ -3,6 +3,9 @@ app.component('dashboard', controller: ['$filter', 'API', function($filter, API) { let ctrl = this; + ctrl.granularity = "monthly"; + + let is_monthly = () => { return ctrl.granularity == "monthly"; }; ctrl.compute_selected_accounts = () => { ctrl.graphed_accounts = _.chain(ctrl.main_accounts_depths) @@ -25,7 +28,7 @@ app.component('dashboard', }; ctrl.retrieve_graph_values = (categories) => { - API.graph_values("", categories.join(" ")) + API.graph_values("", ctrl.granularity, categories.join(" ")) .then((response) => { ctrl.periods = []; @@ -75,12 +78,12 @@ app.component('dashboard', tooltip: { contentGenerator: function(e) { let format_line = (serie) => { - return ` -
- | Total | -${e.series.reduce((memo, serie) => { return memo + serie.value; }, 0)} | -
+ | Total | +${e.series.reduce((memo, serie) => { return memo + serie.value; }, 0)} | +