chart: filter based on opts & args

This commit is contained in:
Simon Michael 2010-02-04 21:11:59 +00:00
parent a2b8faa4d6
commit 71c6b13717
3 changed files with 14 additions and 10 deletions

View File

@ -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

View File

@ -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

View File

@ -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.