-- |
-- Module     : Simulation.Aivika.Experiment.Chart.Utils
-- Copyright  : Copyright (c) 2012-2017, David Sorokin <david.sorokin@gmail.com>
-- License    : BSD3
-- Maintainer : David Sorokin <david.sorokin@gmail.com>
-- Stability  : experimental
-- Tested with: GHC 8.0.1
--
-- The module defines some utilities used in the charting.
--

module Simulation.Aivika.Experiment.Chart.Utils
       (colourisePlotLines,
        colourisePlotFillBetween,
        colourisePlotBars) where

import Control.Lens

import Data.Colour
import Data.Colour.Names

import Graphics.Rendering.Chart

-- | Colourise the plot lines.
colourisePlotLines :: [PlotLines x y -> PlotLines x y]
colourisePlotLines :: forall x y. [PlotLines x y -> PlotLines x y]
colourisePlotLines = forall a b. (a -> b) -> [a] -> [b]
map forall {x} {y}.
AlphaColour Double -> PlotLines x y -> PlotLines x y
mkstyle forall a b. (a -> b) -> a -> b
$ forall a. [a] -> [a]
cycle [AlphaColour Double]
defaultColorSeq
  where mkstyle :: AlphaColour Double -> PlotLines x y -> PlotLines x y
mkstyle AlphaColour Double
c = forall x y. Lens' (PlotLines x y) LineStyle
plot_lines_style forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lens' LineStyle (AlphaColour Double)
line_color forall s t a b. ASetter s t a b -> b -> s -> t
.~ AlphaColour Double
c

-- | Colourise the filling areas.
colourisePlotFillBetween :: [PlotFillBetween x y -> PlotFillBetween x y]
colourisePlotFillBetween :: forall x y. [PlotFillBetween x y -> PlotFillBetween x y]
colourisePlotFillBetween = forall a b. (a -> b) -> [a] -> [b]
map forall {x} {y}.
AlphaColour Double -> PlotFillBetween x y -> PlotFillBetween x y
mkstyle forall a b. (a -> b) -> a -> b
$ forall a. [a] -> [a]
cycle [AlphaColour Double]
defaultColorSeq
  where mkstyle :: AlphaColour Double -> PlotFillBetween x y -> PlotFillBetween x y
mkstyle AlphaColour Double
c = forall x y. Lens' (PlotFillBetween x y) FillStyle
plot_fillbetween_style forall s t a b. ASetter s t a b -> b -> s -> t
.~ AlphaColour Double -> FillStyle
solidFillStyle (forall a. Num a => a -> AlphaColour a -> AlphaColour a
dissolve Double
0.4 AlphaColour Double
c)
  
-- | Colourise the plot bars.
colourisePlotBars :: PlotBars x y -> PlotBars x y
colourisePlotBars :: forall x y. PlotBars x y -> PlotBars x y
colourisePlotBars = forall x y. Lens' (PlotBars x y) [(FillStyle, Maybe LineStyle)]
plot_bars_item_styles forall s t a b. ASetter s t a b -> b -> s -> t
.~ forall a b. (a -> b) -> [a] -> [b]
map AlphaColour Double -> (FillStyle, Maybe LineStyle)
mkstyle (forall a. [a] -> [a]
cycle [AlphaColour Double]
defaultColorSeq)
  where mkstyle :: AlphaColour Double -> (FillStyle, Maybe LineStyle)
mkstyle AlphaColour Double
c = (AlphaColour Double -> FillStyle
solidFillStyle AlphaColour Double
c, forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ Double -> AlphaColour Double -> LineStyle
solidLine Double
1.0 forall a b. (a -> b) -> a -> b
$ forall a. Num a => Colour a -> AlphaColour a
opaque forall a. Num a => Colour a
black)