diff --git a/Commands/Chart.hs b/Commands/Chart.hs index e8a7f16c9..a4f757688 100644 --- a/Commands/Chart.hs +++ b/Commands/Chart.hs @@ -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 diff --git a/Options.hs b/Options.hs index 6df64d6b0..84bb01226 100644 --- a/Options.hs +++ b/Options.hs @@ -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)