Skip to content

armgit / maybe

Public Imported from GitHub
0

The personal finance app for everyone

Invert liability graphs to have correct signage (#1928)

Zach Gollwitzer7c66f167500f
diff --git a/app/models/account/chartable.rb b/app/models/account/chartable.rb
index aba8415c..2770da3b 100644
--- a/app/models/account/chartable.rb
+++ b/app/models/account/chartable.rb
@@ -14,6 +14,7 @@ module Account::Chartable
])
balances = gapfill_balances(balances)
+ balances = invert_balances(balances) if favorable_direction == "down"
values = [ nil, *balances ].each_cons(2).map do |prev, curr|
Series::Value.new(
@@ -69,6 +70,13 @@ module Account::Chartable
SQL
end
+ def invert_balances(balances)
+ balances.map do |balance|
+ balance.balance = -balance.balance
+ balance
+ end
+ end
+
def gapfill_balances(balances)
gapfilled = []