chart: show top 10 (or --items N) accounts, sorted by amount

This commit is contained in:
Simon Michael 2010-02-05 01:18:51 +00:00
parent 71c6b13717
commit 160f8dc5b8
2 changed files with 8 additions and 1 deletions

View File

@ -23,6 +23,7 @@ import Data.Colour.RGBSpace
import Data.Colour.RGBSpace.HSL (hsl)
import Data.Colour.SRGB.Linear (rgb)
import Data.List
import Safe (readDef)
-- | Generate an image with the pie chart and write it to a file
chart :: [Opt] -> [String] -> Ledger -> IO ()
@ -56,9 +57,13 @@ genPie opts filterspec l = defaultPieLayout
where
pie_chart = defaultPieChart { pie_data_ = items, pie_colors_ = mkColours}
items = mapMaybe (uncurry accountPieItem) $
flatten $
top num $
balances $
ledgerAccountTree (fromMaybe 99999 $ depthFromOpts opts) $ cacheLedger'' filterspec l
top n t = topn ++ [other]
where (topn,rest) = splitAt n $ reverse $ sortBy (comparing snd) $ flatten t
other = ("other", sum $ map snd rest)
num = readDef 10 (getOption opts ChartItems "10")
-- | Convert all quantities of MixedAccount to a single commodity
amountValue :: MixedAmount -> Double

View File

@ -86,6 +86,7 @@ options = [
,Option "" ["debug-no-ui"] (NoArg DebugNoUI) "run ui commands with no output"
#ifdef CHART
,Option "o" ["output"] (ReqArg ChartOutput "FILE") "chart: output filename (default: hledger.png)"
,Option "" ["items"] (ReqArg ChartItems "N") "chart: number of accounts to show (default: 10)"
,Option "" ["size"] (ReqArg ChartSize "WIDTHxHEIGHT") "chart: image size (default: 1024x1024)"
#endif
]
@ -118,6 +119,7 @@ data Opt =
| DebugNoUI
#ifdef CHART
| ChartOutput {value::String}
| ChartItems {value::String}
| ChartSize {value::String}
#endif
deriving (Show,Eq)