module Graphics.Rendering.Chart.Easy(
module Control.Lens,
module Data.Default.Class,
module Data.Colour,
module Data.Colour.Names,
module Graphics.Rendering.Chart,
module Graphics.Rendering.Chart.State,
line,
points,
bars,
setColors,
setShapes
) where
import Control.Lens
import Control.Monad(when)
import Data.Default.Class
import Data.Colour hiding (over)
import Data.Colour.Names
import Graphics.Rendering.Chart
import Graphics.Rendering.Chart.State
setColors :: [AlphaColour Double] -> EC l ()
setColors cs = liftCState $ colors .= cycle cs
setShapes :: [PointShape] -> EC l ()
setShapes ps = liftCState $ shapes .= cycle ps
line :: String -> [[(x,y)]] -> EC l (PlotLines x y)
line title values = liftEC $ do
color <- takeColor
plot_lines_title .= title
plot_lines_values .= values
plot_lines_style . line_color .= color
points :: String -> [(x,y)] -> EC l (PlotPoints x y)
points title values = liftEC $ do
color <- takeColor
shape <- takeShape
plot_points_values .= values
plot_points_title .= title
plot_points_style . point_color .= color
plot_points_style . point_shape .= shape
plot_points_style . point_radius .= 2
when (not (isFilled shape)) $ do
plot_points_style . point_border_color .= color
plot_points_style . point_border_width .= 1
isFilled :: PointShape -> Bool
isFilled PointShapeCircle = True
isFilled PointShapePolygon{} = True
isFilled _ = False
bars :: (PlotValue x, BarsPlotValue y) => [String] -> [(x,[y])] -> EC l (PlotBars x y)
bars titles vals = liftEC $ do
styles <- sequence [fmap mkStyle takeColor | _ <- titles]
plot_bars_titles .= titles
plot_bars_values .= vals
plot_bars_style .= BarsClustered
plot_bars_spacing .= BarsFixGap 30 5
plot_bars_item_styles .= styles
where
mkStyle c = (solidFillStyle c, Just (solidLine 1.0 $ opaque black))