chart: messing with colours
This commit is contained in:
parent
e96350c3f1
commit
885ec16f58
@ -15,9 +15,13 @@ import Ledger.Ledger
|
|||||||
import Ledger.Commodity
|
import Ledger.Commodity
|
||||||
import Options
|
import Options
|
||||||
|
|
||||||
|
import Control.Monad (liftM3)
|
||||||
import Graphics.Rendering.Chart
|
import Graphics.Rendering.Chart
|
||||||
import Data.Colour
|
import Data.Colour
|
||||||
import Data.Colour.Names
|
import Data.Colour.Names
|
||||||
|
import Data.Colour.RGBSpace
|
||||||
|
import Data.Colour.RGBSpace.HSL (hsl)
|
||||||
|
import Data.Colour.SRGB.Linear (rgb)
|
||||||
import Data.List
|
import Data.List
|
||||||
|
|
||||||
-- | Generate an image with the pie chart and write it to a file
|
-- | 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_background_ = solidFillStyle $ opaque $ white
|
||||||
, pie_plot_ = pie_chart }
|
, pie_plot_ = pie_chart }
|
||||||
where
|
where
|
||||||
pie_chart = defaultPieChart { pie_data_ = items }
|
pie_chart = defaultPieChart { pie_data_ = items, pie_colors_ = mkColours}
|
||||||
items = mapMaybe (uncurry accountPieItem) $
|
items = mapMaybe (uncurry accountPieItem) $
|
||||||
flatten $
|
flatten $
|
||||||
balances $
|
balances $
|
||||||
@ -75,3 +79,11 @@ accountPieItem accname balance =
|
|||||||
if balance == 0
|
if balance == 0
|
||||||
then Nothing
|
then Nothing
|
||||||
else Just $ PieItem accname 0 balance
|
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
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user