{-# LANGUAGE DeriveDataTypeable     #-}
{-# LANGUAGE FlexibleContexts       #-}
{-# LANGUAGE FlexibleInstances      #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE MultiParamTypeClasses  #-}
{-# LANGUAGE TemplateHaskell        #-}
{-# LANGUAGE TypeFamilies           #-}
-----------------------------------------------------------------------------
-- |
-- Module      :  Plots.Axis.Grid
-- Copyright   :  (C) 2015 Christopher Chalmers
-- License     :  BSD-style (see the file LICENSE)
-- Maintainer  :  Christopher Chalmers
-- Stability   :  experimental
-- Portability :  non-portable
--
-- Lines that go along the axis. Supports major and minor grid lines
-- separately for each axis.
--
----------------------------------------------------------------------------
module Plots.Axis.Grid
  ( -- * Grid lines
    GridLines
  , HasGridLines (..)

  , MajorGridLines
  , HasMajorGridLines (..)
  , MinorGridLines
  , HasMinorGridLines (..)

    -- * Extra traversals
  , gridLinesStyle
  , gridLinesVisible

  , hideGridLines
  , showGridLines

    -- * Grid line functions
  , GridLineFunction
  , onTicksGridLineFunction
  , emptyGridLineFunction

  ) where

import           Control.Lens        hiding (( # ))
import           Data.Data
import           Data.Default
import           Control.Monad.State

import           Diagrams.Prelude
import           Plots.Types

-- | A grid line function takes the positions of the respective ticks
--   (minor ticks for minor grid lines, major ticks for major grid
--   lines) and the bounds of the axis and returns the positions of the
--   grid lines.
--
--   These functions are used in conjuction with 'majorGridLineFunction'
--   and 'minorGridLineFunction' to control how the lines are drawn.
type GridLineFunction n = [n] -> (n, n) -> [n]

------------------------------------------------------------------------
-- Major grid lines
------------------------------------------------------------------------

data MajorGridLines v n = MajorGridLines
  { forall (v :: * -> *) n. MajorGridLines v n -> GridLineFunction n
magFun     :: GridLineFunction n
  , forall (v :: * -> *) n. MajorGridLines v n -> Style v n
magStyle   :: Style v n
  , forall (v :: * -> *) n. MajorGridLines v n -> Bool
magVisible :: Bool
  } deriving Typeable

type instance V (MajorGridLines v n) = v
type instance N (MajorGridLines v n) = n

class HasMajorGridLines f a where
  -- | The options for how to draw the grid lines. This can be used on
  --   various levels of the axis:
  --
  -- @
  -- 'majorGridLines' :: 'Traversal'' ('Axis' b c n)       ('GridLines' ('BaseSpace' c) n)
  -- 'majorGridLines' :: 'Lens''      ('SingleAxis' b v n) ('GridLines' v n)
  -- 'majorGridLines' :: 'Lens''      ('GridLines' v n)    ('GridLines' v n)
  -- @
  majorGridLines :: LensLike' f a (MajorGridLines (V a) (N a))

  -- | The function to calculate location of the major grid lines given
  --   location of the major ticks and bounds.
  majorGridLinesFunction :: Functor f => LensLike' f a (GridLineFunction (N a))
  majorGridLinesFunction = LensLike' f a (MajorGridLines (V a) (N a))
forall (f :: * -> *) a.
HasMajorGridLines f a =>
LensLike' f a (MajorGridLines (V a) (N a))
majorGridLines LensLike' f a (MajorGridLines (V a) (N a))
-> ((GridLineFunction (N a) -> f (GridLineFunction (N a)))
    -> MajorGridLines (V a) (N a) -> f (MajorGridLines (V a) (N a)))
-> LensLike' f a (GridLineFunction (N a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (MajorGridLines (V a) (N a) -> GridLineFunction (N a))
-> (MajorGridLines (V a) (N a)
    -> GridLineFunction (N a) -> MajorGridLines (V a) (N a))
-> Lens
     (MajorGridLines (V a) (N a))
     (MajorGridLines (V a) (N a))
     (GridLineFunction (N a))
     (GridLineFunction (N a))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens MajorGridLines (V a) (N a) -> GridLineFunction (N a)
forall (v :: * -> *) n. MajorGridLines v n -> GridLineFunction n
magFun (\MajorGridLines (V a) (N a)
gl GridLineFunction (N a)
maf -> MajorGridLines (V a) (N a)
gl {magFun = maf})

  -- | The style applied to the major grid lines.
  majorGridLinesStyle :: Functor f => LensLike' f a (Style (V a) (N a))
  majorGridLinesStyle = LensLike' f a (MajorGridLines (V a) (N a))
forall (f :: * -> *) a.
HasMajorGridLines f a =>
LensLike' f a (MajorGridLines (V a) (N a))
majorGridLines LensLike' f a (MajorGridLines (V a) (N a))
-> ((Style (V a) (N a) -> f (Style (V a) (N a)))
    -> MajorGridLines (V a) (N a) -> f (MajorGridLines (V a) (N a)))
-> LensLike' f a (Style (V a) (N a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (MajorGridLines (V a) (N a) -> Style (V a) (N a))
-> (MajorGridLines (V a) (N a)
    -> Style (V a) (N a) -> MajorGridLines (V a) (N a))
-> Lens
     (MajorGridLines (V a) (N a))
     (MajorGridLines (V a) (N a))
     (Style (V a) (N a))
     (Style (V a) (N a))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens MajorGridLines (V a) (N a) -> Style (V a) (N a)
forall (v :: * -> *) n. MajorGridLines v n -> Style v n
magStyle (\MajorGridLines (V a) (N a)
gl Style (V a) (N a)
sty -> MajorGridLines (V a) (N a)
gl {magStyle = sty})

instance HasMajorGridLines f (MajorGridLines v n) where
  majorGridLines :: LensLike'
  f
  (MajorGridLines v n)
  (MajorGridLines (V (MajorGridLines v n)) (N (MajorGridLines v n)))
majorGridLines = (MajorGridLines v n -> f (MajorGridLines v n))
-> MajorGridLines v n -> f (MajorGridLines v n)
LensLike'
  f
  (MajorGridLines v n)
  (MajorGridLines (V (MajorGridLines v n)) (N (MajorGridLines v n)))
forall a. a -> a
id

instance (Typeable n, Floating n) => Default (MajorGridLines v n) where
  def :: MajorGridLines v n
def = MajorGridLines
    { magFun :: GridLineFunction n
magFun     = GridLineFunction n
forall n. GridLineFunction n
onTicksGridLineFunction
    , magStyle :: Style v n
magStyle   = Style v n
forall a. Monoid a => a
mempty Style v n -> (Style v n -> Style v n) -> Style v n
forall a b. a -> (a -> b) -> b
# n -> Style v n -> Style v n
forall a n. (N a ~ n, HasStyle a, Typeable n) => n -> a -> a
lwO n
0.8
    , magVisible :: Bool
magVisible = Bool
True
    }

instance HasVisibility (MajorGridLines v n) where
  visible :: Lens' (MajorGridLines v n) Bool
visible = (MajorGridLines v n -> Bool)
-> (MajorGridLines v n -> Bool -> MajorGridLines v n)
-> Lens' (MajorGridLines v n) Bool
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens MajorGridLines v n -> Bool
forall (v :: * -> *) n. MajorGridLines v n -> Bool
magVisible (\MajorGridLines v n
gl Bool
b -> MajorGridLines v n
gl {magVisible = b})

instance Typeable n => HasStyle (MajorGridLines v n) where
  applyStyle :: Style (V (MajorGridLines v n)) (N (MajorGridLines v n))
-> MajorGridLines v n -> MajorGridLines v n
applyStyle Style (V (MajorGridLines v n)) (N (MajorGridLines v n))
s = (Style v n -> Identity (Style v n))
-> MajorGridLines v n -> Identity (MajorGridLines v n)
LensLike'
  Identity
  (MajorGridLines v n)
  (Style (V (MajorGridLines v n)) (N (MajorGridLines v n)))
forall (f :: * -> *) a.
(HasMajorGridLines f a, Functor f) =>
LensLike' f a (Style (V a) (N a))
majorGridLinesStyle ((Style v n -> Identity (Style v n))
 -> MajorGridLines v n -> Identity (MajorGridLines v n))
-> (Style v n -> Style v n)
-> MajorGridLines v n
-> MajorGridLines v n
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ Style (V (Style v n)) (N (Style v n)) -> Style v n -> Style v n
forall a. HasStyle a => Style (V a) (N a) -> a -> a
applyStyle Style (V (Style v n)) (N (Style v n))
Style (V (MajorGridLines v n)) (N (MajorGridLines v n))
s

------------------------------------------------------------------------
-- Minor grid lines
------------------------------------------------------------------------

data MinorGridLines v n = MinorGridLines
  { forall (v :: * -> *) n. MinorGridLines v n -> GridLineFunction n
migFun     :: GridLineFunction n
  , forall (v :: * -> *) n. MinorGridLines v n -> Style v n
migStyle   :: Style v n
  , forall (v :: * -> *) n. MinorGridLines v n -> Bool
migVisible :: Bool
  } deriving Typeable

type instance V (MinorGridLines v n) = v
type instance N (MinorGridLines v n) = n

class HasMinorGridLines f a where
  -- | The options for how to draw the grid lines. This can be used on
  --   various levels of the axis:
  --
  -- @
  -- 'minorGridLines' :: 'Traversal'' ('Axis' b c n)       ('GridLines' ('BaseSpace' c) n)
  -- 'minorGridLines' :: 'Lens''      ('SingleAxis' b v n) ('GridLines' v n)
  -- 'minorGridLines' :: 'Lens''      ('GridLines' v n)    ('GridLines' v n)
  -- @
  minorGridLines :: LensLike' f a (MinorGridLines (V a) (N a))

  -- | The function to calculate location of the minor grid lines given
  --   location of the minor ticks and bounds.
  minorGridLinesFunction :: Functor f => LensLike' f a (GridLineFunction (N a))
  minorGridLinesFunction = LensLike' f a (MinorGridLines (V a) (N a))
forall (f :: * -> *) a.
HasMinorGridLines f a =>
LensLike' f a (MinorGridLines (V a) (N a))
minorGridLines LensLike' f a (MinorGridLines (V a) (N a))
-> ((GridLineFunction (N a) -> f (GridLineFunction (N a)))
    -> MinorGridLines (V a) (N a) -> f (MinorGridLines (V a) (N a)))
-> LensLike' f a (GridLineFunction (N a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (MinorGridLines (V a) (N a) -> GridLineFunction (N a))
-> (MinorGridLines (V a) (N a)
    -> GridLineFunction (N a) -> MinorGridLines (V a) (N a))
-> Lens
     (MinorGridLines (V a) (N a))
     (MinorGridLines (V a) (N a))
     (GridLineFunction (N a))
     (GridLineFunction (N a))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens MinorGridLines (V a) (N a) -> GridLineFunction (N a)
forall (v :: * -> *) n. MinorGridLines v n -> GridLineFunction n
migFun (\MinorGridLines (V a) (N a)
gl GridLineFunction (N a)
mif -> MinorGridLines (V a) (N a)
gl {migFun = mif})


  -- | The style applied to the minor grid lines.
  minorGridLinesStyle :: Functor f => LensLike' f a (Style (V a) (N a))
  minorGridLinesStyle = LensLike' f a (MinorGridLines (V a) (N a))
forall (f :: * -> *) a.
HasMinorGridLines f a =>
LensLike' f a (MinorGridLines (V a) (N a))
minorGridLines LensLike' f a (MinorGridLines (V a) (N a))
-> ((Style (V a) (N a) -> f (Style (V a) (N a)))
    -> MinorGridLines (V a) (N a) -> f (MinorGridLines (V a) (N a)))
-> LensLike' f a (Style (V a) (N a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (MinorGridLines (V a) (N a) -> Style (V a) (N a))
-> (MinorGridLines (V a) (N a)
    -> Style (V a) (N a) -> MinorGridLines (V a) (N a))
-> Lens
     (MinorGridLines (V a) (N a))
     (MinorGridLines (V a) (N a))
     (Style (V a) (N a))
     (Style (V a) (N a))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens MinorGridLines (V a) (N a) -> Style (V a) (N a)
forall (v :: * -> *) n. MinorGridLines v n -> Style v n
migStyle (\MinorGridLines (V a) (N a)
gl Style (V a) (N a)
sty -> MinorGridLines (V a) (N a)
gl {migStyle = sty})

instance HasMinorGridLines f (MinorGridLines v n) where
  minorGridLines :: LensLike'
  f
  (MinorGridLines v n)
  (MinorGridLines (V (MinorGridLines v n)) (N (MinorGridLines v n)))
minorGridLines = (MinorGridLines v n -> f (MinorGridLines v n))
-> MinorGridLines v n -> f (MinorGridLines v n)
LensLike'
  f
  (MinorGridLines v n)
  (MinorGridLines (V (MinorGridLines v n)) (N (MinorGridLines v n)))
forall a. a -> a
id

instance (Typeable n, Floating n) => Default (MinorGridLines v n) where
  def :: MinorGridLines v n
def = MinorGridLines
    { migFun :: GridLineFunction n
migFun     = GridLineFunction n
forall n. GridLineFunction n
onTicksGridLineFunction
    , migStyle :: Style v n
migStyle   = Style v n
forall a. Monoid a => a
mempty Style v n -> (Style v n -> Style v n) -> Style v n
forall a b. a -> (a -> b) -> b
# n -> Style v n -> Style v n
forall a n. (N a ~ n, HasStyle a, Typeable n) => n -> a -> a
lwO n
0.5
    , migVisible :: Bool
migVisible = Bool
False
    }

-- | Hidden by default.
instance HasVisibility (MinorGridLines v n) where
  visible :: Lens' (MinorGridLines v n) Bool
visible = (MinorGridLines v n -> Bool)
-> (MinorGridLines v n -> Bool -> MinorGridLines v n)
-> Lens' (MinorGridLines v n) Bool
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens MinorGridLines v n -> Bool
forall (v :: * -> *) n. MinorGridLines v n -> Bool
migVisible (\MinorGridLines v n
gl Bool
b -> MinorGridLines v n
gl {migVisible = b})

instance Typeable n => HasStyle (MinorGridLines v n) where
  applyStyle :: Style (V (MinorGridLines v n)) (N (MinorGridLines v n))
-> MinorGridLines v n -> MinorGridLines v n
applyStyle Style (V (MinorGridLines v n)) (N (MinorGridLines v n))
s = (Style v n -> Identity (Style v n))
-> MinorGridLines v n -> Identity (MinorGridLines v n)
LensLike'
  Identity
  (MinorGridLines v n)
  (Style (V (MinorGridLines v n)) (N (MinorGridLines v n)))
forall (f :: * -> *) a.
(HasMinorGridLines f a, Functor f) =>
LensLike' f a (Style (V a) (N a))
minorGridLinesStyle ((Style v n -> Identity (Style v n))
 -> MinorGridLines v n -> Identity (MinorGridLines v n))
-> (Style v n -> Style v n)
-> MinorGridLines v n
-> MinorGridLines v n
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ Style (V (Style v n)) (N (Style v n)) -> Style v n -> Style v n
forall a. HasStyle a => Style (V a) (N a) -> a -> a
applyStyle Style (V (Style v n)) (N (Style v n))
Style (V (MinorGridLines v n)) (N (MinorGridLines v n))
s

------------------------------------------------------------------------
-- Grid lines helpers
------------------------------------------------------------------------

-- | Place grid lines at the same position as the respective ticks. This
--   is the 'Default'.
onTicksGridLineFunction :: GridLineFunction n
onTicksGridLineFunction :: forall n. GridLineFunction n
onTicksGridLineFunction = [n] -> (n, n) -> [n]
forall a b. a -> b -> a
const

-- | The 'GridLineFunction' such that no grid lines appear.
--
--   See 'hideGridLines', 'majorGridLineVisible' or
--   'minorGridLineVisible' if you just want to hide the grid lines.
emptyGridLineFunction :: GridLineFunction n
emptyGridLineFunction :: forall n. GridLineFunction n
emptyGridLineFunction [n]
_ (n, n)
_ = []

-- | Traversal over both the major and minor grid styles.
--
-- @
-- 'gridLinesVisible' :: 'Traversal'' ('Axis' b c n) 'Bool'
-- 'gridLinesVisible' :: 'Traversal'' ('SingleAxis' b v n) 'Bool'
-- 'gridLinesVisible' :: 'Traversal'' ('GridLines' v n) 'Bool'
-- @
gridLinesVisible :: (HasGridLines f a, Applicative f) => LensLike' f a Bool
gridLinesVisible :: forall (f :: * -> *) a.
(HasGridLines f a, Applicative f) =>
LensLike' f a Bool
gridLinesVisible = LensLike' f a (GridLines (V a) (N a))
forall (f :: * -> *) a.
HasGridLines f a =>
LensLike' f a (GridLines (V a) (N a))
gridLines LensLike' f a (GridLines (V a) (N a))
-> ((Bool -> f Bool)
    -> GridLines (V a) (N a) -> f (GridLines (V a) (N a)))
-> (Bool -> f Bool)
-> a
-> f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> f Bool)
-> GridLines (V a) (N a) -> f (GridLines (V a) (N a))
forall (v :: * -> *) n (f :: * -> *).
Applicative f =>
(Bool -> f Bool) -> GridLines v n -> f (GridLines v n)
vis where
  vis :: Traversal' (GridLines v n) Bool
  vis :: forall (v :: * -> *) n (f :: * -> *).
Applicative f =>
(Bool -> f Bool) -> GridLines v n -> f (GridLines v n)
vis Bool -> f Bool
f GridLines v n
a =
       (\Bool
m Bool
mn -> GridLines v n
a GridLines v n -> (GridLines v n -> GridLines v n) -> GridLines v n
forall a b. a -> (a -> b) -> b
& (MajorGridLines v n -> Identity (MajorGridLines v n))
-> GridLines v n -> Identity (GridLines v n)
LensLike'
  Identity
  (GridLines v n)
  (MajorGridLines (V (GridLines v n)) (N (GridLines v n)))
forall (f :: * -> *) a.
HasMajorGridLines f a =>
LensLike' f a (MajorGridLines (V a) (N a))
majorGridLines ((MajorGridLines v n -> Identity (MajorGridLines v n))
 -> GridLines v n -> Identity (GridLines v n))
-> ((Bool -> Identity Bool)
    -> MajorGridLines v n -> Identity (MajorGridLines v n))
-> (Bool -> Identity Bool)
-> GridLines v n
-> Identity (GridLines v n)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> Identity Bool)
-> MajorGridLines v n -> Identity (MajorGridLines v n)
forall a. HasVisibility a => Lens' a Bool
Lens' (MajorGridLines v n) Bool
visible ((Bool -> Identity Bool)
 -> GridLines v n -> Identity (GridLines v n))
-> Bool -> GridLines v n -> GridLines v n
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Bool
m GridLines v n -> (GridLines v n -> GridLines v n) -> GridLines v n
forall a b. a -> (a -> b) -> b
& (MinorGridLines v n -> Identity (MinorGridLines v n))
-> GridLines v n -> Identity (GridLines v n)
LensLike'
  Identity
  (GridLines v n)
  (MinorGridLines (V (GridLines v n)) (N (GridLines v n)))
forall (f :: * -> *) a.
HasMinorGridLines f a =>
LensLike' f a (MinorGridLines (V a) (N a))
minorGridLines ((MinorGridLines v n -> Identity (MinorGridLines v n))
 -> GridLines v n -> Identity (GridLines v n))
-> ((Bool -> Identity Bool)
    -> MinorGridLines v n -> Identity (MinorGridLines v n))
-> (Bool -> Identity Bool)
-> GridLines v n
-> Identity (GridLines v n)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> Identity Bool)
-> MinorGridLines v n -> Identity (MinorGridLines v n)
forall a. HasVisibility a => Lens' a Bool
Lens' (MinorGridLines v n) Bool
visible ((Bool -> Identity Bool)
 -> GridLines v n -> Identity (GridLines v n))
-> Bool -> GridLines v n -> GridLines v n
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Bool
mn)
         (Bool -> Bool -> GridLines v n)
-> f Bool -> f (Bool -> GridLines v n)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Bool -> f Bool
f (GridLines v n
a GridLines v n -> Getting Bool (GridLines v n) Bool -> Bool
forall s a. s -> Getting a s a -> a
^. (MajorGridLines v n -> Const Bool (MajorGridLines v n))
-> GridLines v n -> Const Bool (GridLines v n)
LensLike'
  (Const Bool)
  (GridLines v n)
  (MajorGridLines (V (GridLines v n)) (N (GridLines v n)))
forall (f :: * -> *) a.
HasMajorGridLines f a =>
LensLike' f a (MajorGridLines (V a) (N a))
majorGridLines ((MajorGridLines v n -> Const Bool (MajorGridLines v n))
 -> GridLines v n -> Const Bool (GridLines v n))
-> ((Bool -> Const Bool Bool)
    -> MajorGridLines v n -> Const Bool (MajorGridLines v n))
-> Getting Bool (GridLines v n) Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> Const Bool Bool)
-> MajorGridLines v n -> Const Bool (MajorGridLines v n)
forall a. HasVisibility a => Lens' a Bool
Lens' (MajorGridLines v n) Bool
visible) f (Bool -> GridLines v n) -> f Bool -> f (GridLines v n)
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Bool -> f Bool
f (GridLines v n
a GridLines v n -> Getting Bool (GridLines v n) Bool -> Bool
forall s a. s -> Getting a s a -> a
^. (MinorGridLines v n -> Const Bool (MinorGridLines v n))
-> GridLines v n -> Const Bool (GridLines v n)
LensLike'
  (Const Bool)
  (GridLines v n)
  (MinorGridLines (V (GridLines v n)) (N (GridLines v n)))
forall (f :: * -> *) a.
HasMinorGridLines f a =>
LensLike' f a (MinorGridLines (V a) (N a))
minorGridLines ((MinorGridLines v n -> Const Bool (MinorGridLines v n))
 -> GridLines v n -> Const Bool (GridLines v n))
-> ((Bool -> Const Bool Bool)
    -> MinorGridLines v n -> Const Bool (MinorGridLines v n))
-> Getting Bool (GridLines v n) Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> Const Bool Bool)
-> MinorGridLines v n -> Const Bool (MinorGridLines v n)
forall a. HasVisibility a => Lens' a Bool
Lens' (MinorGridLines v n) Bool
visible)

------------------------------------------------------------------------
-- Both grid lines
------------------------------------------------------------------------

-- | Type holding information about both major and minor grid lines.
data GridLines v n = GridLines
  { forall (v :: * -> *) n. GridLines v n -> MajorGridLines v n
majGrid     :: MajorGridLines v n
  , forall (v :: * -> *) n. GridLines v n -> MinorGridLines v n
minGrid     :: MinorGridLines v n
  } deriving Typeable

type instance V (GridLines v n) = v
type instance N (GridLines v n) = n

class (HasMinorGridLines f a, HasMajorGridLines f a) => HasGridLines f a where
  gridLines :: LensLike' f a (GridLines (V a) (N a))

instance Functor f => HasGridLines f (GridLines v n) where
  gridLines :: LensLike'
  f
  (GridLines v n)
  (GridLines (V (GridLines v n)) (N (GridLines v n)))
gridLines = (GridLines v n -> f (GridLines v n))
-> GridLines v n -> f (GridLines v n)
LensLike'
  f
  (GridLines v n)
  (GridLines (V (GridLines v n)) (N (GridLines v n)))
forall a. a -> a
id

instance (Typeable n, Floating n) => Default (GridLines v n) where
  def :: GridLines v n
def = GridLines
    { majGrid :: MajorGridLines v n
majGrid = MajorGridLines v n
forall a. Default a => a
def
    , minGrid :: MinorGridLines v n
minGrid = MinorGridLines v n
forall a. Default a => a
def
    }

instance Functor f => HasMajorGridLines f (GridLines v n) where
  majorGridLines :: LensLike'
  f
  (GridLines v n)
  (MajorGridLines (V (GridLines v n)) (N (GridLines v n)))
majorGridLines = (GridLines v n -> MajorGridLines v n)
-> (GridLines v n -> MajorGridLines v n -> GridLines v n)
-> Lens
     (GridLines v n)
     (GridLines v n)
     (MajorGridLines v n)
     (MajorGridLines v n)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens GridLines v n -> MajorGridLines v n
forall (v :: * -> *) n. GridLines v n -> MajorGridLines v n
majGrid (\GridLines v n
g MajorGridLines v n
a -> GridLines v n
g {majGrid = a})

instance Functor f => HasMinorGridLines f (GridLines v n) where
  minorGridLines :: LensLike'
  f
  (GridLines v n)
  (MinorGridLines (V (GridLines v n)) (N (GridLines v n)))
minorGridLines = (GridLines v n -> MinorGridLines v n)
-> (GridLines v n -> MinorGridLines v n -> GridLines v n)
-> Lens
     (GridLines v n)
     (GridLines v n)
     (MinorGridLines v n)
     (MinorGridLines v n)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens GridLines v n -> MinorGridLines v n
forall (v :: * -> *) n. GridLines v n -> MinorGridLines v n
minGrid (\GridLines v n
g MinorGridLines v n
a -> GridLines v n
g {minGrid = a})

instance Typeable n => HasStyle (GridLines v n) where
  applyStyle :: Style (V (GridLines v n)) (N (GridLines v n))
-> GridLines v n -> GridLines v n
applyStyle Style (V (GridLines v n)) (N (GridLines v n))
s = ((MajorGridLines v n -> Identity (MajorGridLines v n))
-> GridLines v n -> Identity (GridLines v n)
LensLike'
  Identity
  (GridLines v n)
  (MajorGridLines (V (GridLines v n)) (N (GridLines v n)))
forall (f :: * -> *) a.
HasMajorGridLines f a =>
LensLike' f a (MajorGridLines (V a) (N a))
majorGridLines ((MajorGridLines v n -> Identity (MajorGridLines v n))
 -> GridLines v n -> Identity (GridLines v n))
-> (MajorGridLines v n -> MajorGridLines v n)
-> GridLines v n
-> GridLines v n
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ Style (V (MajorGridLines v n)) (N (MajorGridLines v n))
-> MajorGridLines v n -> MajorGridLines v n
forall a. HasStyle a => Style (V a) (N a) -> a -> a
applyStyle Style (V (GridLines v n)) (N (GridLines v n))
Style (V (MajorGridLines v n)) (N (MajorGridLines v n))
s) (GridLines v n -> GridLines v n)
-> (GridLines v n -> GridLines v n)
-> GridLines v n
-> GridLines v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((MinorGridLines v n -> Identity (MinorGridLines v n))
-> GridLines v n -> Identity (GridLines v n)
LensLike'
  Identity
  (GridLines v n)
  (MinorGridLines (V (GridLines v n)) (N (GridLines v n)))
forall (f :: * -> *) a.
HasMinorGridLines f a =>
LensLike' f a (MinorGridLines (V a) (N a))
minorGridLines ((MinorGridLines v n -> Identity (MinorGridLines v n))
 -> GridLines v n -> Identity (GridLines v n))
-> (MinorGridLines v n -> MinorGridLines v n)
-> GridLines v n
-> GridLines v n
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ Style (V (MinorGridLines v n)) (N (MinorGridLines v n))
-> MinorGridLines v n -> MinorGridLines v n
forall a. HasStyle a => Style (V a) (N a) -> a -> a
applyStyle Style (V (GridLines v n)) (N (GridLines v n))
Style (V (MinorGridLines v n)) (N (MinorGridLines v n))
s)

-- | Hide both major and minor grid lines.
--
-- @
-- 'hideGridLines' :: 'Axis' b c n       -> 'Axis' b c n
-- 'hideGridLines' :: 'SingleAxis' b c n -> 'SingleAxis' b c n
-- 'hideGridLines' :: 'GridLines' b c n  -> 'GridLines' b c n
-- @
hideGridLines :: (HasGridLines Identity a, MonadState a m) => m ()
hideGridLines :: forall a (m :: * -> *).
(HasGridLines Identity a, MonadState a m) =>
m ()
hideGridLines = do
  LensLike' Identity a (MinorGridLines (V a) (N a))
forall (f :: * -> *) a.
HasMinorGridLines f a =>
LensLike' f a (MinorGridLines (V a) (N a))
minorGridLines LensLike' Identity a (MinorGridLines (V a) (N a))
-> ((Bool -> Identity Bool)
    -> MinorGridLines (V a) (N a)
    -> Identity (MinorGridLines (V a) (N a)))
-> (Bool -> Identity Bool)
-> a
-> Identity a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> Identity Bool)
-> MinorGridLines (V a) (N a)
-> Identity (MinorGridLines (V a) (N a))
forall a. HasVisibility a => Lens' a Bool
Lens' (MinorGridLines (V a) (N a)) Bool
visible ((Bool -> Identity Bool) -> a -> Identity a) -> Bool -> m ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= Bool
False
  LensLike' Identity a (MajorGridLines (V a) (N a))
forall (f :: * -> *) a.
HasMajorGridLines f a =>
LensLike' f a (MajorGridLines (V a) (N a))
majorGridLines LensLike' Identity a (MajorGridLines (V a) (N a))
-> ((Bool -> Identity Bool)
    -> MajorGridLines (V a) (N a)
    -> Identity (MajorGridLines (V a) (N a)))
-> (Bool -> Identity Bool)
-> a
-> Identity a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> Identity Bool)
-> MajorGridLines (V a) (N a)
-> Identity (MajorGridLines (V a) (N a))
forall a. HasVisibility a => Lens' a Bool
Lens' (MajorGridLines (V a) (N a)) Bool
visible ((Bool -> Identity Bool) -> a -> Identity a) -> Bool -> m ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= Bool
False

-- | Show both major and minor grid lines.
--
-- @
-- 'showGridLines' :: 'Axis' b c n       -> 'Axis' b c n
-- 'showGridLines' :: 'SingleAxis' b c n -> 'SingleAxis' b c n
-- 'showGridLines' :: 'GridLines' b c n  -> 'GridLines' b c n
-- @
showGridLines :: (HasGridLines Identity a, MonadState a m) => m ()
showGridLines :: forall a (m :: * -> *).
(HasGridLines Identity a, MonadState a m) =>
m ()
showGridLines = do
  LensLike' Identity a (MinorGridLines (V a) (N a))
forall (f :: * -> *) a.
HasMinorGridLines f a =>
LensLike' f a (MinorGridLines (V a) (N a))
minorGridLines LensLike' Identity a (MinorGridLines (V a) (N a))
-> ((Bool -> Identity Bool)
    -> MinorGridLines (V a) (N a)
    -> Identity (MinorGridLines (V a) (N a)))
-> (Bool -> Identity Bool)
-> a
-> Identity a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> Identity Bool)
-> MinorGridLines (V a) (N a)
-> Identity (MinorGridLines (V a) (N a))
forall a. HasVisibility a => Lens' a Bool
Lens' (MinorGridLines (V a) (N a)) Bool
visible ((Bool -> Identity Bool) -> a -> Identity a) -> Bool -> m ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= Bool
True
  LensLike' Identity a (MajorGridLines (V a) (N a))
forall (f :: * -> *) a.
HasMajorGridLines f a =>
LensLike' f a (MajorGridLines (V a) (N a))
majorGridLines LensLike' Identity a (MajorGridLines (V a) (N a))
-> ((Bool -> Identity Bool)
    -> MajorGridLines (V a) (N a)
    -> Identity (MajorGridLines (V a) (N a)))
-> (Bool -> Identity Bool)
-> a
-> Identity a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> Identity Bool)
-> MajorGridLines (V a) (N a)
-> Identity (MajorGridLines (V a) (N a))
forall a. HasVisibility a => Lens' a Bool
Lens' (MajorGridLines (V a) (N a)) Bool
visible ((Bool -> Identity Bool) -> a -> Identity a) -> Bool -> m ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= Bool
True

-- | Traversal over both the major and minor grid styles. This can be used at several levels in the axis:
gridLinesStyle :: (HasGridLines f a, Applicative f) => LensLike' f a (Style (V a) (N a))
gridLinesStyle :: forall (f :: * -> *) a.
(HasGridLines f a, Applicative f) =>
LensLike' f a (Style (V a) (N a))
gridLinesStyle = LensLike' f a (GridLines (V a) (N a))
forall (f :: * -> *) a.
HasGridLines f a =>
LensLike' f a (GridLines (V a) (N a))
gridLines LensLike' f a (GridLines (V a) (N a))
-> ((Style (V a) (N a) -> f (Style (V a) (N a)))
    -> GridLines (V a) (N a) -> f (GridLines (V a) (N a)))
-> (Style (V a) (N a) -> f (Style (V a) (N a)))
-> a
-> f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Style (V a) (N a) -> f (Style (V a) (N a)))
-> GridLines (V a) (N a) -> f (GridLines (V a) (N a))
forall (v :: * -> *) n (f :: * -> *).
Applicative f =>
(Style v n -> f (Style v n)) -> GridLines v n -> f (GridLines v n)
styles where
  styles :: Traversal' (GridLines v n) (Style v n)
  styles :: forall (v :: * -> *) n (f :: * -> *).
Applicative f =>
(Style v n -> f (Style v n)) -> GridLines v n -> f (GridLines v n)
styles Style v n -> f (Style v n)
f GridLines v n
a =
    (\Style v n
m Style v n
mn -> GridLines v n
a GridLines v n -> (GridLines v n -> GridLines v n) -> GridLines v n
forall a b. a -> (a -> b) -> b
& (Style v n -> Identity (Style v n))
-> GridLines v n -> Identity (GridLines v n)
LensLike'
  Identity
  (GridLines v n)
  (Style (V (GridLines v n)) (N (GridLines v n)))
forall (f :: * -> *) a.
(HasMajorGridLines f a, Functor f) =>
LensLike' f a (Style (V a) (N a))
majorGridLinesStyle ((Style v n -> Identity (Style v n))
 -> GridLines v n -> Identity (GridLines v n))
-> Style v n -> GridLines v n -> GridLines v n
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Style v n
m GridLines v n -> (GridLines v n -> GridLines v n) -> GridLines v n
forall a b. a -> (a -> b) -> b
& (Style v n -> Identity (Style v n))
-> GridLines v n -> Identity (GridLines v n)
LensLike'
  Identity
  (GridLines v n)
  (Style (V (GridLines v n)) (N (GridLines v n)))
forall (f :: * -> *) a.
(HasMinorGridLines f a, Functor f) =>
LensLike' f a (Style (V a) (N a))
minorGridLinesStyle ((Style v n -> Identity (Style v n))
 -> GridLines v n -> Identity (GridLines v n))
-> Style v n -> GridLines v n -> GridLines v n
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Style v n
mn)
      (Style v n -> Style v n -> GridLines v n)
-> f (Style v n) -> f (Style v n -> GridLines v n)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Style v n -> f (Style v n)
f (GridLines v n
a GridLines v n
-> Getting (Style v n) (GridLines v n) (Style v n) -> Style v n
forall s a. s -> Getting a s a -> a
^. Getting (Style v n) (GridLines v n) (Style v n)
LensLike'
  (Const (Style v n))
  (GridLines v n)
  (Style (V (GridLines v n)) (N (GridLines v n)))
forall (f :: * -> *) a.
(HasMajorGridLines f a, Functor f) =>
LensLike' f a (Style (V a) (N a))
majorGridLinesStyle) f (Style v n -> GridLines v n)
-> f (Style v n) -> f (GridLines v n)
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Style v n -> f (Style v n)
f (GridLines v n
a GridLines v n
-> Getting (Style v n) (GridLines v n) (Style v n) -> Style v n
forall s a. s -> Getting a s a -> a
^. Getting (Style v n) (GridLines v n) (Style v n)
LensLike'
  (Const (Style v n))
  (GridLines v n)
  (Style (V (GridLines v n)) (N (GridLines v n)))
forall (f :: * -> *) a.
(HasMinorGridLines f a, Functor f) =>
LensLike' f a (Style (V a) (N a))
minorGridLinesStyle)