diff --git a/Commands/Balance.hs b/Commands/Balance.hs index 6a66fb439..9cc61f745 100644 --- a/Commands/Balance.hs +++ b/Commands/Balance.hs @@ -102,7 +102,6 @@ import Ledger.Types import Ledger.Amount import Ledger.AccountName import Ledger.Posting -import Ledger.Journal import Ledger.Ledger import Options import System.IO.UTF8 @@ -116,11 +115,9 @@ balance opts args l = do -- | Generate a balance report with the specified options for this ledger. showBalanceReport :: [Opt] -> FilterSpec -> Ledger -> String -showBalanceReport opts filterspec l@Ledger{journal=j} = acctsstr ++ totalstr +showBalanceReport opts filterspec l = acctsstr ++ totalstr where - l' = l{journal=j',accountnametree=ant,accountmap=amap} -- like cacheLedger - where (ant, amap) = crunchJournal j' - j' = filterJournalPostings filterspec{depth=Nothing} j + l' = cacheLedger'' filterspec l acctsstr = unlines $ map showacct interestingaccts where showacct = showInterestingAccount l' interestingaccts diff --git a/Commands/Chart.hs b/Commands/Chart.hs index d8ae38749..e8a7f16c9 100644 --- a/Commands/Chart.hs +++ b/Commands/Chart.hs @@ -26,9 +26,11 @@ import Data.List -- | Generate an image with the pie chart and write it to a file chart :: [Opt] -> [String] -> Ledger -> IO () -chart opts args l = renderableToPNGFile (toRenderable chart) w h filename +chart opts args l = do + t <- getCurrentLocalTime + let chart = genPie opts (optsToFilterSpec opts args t) l + renderableToPNGFile (toRenderable chart) w h filename where - chart = genPie opts args l filename = getOption opts ChartOutput "hledger.png" (w,h) = parseSize $ getOption opts ChartSize "1024x1024" @@ -47,8 +49,8 @@ parseSize str = (read w, read h) (w,_:h) = splitAt x str -- | Generate pie chart -genPie :: [Opt] -> [String] -> Ledger -> PieLayout -genPie opts _ l = defaultPieLayout +genPie :: [Opt] -> FilterSpec -> Ledger -> PieLayout +genPie opts filterspec l = defaultPieLayout { pie_background_ = solidFillStyle $ opaque $ white , pie_plot_ = pie_chart } where @@ -56,7 +58,7 @@ genPie opts _ l = defaultPieLayout items = mapMaybe (uncurry accountPieItem) $ flatten $ balances $ - ledgerAccountTree (fromMaybe 99999 $ depthFromOpts opts) $ cacheLedger' l + ledgerAccountTree (fromMaybe 99999 $ depthFromOpts opts) $ cacheLedger'' filterspec l -- | Convert all quantities of MixedAccount to a single commodity amountValue :: MixedAmount -> Double diff --git a/Ledger/Ledger.hs b/Ledger/Ledger.hs index a7a495ed7..1a7ef925a 100644 --- a/Ledger/Ledger.hs +++ b/Ledger/Ledger.hs @@ -89,6 +89,11 @@ cacheLedger' :: Ledger -> CachedLedger cacheLedger' l = l{accountnametree=ant,accountmap=amap} where (ant, amap) = crunchJournal $ journal l +-- | Like cacheLedger, but filtering the journal first. +cacheLedger'' filterspec l@Ledger{journal=j} = l{journal=j',accountnametree=ant,accountmap=amap} + where (ant, amap) = crunchJournal j' + j' = filterJournalPostings filterspec{depth=Nothing} j + type CachedLedger = Ledger -- | List a ledger's account names.