web: show one line per commodity in charts. Needs more polish, but fixes #109.
This commit is contained in:
parent
95f909543a
commit
2e5718d5ea
@ -34,7 +34,8 @@ module Hledger.Reports (
|
||||
TransactionsReport,
|
||||
TransactionsReportItem,
|
||||
triDate,
|
||||
triBalance,
|
||||
triSimpleBalance,
|
||||
transactionsReportByCommodity,
|
||||
journalTransactionsReport,
|
||||
accountTransactionsReport,
|
||||
-- * Accounts report
|
||||
@ -435,9 +436,39 @@ type TransactionsReportItem = (Transaction -- the corresponding transaction
|
||||
)
|
||||
|
||||
triDate (t,_,_,_,_,_) = tdate t
|
||||
triBalance (_,_,_,_,_,Mixed a) = case a of [] -> "0"
|
||||
triAmount (_,_,_,_,a,_) = a
|
||||
triSimpleBalance (_,_,_,_,_,Mixed a) = case a of [] -> "0"
|
||||
(Amount{aquantity=q}):_ -> show q
|
||||
|
||||
-- Split a transactions report whose items may involve several commodities,
|
||||
-- into one or more single-commodity transactions reports.
|
||||
transactionsReportByCommodity :: TransactionsReport -> [TransactionsReport]
|
||||
transactionsReportByCommodity tr =
|
||||
[filterTransactionsReportByCommodity c tr | c <- transactionsReportCommodities tr]
|
||||
where
|
||||
transactionsReportCommodities (_,items) =
|
||||
nub $ sort $ map acommodity $ concatMap (amounts . triAmount) items
|
||||
|
||||
-- Remove transaction report items and item amount components that
|
||||
-- don't involve the specified commodity. Other item fields like the
|
||||
-- running balance and the transaction are left unchanged.
|
||||
filterTransactionsReportByCommodity :: Commodity -> TransactionsReport -> TransactionsReport
|
||||
filterTransactionsReportByCommodity c (label,items) =
|
||||
(label, fixTransactionsReportItemBalances $ concat [filterTransactionsReportItemByCommodity c i | i <- items])
|
||||
where
|
||||
filterTransactionsReportItemByCommodity c (t,t2,s,o,Mixed as,bal)
|
||||
| c `elem` cs = [item']
|
||||
| otherwise = []
|
||||
where
|
||||
cs = map acommodity as
|
||||
item' = (t,t2,s,o,Mixed as',bal)
|
||||
as' = filter ((==c).acommodity) as
|
||||
fixTransactionsReportItemBalances is = reverse $ go nullmixedamt $ reverse is
|
||||
where
|
||||
go _ [] = []
|
||||
go bal ((t,t2,s,o,amt,_):is) = (t,t2,s,o,amt,bal'):go bal' is
|
||||
where bal' = bal + amt
|
||||
|
||||
-- | Select transactions from the whole journal for a transactions report,
|
||||
-- with no \"current\" account. The end result is similar to
|
||||
-- "postingsReport" except it uses queries and transaction-based report
|
||||
|
||||
@ -423,8 +423,8 @@ $forall p' <- tpostings t
|
||||
|
||||
-- Generate html for an account register, including a balance chart and transaction list.
|
||||
registerReportHtml :: WebOpts -> ViewData -> TransactionsReport -> HtmlUrl AppRoute
|
||||
registerReportHtml opts vd r@(_,items) = [hamlet|
|
||||
^{registerChartHtml items}
|
||||
registerReportHtml opts vd r = [hamlet|
|
||||
^{registerChartHtml $ map snd $ transactionsReportByCommodity r}
|
||||
^{registerItemsHtml opts vd r}
|
||||
|]
|
||||
|
||||
@ -486,8 +486,8 @@ $forall p' <- tpostings t
|
||||
-- Data.Foldable.Foldable t1 =>
|
||||
-- t1 (Transaction, t2, t3, t4, t5, MixedAmount)
|
||||
-- -> t -> Text.Blaze.Internal.HtmlM ()
|
||||
registerChartHtml :: [TransactionsReportItem] -> HtmlUrl AppRoute
|
||||
registerChartHtml items =
|
||||
registerChartHtml :: [[TransactionsReportItem]] -> HtmlUrl AppRoute
|
||||
registerChartHtml itemss =
|
||||
-- have to make sure plot is not called when our container (maincontent)
|
||||
-- is hidden, eg with add form toggled
|
||||
[hamlet|
|
||||
@ -499,10 +499,11 @@ registerChartHtml items =
|
||||
if (chartdiv.is(':visible'))
|
||||
\$.plot(chartdiv,
|
||||
[
|
||||
$forall items <- itemss
|
||||
[
|
||||
$forall i <- items
|
||||
[#{dayToJsTimestamp $ triDate i}, #{triBalance i}],
|
||||
]
|
||||
[#{dayToJsTimestamp $ triDate i}, #{triSimpleBalance i}],
|
||||
],
|
||||
],
|
||||
{
|
||||
xaxis: {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user