From 885ec16f5829e5479403e83585d1b7c067ad9f0f Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Sat, 6 Feb 2010 16:08:51 +0000 Subject: [PATCH] chart: messing with colours --- Commands/Chart.hs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Commands/Chart.hs b/Commands/Chart.hs index 2a3f9d26b..c9862dd80 100644 --- a/Commands/Chart.hs +++ b/Commands/Chart.hs @@ -15,9 +15,13 @@ import Ledger.Ledger import Ledger.Commodity import Options +import Control.Monad (liftM3) import Graphics.Rendering.Chart import Data.Colour import Data.Colour.Names +import Data.Colour.RGBSpace +import Data.Colour.RGBSpace.HSL (hsl) +import Data.Colour.SRGB.Linear (rgb) import Data.List -- | Generate an image with the pie chart and write it to a file @@ -48,7 +52,7 @@ genPie opts _ l = defaultPieLayout { pie_background_ = solidFillStyle $ opaque $ white , pie_plot_ = pie_chart } where - pie_chart = defaultPieChart { pie_data_ = items } + pie_chart = defaultPieChart { pie_data_ = items, pie_colors_ = mkColours} items = mapMaybe (uncurry accountPieItem) $ flatten $ balances $ @@ -75,3 +79,11 @@ accountPieItem accname balance = if balance == 0 then Nothing else Just $ PieItem accname 0 balance + +-- | Generate an infinite color list suitable for charts. +mkColours :: [AlphaColour Double] +mkColours = cycle $ [opaque $ rgbToColour $ hsl h s l | (h,s,l) <- liftM3 (,,) + [100] [0.7] [0.2,0.3..0.6] ] + +rgbToColour :: (Fractional a) => RGB a -> Colour a +rgbToColour (RGB r g b) = rgb r g b