{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
module Codec.Xlsx.Types.ConditionalFormatting
  ( ConditionalFormatting
  , CfRule(..)
  , NStdDev(..)
  , Inclusion(..)
  , CfValue(..)
  , MinCfValue(..)
  , MaxCfValue(..)
  , Condition(..)
  , OperatorExpression(..)
  , TimePeriod(..)
  , IconSetOptions(..)
  , IconSetType(..)
  , DataBarOptions(..)
  , dataBarWithColor
    -- * Lenses
    -- ** CfRule
  , cfrCondition
  , cfrDxfId
  , cfrPriority
  , cfrStopIfTrue
    -- ** IconSetOptions
  , isoIconSet
  , isoValues
  , isoReverse
  , isoShowValue
    -- ** DataBarOptions
  , dboMaxLength
  , dboMinLength
  , dboShowValue
  , dboMinimum
  , dboMaximum
  , dboColor
    -- * Misc
  , topCfPriority
  ) where

import Control.Arrow (first, right)
import Control.DeepSeq (NFData)
#ifdef USE_MICROLENS
import Lens.Micro.TH (makeLenses)
#else
import Control.Lens (makeLenses)
#endif
import Data.Bool (bool)
import Data.ByteString (ByteString)
import Data.Default
import Data.Map (Map)
import qualified Data.Map as M
import Data.Maybe
import Data.Monoid ((<>))
import Data.Text (Text)
import qualified Data.Text as T
import GHC.Generics (Generic)
import Text.XML
import Text.XML.Cursor hiding (bool)
import qualified Xeno.DOM as Xeno

import Codec.Xlsx.Parser.Internal
import Codec.Xlsx.Types.Common
import Codec.Xlsx.Types.StyleSheet (Color)
import Codec.Xlsx.Writer.Internal

-- | Logical operation used in 'CellIs' condition
--
-- See 18.18.15 "ST_ConditionalFormattingOperator
-- (Conditional Format Operators)" (p. 2446)
data OperatorExpression
    = OpBeginsWith Formula         -- ^ 'Begins with' operator
    | OpBetween Formula Formula    -- ^ 'Between' operator
    | OpContainsText Formula       -- ^ 'Contains' operator
    | OpEndsWith Formula           -- ^ 'Ends with' operator
    | OpEqual Formula              -- ^ 'Equal to' operator
    | OpGreaterThan Formula        -- ^ 'Greater than' operator
    | OpGreaterThanOrEqual Formula -- ^ 'Greater than or equal to' operator
    | OpLessThan Formula           -- ^ 'Less than' operator
    | OpLessThanOrEqual Formula    -- ^ 'Less than or equal to' operator
    | OpNotBetween Formula Formula -- ^ 'Not between' operator
    | OpNotContains Formula        -- ^ 'Does not contain' operator
    | OpNotEqual Formula           -- ^ 'Not equal to' operator
    deriving (OperatorExpression -> OperatorExpression -> Bool
(OperatorExpression -> OperatorExpression -> Bool)
-> (OperatorExpression -> OperatorExpression -> Bool)
-> Eq OperatorExpression
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OperatorExpression -> OperatorExpression -> Bool
$c/= :: OperatorExpression -> OperatorExpression -> Bool
== :: OperatorExpression -> OperatorExpression -> Bool
$c== :: OperatorExpression -> OperatorExpression -> Bool
Eq, Eq OperatorExpression
Eq OperatorExpression
-> (OperatorExpression -> OperatorExpression -> Ordering)
-> (OperatorExpression -> OperatorExpression -> Bool)
-> (OperatorExpression -> OperatorExpression -> Bool)
-> (OperatorExpression -> OperatorExpression -> Bool)
-> (OperatorExpression -> OperatorExpression -> Bool)
-> (OperatorExpression -> OperatorExpression -> OperatorExpression)
-> (OperatorExpression -> OperatorExpression -> OperatorExpression)
-> Ord OperatorExpression
OperatorExpression -> OperatorExpression -> Bool
OperatorExpression -> OperatorExpression -> Ordering
OperatorExpression -> OperatorExpression -> OperatorExpression
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: OperatorExpression -> OperatorExpression -> OperatorExpression
$cmin :: OperatorExpression -> OperatorExpression -> OperatorExpression
max :: OperatorExpression -> OperatorExpression -> OperatorExpression
$cmax :: OperatorExpression -> OperatorExpression -> OperatorExpression
>= :: OperatorExpression -> OperatorExpression -> Bool
$c>= :: OperatorExpression -> OperatorExpression -> Bool
> :: OperatorExpression -> OperatorExpression -> Bool
$c> :: OperatorExpression -> OperatorExpression -> Bool
<= :: OperatorExpression -> OperatorExpression -> Bool
$c<= :: OperatorExpression -> OperatorExpression -> Bool
< :: OperatorExpression -> OperatorExpression -> Bool
$c< :: OperatorExpression -> OperatorExpression -> Bool
compare :: OperatorExpression -> OperatorExpression -> Ordering
$ccompare :: OperatorExpression -> OperatorExpression -> Ordering
$cp1Ord :: Eq OperatorExpression
Ord, Int -> OperatorExpression -> ShowS
[OperatorExpression] -> ShowS
OperatorExpression -> String
(Int -> OperatorExpression -> ShowS)
-> (OperatorExpression -> String)
-> ([OperatorExpression] -> ShowS)
-> Show OperatorExpression
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OperatorExpression] -> ShowS
$cshowList :: [OperatorExpression] -> ShowS
show :: OperatorExpression -> String
$cshow :: OperatorExpression -> String
showsPrec :: Int -> OperatorExpression -> ShowS
$cshowsPrec :: Int -> OperatorExpression -> ShowS
Show, (forall x. OperatorExpression -> Rep OperatorExpression x)
-> (forall x. Rep OperatorExpression x -> OperatorExpression)
-> Generic OperatorExpression
forall x. Rep OperatorExpression x -> OperatorExpression
forall x. OperatorExpression -> Rep OperatorExpression x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep OperatorExpression x -> OperatorExpression
$cfrom :: forall x. OperatorExpression -> Rep OperatorExpression x
Generic)
instance NFData OperatorExpression

-- | Used in a "contains dates" conditional formatting rule.
-- These are dynamic time periods, which change based on
-- the date the conditional formatting is refreshed / applied.
--
-- See 18.18.82 "ST_TimePeriod (Time Period Types)" (p. 2508)
data TimePeriod
    = PerLast7Days  -- ^ A date in the last seven days.
    | PerLastMonth  -- ^ A date occuring in the last calendar month.
    | PerLastWeek   -- ^ A date occuring last week.
    | PerNextMonth  -- ^ A date occuring in the next calendar month.
    | PerNextWeek   -- ^ A date occuring next week.
    | PerThisMonth  -- ^ A date occuring in this calendar month.
    | PerThisWeek   -- ^ A date occuring this week.
    | PerToday      -- ^ Today's date.
    | PerTomorrow   -- ^ Tomorrow's date.
    | PerYesterday  -- ^ Yesterday's date.
    deriving (TimePeriod -> TimePeriod -> Bool
(TimePeriod -> TimePeriod -> Bool)
-> (TimePeriod -> TimePeriod -> Bool) -> Eq TimePeriod
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TimePeriod -> TimePeriod -> Bool
$c/= :: TimePeriod -> TimePeriod -> Bool
== :: TimePeriod -> TimePeriod -> Bool
$c== :: TimePeriod -> TimePeriod -> Bool
Eq, Eq TimePeriod
Eq TimePeriod
-> (TimePeriod -> TimePeriod -> Ordering)
-> (TimePeriod -> TimePeriod -> Bool)
-> (TimePeriod -> TimePeriod -> Bool)
-> (TimePeriod -> TimePeriod -> Bool)
-> (TimePeriod -> TimePeriod -> Bool)
-> (TimePeriod -> TimePeriod -> TimePeriod)
-> (TimePeriod -> TimePeriod -> TimePeriod)
-> Ord TimePeriod
TimePeriod -> TimePeriod -> Bool
TimePeriod -> TimePeriod -> Ordering
TimePeriod -> TimePeriod -> TimePeriod
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: TimePeriod -> TimePeriod -> TimePeriod
$cmin :: TimePeriod -> TimePeriod -> TimePeriod
max :: TimePeriod -> TimePeriod -> TimePeriod
$cmax :: TimePeriod -> TimePeriod -> TimePeriod
>= :: TimePeriod -> TimePeriod -> Bool
$c>= :: TimePeriod -> TimePeriod -> Bool
> :: TimePeriod -> TimePeriod -> Bool
$c> :: TimePeriod -> TimePeriod -> Bool
<= :: TimePeriod -> TimePeriod -> Bool
$c<= :: TimePeriod -> TimePeriod -> Bool
< :: TimePeriod -> TimePeriod -> Bool
$c< :: TimePeriod -> TimePeriod -> Bool
compare :: TimePeriod -> TimePeriod -> Ordering
$ccompare :: TimePeriod -> TimePeriod -> Ordering
$cp1Ord :: Eq TimePeriod
Ord, Int -> TimePeriod -> ShowS
[TimePeriod] -> ShowS
TimePeriod -> String
(Int -> TimePeriod -> ShowS)
-> (TimePeriod -> String)
-> ([TimePeriod] -> ShowS)
-> Show TimePeriod
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TimePeriod] -> ShowS
$cshowList :: [TimePeriod] -> ShowS
show :: TimePeriod -> String
$cshow :: TimePeriod -> String
showsPrec :: Int -> TimePeriod -> ShowS
$cshowsPrec :: Int -> TimePeriod -> ShowS
Show, (forall x. TimePeriod -> Rep TimePeriod x)
-> (forall x. Rep TimePeriod x -> TimePeriod) -> Generic TimePeriod
forall x. Rep TimePeriod x -> TimePeriod
forall x. TimePeriod -> Rep TimePeriod x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TimePeriod x -> TimePeriod
$cfrom :: forall x. TimePeriod -> Rep TimePeriod x
Generic)
instance NFData TimePeriod

-- | Flag indicating whether the 'aboveAverage' and 'belowAverage'
-- criteria is inclusive of the average itself, or exclusive of that
-- value.
data Inclusion
  = Inclusive
  | Exclusive
  deriving (Inclusion -> Inclusion -> Bool
(Inclusion -> Inclusion -> Bool)
-> (Inclusion -> Inclusion -> Bool) -> Eq Inclusion
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Inclusion -> Inclusion -> Bool
$c/= :: Inclusion -> Inclusion -> Bool
== :: Inclusion -> Inclusion -> Bool
$c== :: Inclusion -> Inclusion -> Bool
Eq, Eq Inclusion
Eq Inclusion
-> (Inclusion -> Inclusion -> Ordering)
-> (Inclusion -> Inclusion -> Bool)
-> (Inclusion -> Inclusion -> Bool)
-> (Inclusion -> Inclusion -> Bool)
-> (Inclusion -> Inclusion -> Bool)
-> (Inclusion -> Inclusion -> Inclusion)
-> (Inclusion -> Inclusion -> Inclusion)
-> Ord Inclusion
Inclusion -> Inclusion -> Bool
Inclusion -> Inclusion -> Ordering
Inclusion -> Inclusion -> Inclusion
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Inclusion -> Inclusion -> Inclusion
$cmin :: Inclusion -> Inclusion -> Inclusion
max :: Inclusion -> Inclusion -> Inclusion
$cmax :: Inclusion -> Inclusion -> Inclusion
>= :: Inclusion -> Inclusion -> Bool
$c>= :: Inclusion -> Inclusion -> Bool
> :: Inclusion -> Inclusion -> Bool
$c> :: Inclusion -> Inclusion -> Bool
<= :: Inclusion -> Inclusion -> Bool
$c<= :: Inclusion -> Inclusion -> Bool
< :: Inclusion -> Inclusion -> Bool
$c< :: Inclusion -> Inclusion -> Bool
compare :: Inclusion -> Inclusion -> Ordering
$ccompare :: Inclusion -> Inclusion -> Ordering
$cp1Ord :: Eq Inclusion
Ord, Int -> Inclusion -> ShowS
[Inclusion] -> ShowS
Inclusion -> String
(Int -> Inclusion -> ShowS)
-> (Inclusion -> String)
-> ([Inclusion] -> ShowS)
-> Show Inclusion
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Inclusion] -> ShowS
$cshowList :: [Inclusion] -> ShowS
show :: Inclusion -> String
$cshow :: Inclusion -> String
showsPrec :: Int -> Inclusion -> ShowS
$cshowsPrec :: Int -> Inclusion -> ShowS
Show, (forall x. Inclusion -> Rep Inclusion x)
-> (forall x. Rep Inclusion x -> Inclusion) -> Generic Inclusion
forall x. Rep Inclusion x -> Inclusion
forall x. Inclusion -> Rep Inclusion x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Inclusion x -> Inclusion
$cfrom :: forall x. Inclusion -> Rep Inclusion x
Generic)
instance NFData Inclusion

-- | The number of standard deviations to include above or below the
-- average in the conditional formatting rule.
newtype NStdDev =
  NStdDev Int
  deriving (NStdDev -> NStdDev -> Bool
(NStdDev -> NStdDev -> Bool)
-> (NStdDev -> NStdDev -> Bool) -> Eq NStdDev
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NStdDev -> NStdDev -> Bool
$c/= :: NStdDev -> NStdDev -> Bool
== :: NStdDev -> NStdDev -> Bool
$c== :: NStdDev -> NStdDev -> Bool
Eq, Eq NStdDev
Eq NStdDev
-> (NStdDev -> NStdDev -> Ordering)
-> (NStdDev -> NStdDev -> Bool)
-> (NStdDev -> NStdDev -> Bool)
-> (NStdDev -> NStdDev -> Bool)
-> (NStdDev -> NStdDev -> Bool)
-> (NStdDev -> NStdDev -> NStdDev)
-> (NStdDev -> NStdDev -> NStdDev)
-> Ord NStdDev
NStdDev -> NStdDev -> Bool
NStdDev -> NStdDev -> Ordering
NStdDev -> NStdDev -> NStdDev
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: NStdDev -> NStdDev -> NStdDev
$cmin :: NStdDev -> NStdDev -> NStdDev
max :: NStdDev -> NStdDev -> NStdDev
$cmax :: NStdDev -> NStdDev -> NStdDev
>= :: NStdDev -> NStdDev -> Bool
$c>= :: NStdDev -> NStdDev -> Bool
> :: NStdDev -> NStdDev -> Bool
$c> :: NStdDev -> NStdDev -> Bool
<= :: NStdDev -> NStdDev -> Bool
$c<= :: NStdDev -> NStdDev -> Bool
< :: NStdDev -> NStdDev -> Bool
$c< :: NStdDev -> NStdDev -> Bool
compare :: NStdDev -> NStdDev -> Ordering
$ccompare :: NStdDev -> NStdDev -> Ordering
$cp1Ord :: Eq NStdDev
Ord, Int -> NStdDev -> ShowS
[NStdDev] -> ShowS
NStdDev -> String
(Int -> NStdDev -> ShowS)
-> (NStdDev -> String) -> ([NStdDev] -> ShowS) -> Show NStdDev
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [NStdDev] -> ShowS
$cshowList :: [NStdDev] -> ShowS
show :: NStdDev -> String
$cshow :: NStdDev -> String
showsPrec :: Int -> NStdDev -> ShowS
$cshowsPrec :: Int -> NStdDev -> ShowS
Show, (forall x. NStdDev -> Rep NStdDev x)
-> (forall x. Rep NStdDev x -> NStdDev) -> Generic NStdDev
forall x. Rep NStdDev x -> NStdDev
forall x. NStdDev -> Rep NStdDev x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep NStdDev x -> NStdDev
$cfrom :: forall x. NStdDev -> Rep NStdDev x
Generic)
instance NFData NStdDev

-- | Conditions which could be used for conditional formatting
--
-- See 18.18.12 "ST_CfType (Conditional Format Type)" (p. 2443)
data Condition
    -- | This conditional formatting rule highlights cells that are
    -- above (or maybe equal to) the average for all values in the range.
    = AboveAverage Inclusion (Maybe NStdDev)
    -- | This conditional formatting rule highlights cells in the
    -- range that begin with the given text. Equivalent to
    -- using the LEFT() sheet function and comparing values.
    | BeginsWith Text
    -- | This conditional formatting rule highlights cells that are
    -- below the average for all values in the range.
    | BelowAverage Inclusion (Maybe NStdDev)
    -- | This conditional formatting rule highlights cells whose
    -- values fall in the bottom N percent bracket.
    | BottomNPercent Int
    -- | This conditional formatting rule highlights cells whose
    -- values fall in the bottom N bracket.
    | BottomNValues Int
    -- | This conditional formatting rule compares a cell value
    -- to a formula calculated result, using an operator.
    | CellIs OperatorExpression
    -- | This conditional formatting rule creates a gradated color
    -- scale on the cells with specified colors for specified minimum
    -- and maximum.
    | ColorScale2 MinCfValue Color MaxCfValue Color
    -- | This conditional formatting rule creates a gradated color
    -- scale on the cells with specified colors for specified minimum,
    -- midpoint and maximum.
    | ColorScale3 MinCfValue Color CfValue Color MaxCfValue Color
    -- | This conditional formatting rule highlights cells that
    -- are completely blank. Equivalent of using LEN(TRIM()).
    -- This means that if the cell contains only characters
    -- that TRIM() would remove, then it is considered blank.
    -- An empty cell is also considered blank.
    | ContainsBlanks
    -- | This conditional formatting rule highlights cells with
    -- formula errors. Equivalent to using ISERROR() sheet
    -- function to determine if there is a formula error.
    | ContainsErrors
    -- | This conditional formatting rule highlights cells
    -- containing given text. Equivalent to using the SEARCH()
    -- sheet function to determine whether the cell contains
    -- the text.
    | ContainsText Text
    -- | This conditional formatting rule displays a gradated data bar
    -- in the range of cells.
    | DataBar DataBarOptions
    -- | This conditional formatting rule highlights cells
    -- without formula errors. Equivalent to using ISERROR()
    -- sheet function to determine if there is a formula error.
    | DoesNotContainErrors
    -- | This conditional formatting rule highlights cells that
    -- are not blank. Equivalent of using LEN(TRIM()). This
    -- means that if the cell contains only characters that
    -- TRIM() would remove, then it is considered blank. An
    -- empty cell is also considered blank.
    | DoesNotContainBlanks
    -- | This conditional formatting rule highlights cells that do
    -- not contain given text. Equivalent to using the
    -- SEARCH() sheet function.
    | DoesNotContainText Text
    -- | This conditional formatting rule highlights duplicated
    -- values.
    | DuplicateValues
    -- | This conditional formatting rule highlights cells ending
    -- with given text. Equivalent to using the RIGHT() sheet
    -- function and comparing values.
    | EndsWith Text
    -- | This conditional formatting rule contains a formula to
    -- evaluate. When the formula result is true, the cell is
    -- highlighted.
    | Expression Formula
    -- | This conditional formatting rule applies icons to cells
    -- according to their values.
    | IconSet IconSetOptions
    -- | This conditional formatting rule highlights cells
    -- containing dates in the specified time period. The
    -- underlying value of the cell is evaluated, therefore the
    -- cell does not need to be formatted as a date to be
    -- evaluated. For example, with a cell containing the
    -- value 38913 the conditional format shall be applied if
    -- the rule requires a value of 7/14/2006.
    | InTimePeriod TimePeriod
    -- | This conditional formatting rule highlights cells whose
    -- values fall in the top N percent bracket.
    | TopNPercent Int
    -- | This conditional formatting rule highlights cells whose
    -- values fall in the top N bracket.
    | TopNValues Int
    -- | This conditional formatting rule highlights unique values in the range.
    | UniqueValues
    deriving (Condition -> Condition -> Bool
(Condition -> Condition -> Bool)
-> (Condition -> Condition -> Bool) -> Eq Condition
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Condition -> Condition -> Bool
$c/= :: Condition -> Condition -> Bool
== :: Condition -> Condition -> Bool
$c== :: Condition -> Condition -> Bool
Eq, Eq Condition
Eq Condition
-> (Condition -> Condition -> Ordering)
-> (Condition -> Condition -> Bool)
-> (Condition -> Condition -> Bool)
-> (Condition -> Condition -> Bool)
-> (Condition -> Condition -> Bool)
-> (Condition -> Condition -> Condition)
-> (Condition -> Condition -> Condition)
-> Ord Condition
Condition -> Condition -> Bool
Condition -> Condition -> Ordering
Condition -> Condition -> Condition
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Condition -> Condition -> Condition
$cmin :: Condition -> Condition -> Condition
max :: Condition -> Condition -> Condition
$cmax :: Condition -> Condition -> Condition
>= :: Condition -> Condition -> Bool
$c>= :: Condition -> Condition -> Bool
> :: Condition -> Condition -> Bool
$c> :: Condition -> Condition -> Bool
<= :: Condition -> Condition -> Bool
$c<= :: Condition -> Condition -> Bool
< :: Condition -> Condition -> Bool
$c< :: Condition -> Condition -> Bool
compare :: Condition -> Condition -> Ordering
$ccompare :: Condition -> Condition -> Ordering
$cp1Ord :: Eq Condition
Ord, Int -> Condition -> ShowS
[Condition] -> ShowS
Condition -> String
(Int -> Condition -> ShowS)
-> (Condition -> String)
-> ([Condition] -> ShowS)
-> Show Condition
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Condition] -> ShowS
$cshowList :: [Condition] -> ShowS
show :: Condition -> String
$cshow :: Condition -> String
showsPrec :: Int -> Condition -> ShowS
$cshowsPrec :: Int -> Condition -> ShowS
Show, (forall x. Condition -> Rep Condition x)
-> (forall x. Rep Condition x -> Condition) -> Generic Condition
forall x. Rep Condition x -> Condition
forall x. Condition -> Rep Condition x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Condition x -> Condition
$cfrom :: forall x. Condition -> Rep Condition x
Generic)
instance NFData Condition

-- | Describes the values of the interpolation points in a color
-- scale, data bar or icon set conditional formatting rules.
--
-- See 18.3.1.11 "cfvo (Conditional Format Value Object)" (p. 1604)
data CfValue
  = CfValue Double
  | CfPercent Double
  | CfPercentile Double
  | CfFormula Formula
  deriving (CfValue -> CfValue -> Bool
(CfValue -> CfValue -> Bool)
-> (CfValue -> CfValue -> Bool) -> Eq CfValue
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CfValue -> CfValue -> Bool
$c/= :: CfValue -> CfValue -> Bool
== :: CfValue -> CfValue -> Bool
$c== :: CfValue -> CfValue -> Bool
Eq, Eq CfValue
Eq CfValue
-> (CfValue -> CfValue -> Ordering)
-> (CfValue -> CfValue -> Bool)
-> (CfValue -> CfValue -> Bool)
-> (CfValue -> CfValue -> Bool)
-> (CfValue -> CfValue -> Bool)
-> (CfValue -> CfValue -> CfValue)
-> (CfValue -> CfValue -> CfValue)
-> Ord CfValue
CfValue -> CfValue -> Bool
CfValue -> CfValue -> Ordering
CfValue -> CfValue -> CfValue
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: CfValue -> CfValue -> CfValue
$cmin :: CfValue -> CfValue -> CfValue
max :: CfValue -> CfValue -> CfValue
$cmax :: CfValue -> CfValue -> CfValue
>= :: CfValue -> CfValue -> Bool
$c>= :: CfValue -> CfValue -> Bool
> :: CfValue -> CfValue -> Bool
$c> :: CfValue -> CfValue -> Bool
<= :: CfValue -> CfValue -> Bool
$c<= :: CfValue -> CfValue -> Bool
< :: CfValue -> CfValue -> Bool
$c< :: CfValue -> CfValue -> Bool
compare :: CfValue -> CfValue -> Ordering
$ccompare :: CfValue -> CfValue -> Ordering
$cp1Ord :: Eq CfValue
Ord, Int -> CfValue -> ShowS
[CfValue] -> ShowS
CfValue -> String
(Int -> CfValue -> ShowS)
-> (CfValue -> String) -> ([CfValue] -> ShowS) -> Show CfValue
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CfValue] -> ShowS
$cshowList :: [CfValue] -> ShowS
show :: CfValue -> String
$cshow :: CfValue -> String
showsPrec :: Int -> CfValue -> ShowS
$cshowsPrec :: Int -> CfValue -> ShowS
Show, (forall x. CfValue -> Rep CfValue x)
-> (forall x. Rep CfValue x -> CfValue) -> Generic CfValue
forall x. Rep CfValue x -> CfValue
forall x. CfValue -> Rep CfValue x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CfValue x -> CfValue
$cfrom :: forall x. CfValue -> Rep CfValue x
Generic)
instance NFData CfValue

data MinCfValue
  = CfvMin
  | MinCfValue CfValue
  deriving (MinCfValue -> MinCfValue -> Bool
(MinCfValue -> MinCfValue -> Bool)
-> (MinCfValue -> MinCfValue -> Bool) -> Eq MinCfValue
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MinCfValue -> MinCfValue -> Bool
$c/= :: MinCfValue -> MinCfValue -> Bool
== :: MinCfValue -> MinCfValue -> Bool
$c== :: MinCfValue -> MinCfValue -> Bool
Eq, Eq MinCfValue
Eq MinCfValue
-> (MinCfValue -> MinCfValue -> Ordering)
-> (MinCfValue -> MinCfValue -> Bool)
-> (MinCfValue -> MinCfValue -> Bool)
-> (MinCfValue -> MinCfValue -> Bool)
-> (MinCfValue -> MinCfValue -> Bool)
-> (MinCfValue -> MinCfValue -> MinCfValue)
-> (MinCfValue -> MinCfValue -> MinCfValue)
-> Ord MinCfValue
MinCfValue -> MinCfValue -> Bool
MinCfValue -> MinCfValue -> Ordering
MinCfValue -> MinCfValue -> MinCfValue
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: MinCfValue -> MinCfValue -> MinCfValue
$cmin :: MinCfValue -> MinCfValue -> MinCfValue
max :: MinCfValue -> MinCfValue -> MinCfValue
$cmax :: MinCfValue -> MinCfValue -> MinCfValue
>= :: MinCfValue -> MinCfValue -> Bool
$c>= :: MinCfValue -> MinCfValue -> Bool
> :: MinCfValue -> MinCfValue -> Bool
$c> :: MinCfValue -> MinCfValue -> Bool
<= :: MinCfValue -> MinCfValue -> Bool
$c<= :: MinCfValue -> MinCfValue -> Bool
< :: MinCfValue -> MinCfValue -> Bool
$c< :: MinCfValue -> MinCfValue -> Bool
compare :: MinCfValue -> MinCfValue -> Ordering
$ccompare :: MinCfValue -> MinCfValue -> Ordering
$cp1Ord :: Eq MinCfValue
Ord, Int -> MinCfValue -> ShowS
[MinCfValue] -> ShowS
MinCfValue -> String
(Int -> MinCfValue -> ShowS)
-> (MinCfValue -> String)
-> ([MinCfValue] -> ShowS)
-> Show MinCfValue
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MinCfValue] -> ShowS
$cshowList :: [MinCfValue] -> ShowS
show :: MinCfValue -> String
$cshow :: MinCfValue -> String
showsPrec :: Int -> MinCfValue -> ShowS
$cshowsPrec :: Int -> MinCfValue -> ShowS
Show, (forall x. MinCfValue -> Rep MinCfValue x)
-> (forall x. Rep MinCfValue x -> MinCfValue) -> Generic MinCfValue
forall x. Rep MinCfValue x -> MinCfValue
forall x. MinCfValue -> Rep MinCfValue x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep MinCfValue x -> MinCfValue
$cfrom :: forall x. MinCfValue -> Rep MinCfValue x
Generic)
instance NFData MinCfValue

data MaxCfValue
  = CfvMax
  | MaxCfValue CfValue
  deriving (MaxCfValue -> MaxCfValue -> Bool
(MaxCfValue -> MaxCfValue -> Bool)
-> (MaxCfValue -> MaxCfValue -> Bool) -> Eq MaxCfValue
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MaxCfValue -> MaxCfValue -> Bool
$c/= :: MaxCfValue -> MaxCfValue -> Bool
== :: MaxCfValue -> MaxCfValue -> Bool
$c== :: MaxCfValue -> MaxCfValue -> Bool
Eq, Eq MaxCfValue
Eq MaxCfValue
-> (MaxCfValue -> MaxCfValue -> Ordering)
-> (MaxCfValue -> MaxCfValue -> Bool)
-> (MaxCfValue -> MaxCfValue -> Bool)
-> (MaxCfValue -> MaxCfValue -> Bool)
-> (MaxCfValue -> MaxCfValue -> Bool)
-> (MaxCfValue -> MaxCfValue -> MaxCfValue)
-> (MaxCfValue -> MaxCfValue -> MaxCfValue)
-> Ord MaxCfValue
MaxCfValue -> MaxCfValue -> Bool
MaxCfValue -> MaxCfValue -> Ordering
MaxCfValue -> MaxCfValue -> MaxCfValue
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: MaxCfValue -> MaxCfValue -> MaxCfValue
$cmin :: MaxCfValue -> MaxCfValue -> MaxCfValue
max :: MaxCfValue -> MaxCfValue -> MaxCfValue
$cmax :: MaxCfValue -> MaxCfValue -> MaxCfValue
>= :: MaxCfValue -> MaxCfValue -> Bool
$c>= :: MaxCfValue -> MaxCfValue -> Bool
> :: MaxCfValue -> MaxCfValue -> Bool
$c> :: MaxCfValue -> MaxCfValue -> Bool
<= :: MaxCfValue -> MaxCfValue -> Bool
$c<= :: MaxCfValue -> MaxCfValue -> Bool
< :: MaxCfValue -> MaxCfValue -> Bool
$c< :: MaxCfValue -> MaxCfValue -> Bool
compare :: MaxCfValue -> MaxCfValue -> Ordering
$ccompare :: MaxCfValue -> MaxCfValue -> Ordering
$cp1Ord :: Eq MaxCfValue
Ord, Int -> MaxCfValue -> ShowS
[MaxCfValue] -> ShowS
MaxCfValue -> String
(Int -> MaxCfValue -> ShowS)
-> (MaxCfValue -> String)
-> ([MaxCfValue] -> ShowS)
-> Show MaxCfValue
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MaxCfValue] -> ShowS
$cshowList :: [MaxCfValue] -> ShowS
show :: MaxCfValue -> String
$cshow :: MaxCfValue -> String
showsPrec :: Int -> MaxCfValue -> ShowS
$cshowsPrec :: Int -> MaxCfValue -> ShowS
Show, (forall x. MaxCfValue -> Rep MaxCfValue x)
-> (forall x. Rep MaxCfValue x -> MaxCfValue) -> Generic MaxCfValue
forall x. Rep MaxCfValue x -> MaxCfValue
forall x. MaxCfValue -> Rep MaxCfValue x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep MaxCfValue x -> MaxCfValue
$cfrom :: forall x. MaxCfValue -> Rep MaxCfValue x
Generic)
instance NFData MaxCfValue

-- | internal type for (de)serialization
--
-- See 18.18.13 "ST_CfvoType (Conditional Format Value Object Type)" (p. 2445)
data CfvType =
  CfvtFormula
  -- ^ The minimum\/ midpoint \/ maximum value for the gradient is
  -- determined by a formula.
  | CfvtMax
  -- ^ Indicates that the maximum value in the range shall be used as
  -- the maximum value for the gradient.
  | CfvtMin
  -- ^ Indicates that the minimum value in the range shall be used as
  -- the minimum value for the gradient.
  | CfvtNum
  -- ^ Indicates that the minimum \/ midpoint \/ maximum value for the
  -- gradient is specified by a constant numeric value.
  | CfvtPercent
  -- ^ Value indicates a percentage between the minimum and maximum
  -- values in the range shall be used as the minimum \/ midpoint \/
  -- maximum value for the gradient.
  | CfvtPercentile
  -- ^ Value indicates a percentile ranking in the range shall be used
  -- as the minimum \/ midpoint \/ maximum value for the gradient.
  deriving (CfvType -> CfvType -> Bool
(CfvType -> CfvType -> Bool)
-> (CfvType -> CfvType -> Bool) -> Eq CfvType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CfvType -> CfvType -> Bool
$c/= :: CfvType -> CfvType -> Bool
== :: CfvType -> CfvType -> Bool
$c== :: CfvType -> CfvType -> Bool
Eq, Eq CfvType
Eq CfvType
-> (CfvType -> CfvType -> Ordering)
-> (CfvType -> CfvType -> Bool)
-> (CfvType -> CfvType -> Bool)
-> (CfvType -> CfvType -> Bool)
-> (CfvType -> CfvType -> Bool)
-> (CfvType -> CfvType -> CfvType)
-> (CfvType -> CfvType -> CfvType)
-> Ord CfvType
CfvType -> CfvType -> Bool
CfvType -> CfvType -> Ordering
CfvType -> CfvType -> CfvType
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: CfvType -> CfvType -> CfvType
$cmin :: CfvType -> CfvType -> CfvType
max :: CfvType -> CfvType -> CfvType
$cmax :: CfvType -> CfvType -> CfvType
>= :: CfvType -> CfvType -> Bool
$c>= :: CfvType -> CfvType -> Bool
> :: CfvType -> CfvType -> Bool
$c> :: CfvType -> CfvType -> Bool
<= :: CfvType -> CfvType -> Bool
$c<= :: CfvType -> CfvType -> Bool
< :: CfvType -> CfvType -> Bool
$c< :: CfvType -> CfvType -> Bool
compare :: CfvType -> CfvType -> Ordering
$ccompare :: CfvType -> CfvType -> Ordering
$cp1Ord :: Eq CfvType
Ord, Int -> CfvType -> ShowS
[CfvType] -> ShowS
CfvType -> String
(Int -> CfvType -> ShowS)
-> (CfvType -> String) -> ([CfvType] -> ShowS) -> Show CfvType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CfvType] -> ShowS
$cshowList :: [CfvType] -> ShowS
show :: CfvType -> String
$cshow :: CfvType -> String
showsPrec :: Int -> CfvType -> ShowS
$cshowsPrec :: Int -> CfvType -> ShowS
Show, (forall x. CfvType -> Rep CfvType x)
-> (forall x. Rep CfvType x -> CfvType) -> Generic CfvType
forall x. Rep CfvType x -> CfvType
forall x. CfvType -> Rep CfvType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CfvType x -> CfvType
$cfrom :: forall x. CfvType -> Rep CfvType x
Generic)
instance NFData CfvType

-- | Describes an icon set conditional formatting rule.
--
-- See 18.3.1.49 "iconSet (Icon Set)" (p. 1645)
data IconSetOptions = IconSetOptions
  { IconSetOptions -> IconSetType
_isoIconSet :: IconSetType
  -- ^ icon set used, default value is 'IconSet3Trafficlights1'
  , IconSetOptions -> [CfValue]
_isoValues :: [CfValue]
  -- ^ values describing per icon ranges
  , IconSetOptions -> Bool
_isoReverse :: Bool
  -- ^ reverses the default order of the icons in the specified icon set
  , IconSetOptions -> Bool
_isoShowValue :: Bool
  -- ^ indicates whether to show the values of the cells on which this
  -- icon set is applied.
  } deriving (IconSetOptions -> IconSetOptions -> Bool
(IconSetOptions -> IconSetOptions -> Bool)
-> (IconSetOptions -> IconSetOptions -> Bool) -> Eq IconSetOptions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: IconSetOptions -> IconSetOptions -> Bool
$c/= :: IconSetOptions -> IconSetOptions -> Bool
== :: IconSetOptions -> IconSetOptions -> Bool
$c== :: IconSetOptions -> IconSetOptions -> Bool
Eq, Eq IconSetOptions
Eq IconSetOptions
-> (IconSetOptions -> IconSetOptions -> Ordering)
-> (IconSetOptions -> IconSetOptions -> Bool)
-> (IconSetOptions -> IconSetOptions -> Bool)
-> (IconSetOptions -> IconSetOptions -> Bool)
-> (IconSetOptions -> IconSetOptions -> Bool)
-> (IconSetOptions -> IconSetOptions -> IconSetOptions)
-> (IconSetOptions -> IconSetOptions -> IconSetOptions)
-> Ord IconSetOptions
IconSetOptions -> IconSetOptions -> Bool
IconSetOptions -> IconSetOptions -> Ordering
IconSetOptions -> IconSetOptions -> IconSetOptions
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: IconSetOptions -> IconSetOptions -> IconSetOptions
$cmin :: IconSetOptions -> IconSetOptions -> IconSetOptions
max :: IconSetOptions -> IconSetOptions -> IconSetOptions
$cmax :: IconSetOptions -> IconSetOptions -> IconSetOptions
>= :: IconSetOptions -> IconSetOptions -> Bool
$c>= :: IconSetOptions -> IconSetOptions -> Bool
> :: IconSetOptions -> IconSetOptions -> Bool
$c> :: IconSetOptions -> IconSetOptions -> Bool
<= :: IconSetOptions -> IconSetOptions -> Bool
$c<= :: IconSetOptions -> IconSetOptions -> Bool
< :: IconSetOptions -> IconSetOptions -> Bool
$c< :: IconSetOptions -> IconSetOptions -> Bool
compare :: IconSetOptions -> IconSetOptions -> Ordering
$ccompare :: IconSetOptions -> IconSetOptions -> Ordering
$cp1Ord :: Eq IconSetOptions
Ord, Int -> IconSetOptions -> ShowS
[IconSetOptions] -> ShowS
IconSetOptions -> String
(Int -> IconSetOptions -> ShowS)
-> (IconSetOptions -> String)
-> ([IconSetOptions] -> ShowS)
-> Show IconSetOptions
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IconSetOptions] -> ShowS
$cshowList :: [IconSetOptions] -> ShowS
show :: IconSetOptions -> String
$cshow :: IconSetOptions -> String
showsPrec :: Int -> IconSetOptions -> ShowS
$cshowsPrec :: Int -> IconSetOptions -> ShowS
Show, (forall x. IconSetOptions -> Rep IconSetOptions x)
-> (forall x. Rep IconSetOptions x -> IconSetOptions)
-> Generic IconSetOptions
forall x. Rep IconSetOptions x -> IconSetOptions
forall x. IconSetOptions -> Rep IconSetOptions x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep IconSetOptions x -> IconSetOptions
$cfrom :: forall x. IconSetOptions -> Rep IconSetOptions x
Generic)
instance NFData IconSetOptions

-- | Icon set type for conditional formatting. 'CfValue' fields
-- determine lower range bounds. I.e. @IconSet3Signs (CfPercent 0)
-- (CfPercent 33) (CfPercent 67)@ say that 1st icon will be shown for
-- values ranging from 0 to 33 percents, 2nd for 33 to 67 percent and
-- the 3rd one for values from 67 to 100 percent.
--
-- 18.18.42 "ST_IconSetType (Icon Set Type)" (p. 2463)
data IconSetType =
  IconSet3Arrows -- CfValue CfValue CfValue
  | IconSet3ArrowsGray -- CfValue CfValue CfValue
  | IconSet3Flags -- CfValue CfValue CfValue
  | IconSet3Signs -- CfValue CfValue CfValue
  | IconSet3Symbols -- CfValue CfValue CfValue
  | IconSet3Symbols2 -- CfValue CfValue CfValue
  | IconSet3TrafficLights1 -- CfValue CfValue CfValue
  | IconSet3TrafficLights2 -- CfValue CfValue CfValue
  -- ^ 3 traffic lights icon set with thick black border.
  | IconSet4Arrows -- CfValue CfValue CfValue CfValue
  | IconSet4ArrowsGray -- CfValue CfValue CfValue CfValue
  | IconSet4Rating -- CfValue CfValue CfValue CfValue
  | IconSet4RedToBlack -- CfValue CfValue CfValue CfValue
  | IconSet4TrafficLights -- CfValue CfValue CfValue CfValue
  | IconSet5Arrows -- CfValue CfValue CfValue CfValue CfValue
  | IconSet5ArrowsGray -- CfValue CfValue CfValue CfValue CfValue
  | IconSet5Quarters -- CfValue CfValue CfValue CfValue CfValue
  | IconSet5Rating -- CfValue CfValue CfValue CfValue CfValue
  deriving  (IconSetType -> IconSetType -> Bool
(IconSetType -> IconSetType -> Bool)
-> (IconSetType -> IconSetType -> Bool) -> Eq IconSetType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: IconSetType -> IconSetType -> Bool
$c/= :: IconSetType -> IconSetType -> Bool
== :: IconSetType -> IconSetType -> Bool
$c== :: IconSetType -> IconSetType -> Bool
Eq, Eq IconSetType
Eq IconSetType
-> (IconSetType -> IconSetType -> Ordering)
-> (IconSetType -> IconSetType -> Bool)
-> (IconSetType -> IconSetType -> Bool)
-> (IconSetType -> IconSetType -> Bool)
-> (IconSetType -> IconSetType -> Bool)
-> (IconSetType -> IconSetType -> IconSetType)
-> (IconSetType -> IconSetType -> IconSetType)
-> Ord IconSetType
IconSetType -> IconSetType -> Bool
IconSetType -> IconSetType -> Ordering
IconSetType -> IconSetType -> IconSetType
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: IconSetType -> IconSetType -> IconSetType
$cmin :: IconSetType -> IconSetType -> IconSetType
max :: IconSetType -> IconSetType -> IconSetType
$cmax :: IconSetType -> IconSetType -> IconSetType
>= :: IconSetType -> IconSetType -> Bool
$c>= :: IconSetType -> IconSetType -> Bool
> :: IconSetType -> IconSetType -> Bool
$c> :: IconSetType -> IconSetType -> Bool
<= :: IconSetType -> IconSetType -> Bool
$c<= :: IconSetType -> IconSetType -> Bool
< :: IconSetType -> IconSetType -> Bool
$c< :: IconSetType -> IconSetType -> Bool
compare :: IconSetType -> IconSetType -> Ordering
$ccompare :: IconSetType -> IconSetType -> Ordering
$cp1Ord :: Eq IconSetType
Ord, Int -> IconSetType -> ShowS
[IconSetType] -> ShowS
IconSetType -> String
(Int -> IconSetType -> ShowS)
-> (IconSetType -> String)
-> ([IconSetType] -> ShowS)
-> Show IconSetType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IconSetType] -> ShowS
$cshowList :: [IconSetType] -> ShowS
show :: IconSetType -> String
$cshow :: IconSetType -> String
showsPrec :: Int -> IconSetType -> ShowS
$cshowsPrec :: Int -> IconSetType -> ShowS
Show, (forall x. IconSetType -> Rep IconSetType x)
-> (forall x. Rep IconSetType x -> IconSetType)
-> Generic IconSetType
forall x. Rep IconSetType x -> IconSetType
forall x. IconSetType -> Rep IconSetType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep IconSetType x -> IconSetType
$cfrom :: forall x. IconSetType -> Rep IconSetType x
Generic)
instance NFData IconSetType

-- | Describes a data bar conditional formatting rule.
--
-- See 18.3.1.28 "dataBar (Data Bar)" (p. 1621)
data DataBarOptions = DataBarOptions
  { DataBarOptions -> Int
_dboMaxLength :: Int
  -- ^ The maximum length of the data bar, as a percentage of the cell
  -- width.
  , DataBarOptions -> Int
_dboMinLength :: Int
  -- ^ The minimum length of the data bar, as a percentage of the cell
  -- width.
  , DataBarOptions -> Bool
_dboShowValue :: Bool
  -- ^ Indicates whether to show the values of the cells on which this
  -- data bar is applied.
  , DataBarOptions -> MinCfValue
_dboMinimum :: MinCfValue
  , DataBarOptions -> MaxCfValue
_dboMaximum :: MaxCfValue
  , DataBarOptions -> Color
_dboColor :: Color
  } deriving (DataBarOptions -> DataBarOptions -> Bool
(DataBarOptions -> DataBarOptions -> Bool)
-> (DataBarOptions -> DataBarOptions -> Bool) -> Eq DataBarOptions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DataBarOptions -> DataBarOptions -> Bool
$c/= :: DataBarOptions -> DataBarOptions -> Bool
== :: DataBarOptions -> DataBarOptions -> Bool
$c== :: DataBarOptions -> DataBarOptions -> Bool
Eq, Eq DataBarOptions
Eq DataBarOptions
-> (DataBarOptions -> DataBarOptions -> Ordering)
-> (DataBarOptions -> DataBarOptions -> Bool)
-> (DataBarOptions -> DataBarOptions -> Bool)
-> (DataBarOptions -> DataBarOptions -> Bool)
-> (DataBarOptions -> DataBarOptions -> Bool)
-> (DataBarOptions -> DataBarOptions -> DataBarOptions)
-> (DataBarOptions -> DataBarOptions -> DataBarOptions)
-> Ord DataBarOptions
DataBarOptions -> DataBarOptions -> Bool
DataBarOptions -> DataBarOptions -> Ordering
DataBarOptions -> DataBarOptions -> DataBarOptions
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: DataBarOptions -> DataBarOptions -> DataBarOptions
$cmin :: DataBarOptions -> DataBarOptions -> DataBarOptions
max :: DataBarOptions -> DataBarOptions -> DataBarOptions
$cmax :: DataBarOptions -> DataBarOptions -> DataBarOptions
>= :: DataBarOptions -> DataBarOptions -> Bool
$c>= :: DataBarOptions -> DataBarOptions -> Bool
> :: DataBarOptions -> DataBarOptions -> Bool
$c> :: DataBarOptions -> DataBarOptions -> Bool
<= :: DataBarOptions -> DataBarOptions -> Bool
$c<= :: DataBarOptions -> DataBarOptions -> Bool
< :: DataBarOptions -> DataBarOptions -> Bool
$c< :: DataBarOptions -> DataBarOptions -> Bool
compare :: DataBarOptions -> DataBarOptions -> Ordering
$ccompare :: DataBarOptions -> DataBarOptions -> Ordering
$cp1Ord :: Eq DataBarOptions
Ord, Int -> DataBarOptions -> ShowS
[DataBarOptions] -> ShowS
DataBarOptions -> String
(Int -> DataBarOptions -> ShowS)
-> (DataBarOptions -> String)
-> ([DataBarOptions] -> ShowS)
-> Show DataBarOptions
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DataBarOptions] -> ShowS
$cshowList :: [DataBarOptions] -> ShowS
show :: DataBarOptions -> String
$cshow :: DataBarOptions -> String
showsPrec :: Int -> DataBarOptions -> ShowS
$cshowsPrec :: Int -> DataBarOptions -> ShowS
Show, (forall x. DataBarOptions -> Rep DataBarOptions x)
-> (forall x. Rep DataBarOptions x -> DataBarOptions)
-> Generic DataBarOptions
forall x. Rep DataBarOptions x -> DataBarOptions
forall x. DataBarOptions -> Rep DataBarOptions x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DataBarOptions x -> DataBarOptions
$cfrom :: forall x. DataBarOptions -> Rep DataBarOptions x
Generic)
instance NFData DataBarOptions

defaultDboMaxLength :: Int
defaultDboMaxLength :: Int
defaultDboMaxLength = Int
90

defaultDboMinLength :: Int
defaultDboMinLength :: Int
defaultDboMinLength = Int
10

dataBarWithColor :: Color -> Condition
dataBarWithColor :: Color -> Condition
dataBarWithColor Color
c =
  DataBarOptions -> Condition
DataBar
    DataBarOptions :: Int
-> Int
-> Bool
-> MinCfValue
-> MaxCfValue
-> Color
-> DataBarOptions
DataBarOptions
    { _dboMaxLength :: Int
_dboMaxLength = Int
defaultDboMaxLength
    , _dboMinLength :: Int
_dboMinLength = Int
defaultDboMinLength
    , _dboShowValue :: Bool
_dboShowValue = Bool
True
    , _dboMinimum :: MinCfValue
_dboMinimum = MinCfValue
CfvMin
    , _dboMaximum :: MaxCfValue
_dboMaximum = MaxCfValue
CfvMax
    , _dboColor :: Color
_dboColor = Color
c
    }

-- | This collection represents a description of a conditional formatting rule.
--
-- See 18.3.1.10 "cfRule (Conditional Formatting Rule)" (p. 1602)
data CfRule = CfRule
    { CfRule -> Condition
_cfrCondition  :: Condition
    -- | This is an index to a dxf element in the Styles Part
    -- indicating which cell formatting to
    -- apply when the conditional formatting rule criteria is met.
    , CfRule -> Maybe Int
_cfrDxfId      :: Maybe Int
    -- | The priority of this conditional formatting rule. This value
    -- is used to determine which format should be evaluated and
    -- rendered. Lower numeric values are higher priority than
    -- higher numeric values, where 1 is the highest priority.
    , CfRule -> Int
_cfrPriority   :: Int
    -- | If this flag is set, no rules with lower priority shall
    -- be applied over this rule, when this rule
    -- evaluates to true.
    , CfRule -> Maybe Bool
_cfrStopIfTrue :: Maybe Bool
    } deriving (CfRule -> CfRule -> Bool
(CfRule -> CfRule -> Bool)
-> (CfRule -> CfRule -> Bool) -> Eq CfRule
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CfRule -> CfRule -> Bool
$c/= :: CfRule -> CfRule -> Bool
== :: CfRule -> CfRule -> Bool
$c== :: CfRule -> CfRule -> Bool
Eq, Eq CfRule
Eq CfRule
-> (CfRule -> CfRule -> Ordering)
-> (CfRule -> CfRule -> Bool)
-> (CfRule -> CfRule -> Bool)
-> (CfRule -> CfRule -> Bool)
-> (CfRule -> CfRule -> Bool)
-> (CfRule -> CfRule -> CfRule)
-> (CfRule -> CfRule -> CfRule)
-> Ord CfRule
CfRule -> CfRule -> Bool
CfRule -> CfRule -> Ordering
CfRule -> CfRule -> CfRule
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: CfRule -> CfRule -> CfRule
$cmin :: CfRule -> CfRule -> CfRule
max :: CfRule -> CfRule -> CfRule
$cmax :: CfRule -> CfRule -> CfRule
>= :: CfRule -> CfRule -> Bool
$c>= :: CfRule -> CfRule -> Bool
> :: CfRule -> CfRule -> Bool
$c> :: CfRule -> CfRule -> Bool
<= :: CfRule -> CfRule -> Bool
$c<= :: CfRule -> CfRule -> Bool
< :: CfRule -> CfRule -> Bool
$c< :: CfRule -> CfRule -> Bool
compare :: CfRule -> CfRule -> Ordering
$ccompare :: CfRule -> CfRule -> Ordering
$cp1Ord :: Eq CfRule
Ord, Int -> CfRule -> ShowS
[CfRule] -> ShowS
CfRule -> String
(Int -> CfRule -> ShowS)
-> (CfRule -> String) -> ([CfRule] -> ShowS) -> Show CfRule
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CfRule] -> ShowS
$cshowList :: [CfRule] -> ShowS
show :: CfRule -> String
$cshow :: CfRule -> String
showsPrec :: Int -> CfRule -> ShowS
$cshowsPrec :: Int -> CfRule -> ShowS
Show, (forall x. CfRule -> Rep CfRule x)
-> (forall x. Rep CfRule x -> CfRule) -> Generic CfRule
forall x. Rep CfRule x -> CfRule
forall x. CfRule -> Rep CfRule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CfRule x -> CfRule
$cfrom :: forall x. CfRule -> Rep CfRule x
Generic)
instance NFData CfRule

instance Default IconSetOptions where
  def :: IconSetOptions
def =
    IconSetOptions :: IconSetType -> [CfValue] -> Bool -> Bool -> IconSetOptions
IconSetOptions
    { _isoIconSet :: IconSetType
_isoIconSet = IconSetType
IconSet3TrafficLights1
    , _isoValues :: [CfValue]
_isoValues = [Double -> CfValue
CfPercent Double
0, Double -> CfValue
CfPercent Double
33.33, Double -> CfValue
CfPercent Double
66.67]
--        IconSet3TrafficLights1 (CfPercent 0) (CfPercent 33.33) (CfPercent 66.67)
    , _isoReverse :: Bool
_isoReverse = Bool
False
    , _isoShowValue :: Bool
_isoShowValue = Bool
True
    }

makeLenses ''CfRule
makeLenses ''IconSetOptions
makeLenses ''DataBarOptions

type ConditionalFormatting = [CfRule]

topCfPriority :: Int
topCfPriority :: Int
topCfPriority = Int
1

{-------------------------------------------------------------------------------
  Parsing
-------------------------------------------------------------------------------}

instance FromCursor CfRule where
    fromCursor :: Cursor -> [CfRule]
fromCursor Cursor
cur = do
        Maybe Int
_cfrDxfId      <- Name -> Cursor -> [Maybe Int]
forall a. FromAttrVal a => Name -> Cursor -> [Maybe a]
maybeAttribute Name
"dxfId" Cursor
cur
        Int
_cfrPriority   <- Name -> Cursor -> [Int]
forall a. FromAttrVal a => Name -> Cursor -> [a]
fromAttribute Name
"priority" Cursor
cur
        Maybe Bool
_cfrStopIfTrue <- Name -> Cursor -> [Maybe Bool]
forall a. FromAttrVal a => Name -> Cursor -> [Maybe a]
maybeAttribute Name
"stopIfTrue" Cursor
cur
        -- spec shows this attribute as optional but it's not clear why could
        -- conditional formatting record be needed with no condition type set
        Text
cfType <- Name -> Cursor -> [Text]
forall a. FromAttrVal a => Name -> Cursor -> [a]
fromAttribute Name
"type" Cursor
cur
        Condition
_cfrCondition <- Text -> Cursor -> [Condition]
readCondition Text
cfType Cursor
cur
        CfRule -> [CfRule]
forall (m :: * -> *) a. Monad m => a -> m a
return CfRule :: Condition -> Maybe Int -> Int -> Maybe Bool -> CfRule
CfRule{Int
Maybe Bool
Maybe Int
Condition
_cfrCondition :: Condition
_cfrStopIfTrue :: Maybe Bool
_cfrPriority :: Int
_cfrDxfId :: Maybe Int
_cfrStopIfTrue :: Maybe Bool
_cfrPriority :: Int
_cfrDxfId :: Maybe Int
_cfrCondition :: Condition
..}

readCondition :: Text -> Cursor -> [Condition]
readCondition :: Text -> Cursor -> [Condition]
readCondition Text
"aboveAverage" Cursor
cur       = do
  Bool
above <- Name -> Bool -> Cursor -> [Bool]
forall a. FromAttrVal a => Name -> a -> Cursor -> [a]
fromAttributeDef Name
"aboveAverage" Bool
True Cursor
cur
  Inclusion
inclusion <- Name -> Inclusion -> Cursor -> [Inclusion]
forall a. FromAttrVal a => Name -> a -> Cursor -> [a]
fromAttributeDef Name
"equalAverage" Inclusion
Exclusive Cursor
cur
  Maybe NStdDev
nStdDev <- Name -> Cursor -> [Maybe NStdDev]
forall a. FromAttrVal a => Name -> Cursor -> [Maybe a]
maybeAttribute Name
"stdDev" Cursor
cur
  if Bool
above
    then Condition -> [Condition]
forall (m :: * -> *) a. Monad m => a -> m a
return (Condition -> [Condition]) -> Condition -> [Condition]
forall a b. (a -> b) -> a -> b
$ Inclusion -> Maybe NStdDev -> Condition
AboveAverage Inclusion
inclusion Maybe NStdDev
nStdDev
    else Condition -> [Condition]
forall (m :: * -> *) a. Monad m => a -> m a
return (Condition -> [Condition]) -> Condition -> [Condition]
forall a b. (a -> b) -> a -> b
$ Inclusion -> Maybe NStdDev -> Condition
BelowAverage Inclusion
inclusion Maybe NStdDev
nStdDev
readCondition Text
"beginsWith" Cursor
cur = do
  Text
txt <- Name -> Cursor -> [Text]
forall a. FromAttrVal a => Name -> Cursor -> [a]
fromAttribute Name
"text" Cursor
cur
  Condition -> [Condition]
forall (m :: * -> *) a. Monad m => a -> m a
return (Condition -> [Condition]) -> Condition -> [Condition]
forall a b. (a -> b) -> a -> b
$ Text -> Condition
BeginsWith Text
txt
readCondition Text
"colorScale" Cursor
cur = do
  let cfvos :: [Node]
cfvos = Cursor
cur Cursor -> (Cursor -> [Node]) -> [Node]
forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$/ Name -> Axis
element (Text -> Name
n_ Text
"colorScale") Axis -> (Cursor -> [Node]) -> Cursor -> [Node]
forall node a.
Axis node -> (Cursor node -> [a]) -> Cursor node -> [a]
&/ Name -> Axis
element (Text -> Name
n_ Text
"cfvo") Axis -> (Cursor -> Node) -> Cursor -> [Node]
forall node a b.
(Cursor node -> [a]) -> (a -> b) -> Cursor node -> [b]
&| Cursor -> Node
forall node. Cursor node -> node
node
      colors :: [Node]
colors = Cursor
cur Cursor -> (Cursor -> [Node]) -> [Node]
forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$/ Name -> Axis
element (Text -> Name
n_ Text
"colorScale") Axis -> (Cursor -> [Node]) -> Cursor -> [Node]
forall node a.
Axis node -> (Cursor node -> [a]) -> Cursor node -> [a]
&/ Name -> Axis
element (Text -> Name
n_ Text
"color") Axis -> (Cursor -> Node) -> Cursor -> [Node]
forall node a b.
(Cursor node -> [a]) -> (a -> b) -> Cursor node -> [b]
&| Cursor -> Node
forall node. Cursor node -> node
node
  case ([Node]
cfvos, [Node]
colors) of
    ([Node
n1, Node
n2], [Node
cn1, Node
cn2]) -> do
      MinCfValue
mincfv <- Cursor -> [MinCfValue]
forall a. FromCursor a => Cursor -> [a]
fromCursor (Cursor -> [MinCfValue]) -> Cursor -> [MinCfValue]
forall a b. (a -> b) -> a -> b
$ Node -> Cursor
fromNode Node
n1
      Color
minc <- Cursor -> [Color]
forall a. FromCursor a => Cursor -> [a]
fromCursor (Cursor -> [Color]) -> Cursor -> [Color]
forall a b. (a -> b) -> a -> b
$ Node -> Cursor
fromNode Node
cn1
      MaxCfValue
maxcfv <- Cursor -> [MaxCfValue]
forall a. FromCursor a => Cursor -> [a]
fromCursor (Cursor -> [MaxCfValue]) -> Cursor -> [MaxCfValue]
forall a b. (a -> b) -> a -> b
$ Node -> Cursor
fromNode Node
n2
      Color
maxc <- Cursor -> [Color]
forall a. FromCursor a => Cursor -> [a]
fromCursor (Cursor -> [Color]) -> Cursor -> [Color]
forall a b. (a -> b) -> a -> b
$ Node -> Cursor
fromNode Node
cn2
      Condition -> [Condition]
forall (m :: * -> *) a. Monad m => a -> m a
return (Condition -> [Condition]) -> Condition -> [Condition]
forall a b. (a -> b) -> a -> b
$ MinCfValue -> Color -> MaxCfValue -> Color -> Condition
ColorScale2 MinCfValue
mincfv Color
minc MaxCfValue
maxcfv Color
maxc
    ([Node
n1, Node
n2, Node
n3], [Node
cn1, Node
cn2, Node
cn3]) -> do
      MinCfValue
mincfv <- Cursor -> [MinCfValue]
forall a. FromCursor a => Cursor -> [a]
fromCursor (Cursor -> [MinCfValue]) -> Cursor -> [MinCfValue]
forall a b. (a -> b) -> a -> b
$ Node -> Cursor
fromNode Node
n1
      Color
minc <- Cursor -> [Color]
forall a. FromCursor a => Cursor -> [a]
fromCursor (Cursor -> [Color]) -> Cursor -> [Color]
forall a b. (a -> b) -> a -> b
$ Node -> Cursor
fromNode Node
cn1
      CfValue
midcfv <- Cursor -> [CfValue]
forall a. FromCursor a => Cursor -> [a]
fromCursor (Cursor -> [CfValue]) -> Cursor -> [CfValue]
forall a b. (a -> b) -> a -> b
$ Node -> Cursor
fromNode Node
n2
      Color
midc <- Cursor -> [Color]
forall a. FromCursor a => Cursor -> [a]
fromCursor (Cursor -> [Color]) -> Cursor -> [Color]
forall a b. (a -> b) -> a -> b
$ Node -> Cursor
fromNode Node
cn2
      MaxCfValue
maxcfv <- Cursor -> [MaxCfValue]
forall a. FromCursor a => Cursor -> [a]
fromCursor (Cursor -> [MaxCfValue]) -> Cursor -> [MaxCfValue]
forall a b. (a -> b) -> a -> b
$ Node -> Cursor
fromNode Node
n3
      Color
maxc <- Cursor -> [Color]
forall a. FromCursor a => Cursor -> [a]
fromCursor (Cursor -> [Color]) -> Cursor -> [Color]
forall a b. (a -> b) -> a -> b
$ Node -> Cursor
fromNode Node
cn3
      Condition -> [Condition]
forall (m :: * -> *) a. Monad m => a -> m a
return (Condition -> [Condition]) -> Condition -> [Condition]
forall a b. (a -> b) -> a -> b
$ MinCfValue
-> Color -> CfValue -> Color -> MaxCfValue -> Color -> Condition
ColorScale3 MinCfValue
mincfv Color
minc CfValue
midcfv Color
midc MaxCfValue
maxcfv Color
maxc
    ([Node], [Node])
_ ->
      String -> [Condition]
forall a. HasCallStack => String -> a
error String
"Malformed colorScale condition"
readCondition Text
"cellIs" Cursor
cur           = do
    Text
operator <- Name -> Cursor -> [Text]
forall a. FromAttrVal a => Name -> Cursor -> [a]
fromAttribute Name
"operator" Cursor
cur
    let formulas :: [Formula]
formulas = Cursor
cur Cursor -> (Cursor -> [Formula]) -> [Formula]
forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$/ Name -> Axis
element (Text -> Name
n_ Text
"formula") Axis -> (Cursor -> [Formula]) -> Cursor -> [Formula]
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> Cursor -> [Formula]
forall a. FromCursor a => Cursor -> [a]
fromCursor
    OperatorExpression
expr <- Text -> [Formula] -> [OperatorExpression]
readOpExpression Text
operator [Formula]
formulas
    Condition -> [Condition]
forall (m :: * -> *) a. Monad m => a -> m a
return (Condition -> [Condition]) -> Condition -> [Condition]
forall a b. (a -> b) -> a -> b
$ OperatorExpression -> Condition
CellIs OperatorExpression
expr
readCondition Text
"containsBlanks" Cursor
_     = Condition -> [Condition]
forall (m :: * -> *) a. Monad m => a -> m a
return Condition
ContainsBlanks
readCondition Text
"containsErrors" Cursor
_     = Condition -> [Condition]
forall (m :: * -> *) a. Monad m => a -> m a
return Condition
ContainsErrors
readCondition Text
"containsText" Cursor
cur     = do
    Text
txt <- Name -> Cursor -> [Text]
forall a. FromAttrVal a => Name -> Cursor -> [a]
fromAttribute Name
"text" Cursor
cur
    Condition -> [Condition]
forall (m :: * -> *) a. Monad m => a -> m a
return (Condition -> [Condition]) -> Condition -> [Condition]
forall a b. (a -> b) -> a -> b
$ Text -> Condition
ContainsText Text
txt
readCondition Text
"dataBar" Cursor
cur = (DataBarOptions -> Condition) -> [DataBarOptions] -> [Condition]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap DataBarOptions -> Condition
DataBar ([DataBarOptions] -> [Condition])
-> [DataBarOptions] -> [Condition]
forall a b. (a -> b) -> a -> b
$ Cursor
cur Cursor -> (Cursor -> [DataBarOptions]) -> [DataBarOptions]
forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$/ Name -> Axis
element (Text -> Name
n_ Text
"dataBar") Axis -> (Cursor -> [DataBarOptions]) -> Cursor -> [DataBarOptions]
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> Cursor -> [DataBarOptions]
forall a. FromCursor a => Cursor -> [a]
fromCursor
readCondition Text
"duplicateValues" Cursor
_    = Condition -> [Condition]
forall (m :: * -> *) a. Monad m => a -> m a
return Condition
DuplicateValues
readCondition Text
"endsWith" Cursor
cur         = do
    Text
txt <- Name -> Cursor -> [Text]
forall a. FromAttrVal a => Name -> Cursor -> [a]
fromAttribute Name
"text" Cursor
cur
    Condition -> [Condition]
forall (m :: * -> *) a. Monad m => a -> m a
return (Condition -> [Condition]) -> Condition -> [Condition]
forall a b. (a -> b) -> a -> b
$ Text -> Condition
EndsWith Text
txt
readCondition Text
"expression" Cursor
cur       = do
    Formula
formula <- Cursor
cur Cursor -> (Cursor -> [Formula]) -> [Formula]
forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$/ Name -> Axis
element (Text -> Name
n_ Text
"formula") Axis -> (Cursor -> [Formula]) -> Cursor -> [Formula]
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> Cursor -> [Formula]
forall a. FromCursor a => Cursor -> [a]
fromCursor
    Condition -> [Condition]
forall (m :: * -> *) a. Monad m => a -> m a
return (Condition -> [Condition]) -> Condition -> [Condition]
forall a b. (a -> b) -> a -> b
$ Formula -> Condition
Expression Formula
formula
readCondition Text
"iconSet" Cursor
cur = (IconSetOptions -> Condition) -> [IconSetOptions] -> [Condition]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap IconSetOptions -> Condition
IconSet ([IconSetOptions] -> [Condition])
-> [IconSetOptions] -> [Condition]
forall a b. (a -> b) -> a -> b
$ Cursor
cur Cursor -> (Cursor -> [IconSetOptions]) -> [IconSetOptions]
forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$/ Name -> Axis
element (Text -> Name
n_ Text
"iconSet") Axis -> (Cursor -> [IconSetOptions]) -> Cursor -> [IconSetOptions]
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> Cursor -> [IconSetOptions]
forall a. FromCursor a => Cursor -> [a]
fromCursor
readCondition Text
"notContainsBlanks" Cursor
_  = Condition -> [Condition]
forall (m :: * -> *) a. Monad m => a -> m a
return Condition
DoesNotContainBlanks
readCondition Text
"notContainsErrors" Cursor
_  = Condition -> [Condition]
forall (m :: * -> *) a. Monad m => a -> m a
return Condition
DoesNotContainErrors
readCondition Text
"notContainsText" Cursor
cur  = do
    Text
txt <- Name -> Cursor -> [Text]
forall a. FromAttrVal a => Name -> Cursor -> [a]
fromAttribute Name
"text" Cursor
cur
    Condition -> [Condition]
forall (m :: * -> *) a. Monad m => a -> m a
return (Condition -> [Condition]) -> Condition -> [Condition]
forall a b. (a -> b) -> a -> b
$ Text -> Condition
DoesNotContainText Text
txt
readCondition Text
"timePeriod" Cursor
cur  = do
    TimePeriod
period <- Name -> Cursor -> [TimePeriod]
forall a. FromAttrVal a => Name -> Cursor -> [a]
fromAttribute Name
"timePeriod" Cursor
cur
    Condition -> [Condition]
forall (m :: * -> *) a. Monad m => a -> m a
return (Condition -> [Condition]) -> Condition -> [Condition]
forall a b. (a -> b) -> a -> b
$ TimePeriod -> Condition
InTimePeriod TimePeriod
period
readCondition Text
"top10" Cursor
cur = do
  Bool
bottom <- Name -> Bool -> Cursor -> [Bool]
forall a. FromAttrVal a => Name -> a -> Cursor -> [a]
fromAttributeDef Name
"bottom" Bool
False Cursor
cur
  Bool
percent <- Name -> Bool -> Cursor -> [Bool]
forall a. FromAttrVal a => Name -> a -> Cursor -> [a]
fromAttributeDef Name
"percent" Bool
False Cursor
cur
  Int
rank <- Name -> Cursor -> [Int]
forall a. FromAttrVal a => Name -> Cursor -> [a]
fromAttribute Name
"rank" Cursor
cur
  case (Bool
bottom, Bool
percent) of
    (Bool
True, Bool
True) -> Condition -> [Condition]
forall (m :: * -> *) a. Monad m => a -> m a
return (Condition -> [Condition]) -> Condition -> [Condition]
forall a b. (a -> b) -> a -> b
$ Int -> Condition
BottomNPercent Int
rank
    (Bool
True, Bool
False) -> Condition -> [Condition]
forall (m :: * -> *) a. Monad m => a -> m a
return (Condition -> [Condition]) -> Condition -> [Condition]
forall a b. (a -> b) -> a -> b
$ Int -> Condition
BottomNValues Int
rank
    (Bool
False, Bool
True) -> Condition -> [Condition]
forall (m :: * -> *) a. Monad m => a -> m a
return (Condition -> [Condition]) -> Condition -> [Condition]
forall a b. (a -> b) -> a -> b
$ Int -> Condition
TopNPercent Int
rank
    (Bool
False, Bool
False) -> Condition -> [Condition]
forall (m :: * -> *) a. Monad m => a -> m a
return (Condition -> [Condition]) -> Condition -> [Condition]
forall a b. (a -> b) -> a -> b
$ Int -> Condition
TopNValues Int
rank
readCondition Text
"uniqueValues" Cursor
_       = Condition -> [Condition]
forall (m :: * -> *) a. Monad m => a -> m a
return Condition
UniqueValues
readCondition Text
t Cursor
_                    = String -> [Condition]
forall a. HasCallStack => String -> a
error (String -> [Condition]) -> String -> [Condition]
forall a b. (a -> b) -> a -> b
$ String
"Unexpected conditional formatting type " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Text -> String
forall a. Show a => a -> String
show Text
t

readOpExpression :: Text -> [Formula] -> [OperatorExpression]
readOpExpression :: Text -> [Formula] -> [OperatorExpression]
readOpExpression Text
"beginsWith" [Formula
f]         = [Formula -> OperatorExpression
OpBeginsWith Formula
f ]
readOpExpression Text
"between" [Formula
f1, Formula
f2]       = [Formula -> Formula -> OperatorExpression
OpBetween Formula
f1 Formula
f2]
readOpExpression Text
"containsText" [Formula
f]       = [Formula -> OperatorExpression
OpContainsText Formula
f]
readOpExpression Text
"endsWith" [Formula
f]           = [Formula -> OperatorExpression
OpEndsWith Formula
f]
readOpExpression Text
"equal" [Formula
f]              = [Formula -> OperatorExpression
OpEqual Formula
f]
readOpExpression Text
"greaterThan" [Formula
f]        = [Formula -> OperatorExpression
OpGreaterThan Formula
f]
readOpExpression Text
"greaterThanOrEqual" [Formula
f] = [Formula -> OperatorExpression
OpGreaterThanOrEqual Formula
f]
readOpExpression Text
"lessThan" [Formula
f]           = [Formula -> OperatorExpression
OpLessThan Formula
f]
readOpExpression Text
"lessThanOrEqual" [Formula
f]    = [Formula -> OperatorExpression
OpLessThanOrEqual Formula
f]
readOpExpression Text
"notBetween" [Formula
f1, Formula
f2]    = [Formula -> Formula -> OperatorExpression
OpNotBetween Formula
f1 Formula
f2]
readOpExpression Text
"notContains" [Formula
f]        = [Formula -> OperatorExpression
OpNotContains Formula
f]
readOpExpression Text
"notEqual" [Formula
f]           = [Formula -> OperatorExpression
OpNotEqual Formula
f]
readOpExpression Text
_ [Formula]
_                      = []

instance FromXenoNode CfRule where
  fromXenoNode :: Node -> Either Text CfRule
fromXenoNode Node
root = Node -> AttrParser CfRule -> Either Text CfRule
forall a. Node -> AttrParser a -> Either Text a
parseAttributes Node
root (AttrParser CfRule -> Either Text CfRule)
-> AttrParser CfRule -> Either Text CfRule
forall a b. (a -> b) -> a -> b
$ do
        Maybe Int
_cfrDxfId <- ByteString -> AttrParser (Maybe Int)
forall a. FromAttrBs a => ByteString -> AttrParser (Maybe a)
maybeAttr ByteString
"dxfId"
        Int
_cfrPriority <- ByteString -> AttrParser Int
forall a. FromAttrBs a => ByteString -> AttrParser a
fromAttr ByteString
"priority"
        Maybe Bool
_cfrStopIfTrue <- ByteString -> AttrParser (Maybe Bool)
forall a. FromAttrBs a => ByteString -> AttrParser (Maybe a)
maybeAttr ByteString
"stopIfTrue"
        -- spec shows this attribute as optional but it's not clear why could
        -- conditional formatting record be needed with no condition type set
        ByteString
cfType <- ByteString -> AttrParser ByteString
forall a. FromAttrBs a => ByteString -> AttrParser a
fromAttr ByteString
"type"
        Condition
_cfrCondition <- ByteString -> AttrParser Condition
readConditionX ByteString
cfType
        CfRule -> AttrParser CfRule
forall (m :: * -> *) a. Monad m => a -> m a
return CfRule :: Condition -> Maybe Int -> Int -> Maybe Bool -> CfRule
CfRule {Int
Maybe Bool
Maybe Int
Condition
_cfrCondition :: Condition
_cfrStopIfTrue :: Maybe Bool
_cfrPriority :: Int
_cfrDxfId :: Maybe Int
_cfrStopIfTrue :: Maybe Bool
_cfrPriority :: Int
_cfrDxfId :: Maybe Int
_cfrCondition :: Condition
..}
    where
      readConditionX :: ByteString -> AttrParser Condition
readConditionX (ByteString
"aboveAverage" :: ByteString) = do
        Bool
above <- ByteString -> Bool -> AttrParser Bool
forall a. FromAttrBs a => ByteString -> a -> AttrParser a
fromAttrDef ByteString
"aboveAverage" Bool
True
        Inclusion
inclusion <- ByteString -> Inclusion -> AttrParser Inclusion
forall a. FromAttrBs a => ByteString -> a -> AttrParser a
fromAttrDef ByteString
"equalAverage" Inclusion
Exclusive
        Maybe NStdDev
nStdDev <- ByteString -> AttrParser (Maybe NStdDev)
forall a. FromAttrBs a => ByteString -> AttrParser (Maybe a)
maybeAttr ByteString
"stdDev"
        if Bool
above
          then Condition -> AttrParser Condition
forall (m :: * -> *) a. Monad m => a -> m a
return (Condition -> AttrParser Condition)
-> Condition -> AttrParser Condition
forall a b. (a -> b) -> a -> b
$ Inclusion -> Maybe NStdDev -> Condition
AboveAverage Inclusion
inclusion Maybe NStdDev
nStdDev
          else Condition -> AttrParser Condition
forall (m :: * -> *) a. Monad m => a -> m a
return (Condition -> AttrParser Condition)
-> Condition -> AttrParser Condition
forall a b. (a -> b) -> a -> b
$ Inclusion -> Maybe NStdDev -> Condition
BelowAverage Inclusion
inclusion Maybe NStdDev
nStdDev
      readConditionX ByteString
"beginsWith" = Text -> Condition
BeginsWith (Text -> Condition) -> AttrParser Text -> AttrParser Condition
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ByteString -> AttrParser Text
forall a. FromAttrBs a => ByteString -> AttrParser a
fromAttr ByteString
"text"
      readConditionX ByteString
"colorScale" = Either Text Condition -> AttrParser Condition
forall a. Either Text a -> AttrParser a
toAttrParser (Either Text Condition -> AttrParser Condition)
-> Either Text Condition -> AttrParser Condition
forall a b. (a -> b) -> a -> b
$ do
        Maybe ([Node], [Node])
xs <- Node
-> ChildCollector (Maybe ([Node], [Node]))
-> Either Text (Maybe ([Node], [Node]))
forall a. Node -> ChildCollector a -> Either Text a
collectChildren Node
root (ChildCollector (Maybe ([Node], [Node]))
 -> Either Text (Maybe ([Node], [Node])))
-> ((Node -> Either Text ([Node], [Node]))
    -> ChildCollector (Maybe ([Node], [Node])))
-> (Node -> Either Text ([Node], [Node]))
-> Either Text (Maybe ([Node], [Node]))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString
-> (Node -> Either Text ([Node], [Node]))
-> ChildCollector (Maybe ([Node], [Node]))
forall a.
ByteString -> (Node -> Either Text a) -> ChildCollector (Maybe a)
maybeParse ByteString
"colorScale" ((Node -> Either Text ([Node], [Node]))
 -> Either Text (Maybe ([Node], [Node])))
-> (Node -> Either Text ([Node], [Node]))
-> Either Text (Maybe ([Node], [Node]))
forall a b. (a -> b) -> a -> b
$ \Node
node ->
          Node
-> ChildCollector ([Node], [Node]) -> Either Text ([Node], [Node])
forall a. Node -> ChildCollector a -> Either Text a
collectChildren Node
node (ChildCollector ([Node], [Node]) -> Either Text ([Node], [Node]))
-> ChildCollector ([Node], [Node]) -> Either Text ([Node], [Node])
forall a b. (a -> b) -> a -> b
$ (,) ([Node] -> [Node] -> ([Node], [Node]))
-> ChildCollector [Node]
-> ChildCollector ([Node] -> ([Node], [Node]))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ByteString -> ChildCollector [Node]
childList ByteString
"cfvo"
                                     ChildCollector ([Node] -> ([Node], [Node]))
-> ChildCollector [Node] -> ChildCollector ([Node], [Node])
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ByteString -> ChildCollector [Node]
childList ByteString
"color"
        case Maybe ([Node], [Node])
xs of
          Just ([Node
n1, Node
n2], [Node
cn1, Node
cn2]) -> do
            MinCfValue
mincfv <- Node -> Either Text MinCfValue
forall a. FromXenoNode a => Node -> Either Text a
fromXenoNode Node
n1
            Color
minc <- Node -> Either Text Color
forall a. FromXenoNode a => Node -> Either Text a
fromXenoNode Node
cn1
            MaxCfValue
maxcfv <- Node -> Either Text MaxCfValue
forall a. FromXenoNode a => Node -> Either Text a
fromXenoNode Node
n2
            Color
maxc <- Node -> Either Text Color
forall a. FromXenoNode a => Node -> Either Text a
fromXenoNode Node
cn2
            Condition -> Either Text Condition
forall (m :: * -> *) a. Monad m => a -> m a
return (Condition -> Either Text Condition)
-> Condition -> Either Text Condition
forall a b. (a -> b) -> a -> b
$ MinCfValue -> Color -> MaxCfValue -> Color -> Condition
ColorScale2 MinCfValue
mincfv Color
minc MaxCfValue
maxcfv Color
maxc
          Just ([Node
n1, Node
n2, Node
n3], [Node
cn1, Node
cn2, Node
cn3]) -> do
            MinCfValue
mincfv <- Node -> Either Text MinCfValue
forall a. FromXenoNode a => Node -> Either Text a
fromXenoNode Node
n1
            Color
minc <- Node -> Either Text Color
forall a. FromXenoNode a => Node -> Either Text a
fromXenoNode Node
cn1
            CfValue
midcfv <- Node -> Either Text CfValue
forall a. FromXenoNode a => Node -> Either Text a
fromXenoNode Node
n2
            Color
midc <- Node -> Either Text Color
forall a. FromXenoNode a => Node -> Either Text a
fromXenoNode Node
cn2
            MaxCfValue
maxcfv <- Node -> Either Text MaxCfValue
forall a. FromXenoNode a => Node -> Either Text a
fromXenoNode Node
n3
            Color
maxc <- Node -> Either Text Color
forall a. FromXenoNode a => Node -> Either Text a
fromXenoNode Node
cn3
            Condition -> Either Text Condition
forall (m :: * -> *) a. Monad m => a -> m a
return (Condition -> Either Text Condition)
-> Condition -> Either Text Condition
forall a b. (a -> b) -> a -> b
$ MinCfValue
-> Color -> CfValue -> Color -> MaxCfValue -> Color -> Condition
ColorScale3 MinCfValue
mincfv Color
minc CfValue
midcfv Color
midc MaxCfValue
maxcfv Color
maxc
          Maybe ([Node], [Node])
_ ->
            Text -> Either Text Condition
forall a b. a -> Either a b
Left Text
"Malformed colorScale condition"
      readConditionX ByteString
"cellIs" = do
        ByteString
operator <- ByteString -> AttrParser ByteString
forall a. FromAttrBs a => ByteString -> AttrParser a
fromAttr ByteString
"operator"
        [Formula]
formulas <- Either Text [Formula] -> AttrParser [Formula]
forall a. Either Text a -> AttrParser a
toAttrParser (Either Text [Formula] -> AttrParser [Formula])
-> (ChildCollector [Formula] -> Either Text [Formula])
-> ChildCollector [Formula]
-> AttrParser [Formula]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Node -> ChildCollector [Formula] -> Either Text [Formula]
forall a. Node -> ChildCollector a -> Either Text a
collectChildren Node
root (ChildCollector [Formula] -> AttrParser [Formula])
-> ChildCollector [Formula] -> AttrParser [Formula]
forall a b. (a -> b) -> a -> b
$ ByteString -> ChildCollector [Formula]
forall a. FromXenoNode a => ByteString -> ChildCollector [a]
fromChildList ByteString
"formula"
        case (ByteString
operator, [Formula]
formulas) of
          (ByteString
"beginsWith" :: ByteString, [Formula
f]) -> Condition -> AttrParser Condition
forall (m :: * -> *) a. Monad m => a -> m a
return (Condition -> AttrParser Condition)
-> (OperatorExpression -> Condition)
-> OperatorExpression
-> AttrParser Condition
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OperatorExpression -> Condition
CellIs (OperatorExpression -> AttrParser Condition)
-> OperatorExpression -> AttrParser Condition
forall a b. (a -> b) -> a -> b
$ Formula -> OperatorExpression
OpBeginsWith Formula
f
          (ByteString
"between", [Formula
f1, Formula
f2]) -> Condition -> AttrParser Condition
forall (m :: * -> *) a. Monad m => a -> m a
return (Condition -> AttrParser Condition)
-> (OperatorExpression -> Condition)
-> OperatorExpression
-> AttrParser Condition
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OperatorExpression -> Condition
CellIs (OperatorExpression -> AttrParser Condition)
-> OperatorExpression -> AttrParser Condition
forall a b. (a -> b) -> a -> b
$ Formula -> Formula -> OperatorExpression
OpBetween Formula
f1 Formula
f2
          (ByteString
"containsText", [Formula
f]) -> Condition -> AttrParser Condition
forall (m :: * -> *) a. Monad m => a -> m a
return (Condition -> AttrParser Condition)
-> (OperatorExpression -> Condition)
-> OperatorExpression
-> AttrParser Condition
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OperatorExpression -> Condition
CellIs (OperatorExpression -> AttrParser Condition)
-> OperatorExpression -> AttrParser Condition
forall a b. (a -> b) -> a -> b
$ Formula -> OperatorExpression
OpContainsText Formula
f
          (ByteString
"endsWith", [Formula
f]) -> Condition -> AttrParser Condition
forall (m :: * -> *) a. Monad m => a -> m a
return (Condition -> AttrParser Condition)
-> (OperatorExpression -> Condition)
-> OperatorExpression
-> AttrParser Condition
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OperatorExpression -> Condition
CellIs (OperatorExpression -> AttrParser Condition)
-> OperatorExpression -> AttrParser Condition
forall a b. (a -> b) -> a -> b
$ Formula -> OperatorExpression
OpEndsWith Formula
f
          (ByteString
"equal", [Formula
f]) -> Condition -> AttrParser Condition
forall (m :: * -> *) a. Monad m => a -> m a
return (Condition -> AttrParser Condition)
-> (OperatorExpression -> Condition)
-> OperatorExpression
-> AttrParser Condition
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OperatorExpression -> Condition
CellIs (OperatorExpression -> AttrParser Condition)
-> OperatorExpression -> AttrParser Condition
forall a b. (a -> b) -> a -> b
$ Formula -> OperatorExpression
OpEqual Formula
f
          (ByteString
"greaterThan", [Formula
f]) -> Condition -> AttrParser Condition
forall (m :: * -> *) a. Monad m => a -> m a
return (Condition -> AttrParser Condition)
-> (OperatorExpression -> Condition)
-> OperatorExpression
-> AttrParser Condition
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OperatorExpression -> Condition
CellIs (OperatorExpression -> AttrParser Condition)
-> OperatorExpression -> AttrParser Condition
forall a b. (a -> b) -> a -> b
$ Formula -> OperatorExpression
OpGreaterThan Formula
f
          (ByteString
"greaterThanOrEqual", [Formula
f]) -> Condition -> AttrParser Condition
forall (m :: * -> *) a. Monad m => a -> m a
return (Condition -> AttrParser Condition)
-> (OperatorExpression -> Condition)
-> OperatorExpression
-> AttrParser Condition
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OperatorExpression -> Condition
CellIs (OperatorExpression -> AttrParser Condition)
-> OperatorExpression -> AttrParser Condition
forall a b. (a -> b) -> a -> b
$ Formula -> OperatorExpression
OpGreaterThanOrEqual Formula
f
          (ByteString
"lessThan", [Formula
f]) -> Condition -> AttrParser Condition
forall (m :: * -> *) a. Monad m => a -> m a
return (Condition -> AttrParser Condition)
-> (OperatorExpression -> Condition)
-> OperatorExpression
-> AttrParser Condition
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OperatorExpression -> Condition
CellIs (OperatorExpression -> AttrParser Condition)
-> OperatorExpression -> AttrParser Condition
forall a b. (a -> b) -> a -> b
$ Formula -> OperatorExpression
OpLessThan Formula
f
          (ByteString
"lessThanOrEqual", [Formula
f]) -> Condition -> AttrParser Condition
forall (m :: * -> *) a. Monad m => a -> m a
return (Condition -> AttrParser Condition)
-> (OperatorExpression -> Condition)
-> OperatorExpression
-> AttrParser Condition
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OperatorExpression -> Condition
CellIs (OperatorExpression -> AttrParser Condition)
-> OperatorExpression -> AttrParser Condition
forall a b. (a -> b) -> a -> b
$ Formula -> OperatorExpression
OpLessThanOrEqual Formula
f
          (ByteString
"notBetween", [Formula
f1, Formula
f2]) -> Condition -> AttrParser Condition
forall (m :: * -> *) a. Monad m => a -> m a
return (Condition -> AttrParser Condition)
-> (OperatorExpression -> Condition)
-> OperatorExpression
-> AttrParser Condition
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OperatorExpression -> Condition
CellIs (OperatorExpression -> AttrParser Condition)
-> OperatorExpression -> AttrParser Condition
forall a b. (a -> b) -> a -> b
$ Formula -> Formula -> OperatorExpression
OpNotBetween Formula
f1 Formula
f2
          (ByteString
"notContains", [Formula
f]) -> Condition -> AttrParser Condition
forall (m :: * -> *) a. Monad m => a -> m a
return (Condition -> AttrParser Condition)
-> (OperatorExpression -> Condition)
-> OperatorExpression
-> AttrParser Condition
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OperatorExpression -> Condition
CellIs (OperatorExpression -> AttrParser Condition)
-> OperatorExpression -> AttrParser Condition
forall a b. (a -> b) -> a -> b
$ Formula -> OperatorExpression
OpNotContains Formula
f
          (ByteString
"notEqual", [Formula
f]) -> Condition -> AttrParser Condition
forall (m :: * -> *) a. Monad m => a -> m a
return (Condition -> AttrParser Condition)
-> (OperatorExpression -> Condition)
-> OperatorExpression
-> AttrParser Condition
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OperatorExpression -> Condition
CellIs (OperatorExpression -> AttrParser Condition)
-> OperatorExpression -> AttrParser Condition
forall a b. (a -> b) -> a -> b
$ Formula -> OperatorExpression
OpNotEqual Formula
f
          (ByteString, [Formula])
_ -> Either Text Condition -> AttrParser Condition
forall a. Either Text a -> AttrParser a
toAttrParser (Either Text Condition -> AttrParser Condition)
-> Either Text Condition -> AttrParser Condition
forall a b. (a -> b) -> a -> b
$ Text -> Either Text Condition
forall a b. a -> Either a b
Left Text
"Bad cellIs rule"
      readConditionX ByteString
"containsBlanks" = Condition -> AttrParser Condition
forall (m :: * -> *) a. Monad m => a -> m a
return Condition
ContainsBlanks
      readConditionX ByteString
"containsErrors" = Condition -> AttrParser Condition
forall (m :: * -> *) a. Monad m => a -> m a
return Condition
ContainsErrors
      readConditionX ByteString
"containsText" = Text -> Condition
ContainsText (Text -> Condition) -> AttrParser Text -> AttrParser Condition
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ByteString -> AttrParser Text
forall a. FromAttrBs a => ByteString -> AttrParser a
fromAttr ByteString
"text"
      readConditionX ByteString
"dataBar" =
        (DataBarOptions -> Condition)
-> AttrParser DataBarOptions -> AttrParser Condition
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap DataBarOptions -> Condition
DataBar (AttrParser DataBarOptions -> AttrParser Condition)
-> (ChildCollector DataBarOptions -> AttrParser DataBarOptions)
-> ChildCollector DataBarOptions
-> AttrParser Condition
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Either Text DataBarOptions -> AttrParser DataBarOptions
forall a. Either Text a -> AttrParser a
toAttrParser (Either Text DataBarOptions -> AttrParser DataBarOptions)
-> (ChildCollector DataBarOptions -> Either Text DataBarOptions)
-> ChildCollector DataBarOptions
-> AttrParser DataBarOptions
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Node -> ChildCollector DataBarOptions -> Either Text DataBarOptions
forall a. Node -> ChildCollector a -> Either Text a
collectChildren Node
root (ChildCollector DataBarOptions -> AttrParser Condition)
-> ChildCollector DataBarOptions -> AttrParser Condition
forall a b. (a -> b) -> a -> b
$ ByteString -> ChildCollector DataBarOptions
forall a. FromXenoNode a => ByteString -> ChildCollector a
fromChild ByteString
"dataBar"
      readConditionX ByteString
"duplicateValues" = Condition -> AttrParser Condition
forall (m :: * -> *) a. Monad m => a -> m a
return Condition
DuplicateValues
      readConditionX ByteString
"endsWith" = Text -> Condition
EndsWith (Text -> Condition) -> AttrParser Text -> AttrParser Condition
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ByteString -> AttrParser Text
forall a. FromAttrBs a => ByteString -> AttrParser a
fromAttr ByteString
"text"
      readConditionX ByteString
"expression" =
        (Formula -> Condition)
-> AttrParser Formula -> AttrParser Condition
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Formula -> Condition
Expression (AttrParser Formula -> AttrParser Condition)
-> (ChildCollector Formula -> AttrParser Formula)
-> ChildCollector Formula
-> AttrParser Condition
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Either Text Formula -> AttrParser Formula
forall a. Either Text a -> AttrParser a
toAttrParser (Either Text Formula -> AttrParser Formula)
-> (ChildCollector Formula -> Either Text Formula)
-> ChildCollector Formula
-> AttrParser Formula
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Node -> ChildCollector Formula -> Either Text Formula
forall a. Node -> ChildCollector a -> Either Text a
collectChildren Node
root (ChildCollector Formula -> AttrParser Condition)
-> ChildCollector Formula -> AttrParser Condition
forall a b. (a -> b) -> a -> b
$ ByteString -> ChildCollector Formula
forall a. FromXenoNode a => ByteString -> ChildCollector a
fromChild ByteString
"formula"
      readConditionX ByteString
"iconSet" =
        (IconSetOptions -> Condition)
-> AttrParser IconSetOptions -> AttrParser Condition
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap IconSetOptions -> Condition
IconSet (AttrParser IconSetOptions -> AttrParser Condition)
-> (ChildCollector IconSetOptions -> AttrParser IconSetOptions)
-> ChildCollector IconSetOptions
-> AttrParser Condition
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Either Text IconSetOptions -> AttrParser IconSetOptions
forall a. Either Text a -> AttrParser a
toAttrParser (Either Text IconSetOptions -> AttrParser IconSetOptions)
-> (ChildCollector IconSetOptions -> Either Text IconSetOptions)
-> ChildCollector IconSetOptions
-> AttrParser IconSetOptions
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Node -> ChildCollector IconSetOptions -> Either Text IconSetOptions
forall a. Node -> ChildCollector a -> Either Text a
collectChildren Node
root (ChildCollector IconSetOptions -> AttrParser Condition)
-> ChildCollector IconSetOptions -> AttrParser Condition
forall a b. (a -> b) -> a -> b
$ ByteString -> ChildCollector IconSetOptions
forall a. FromXenoNode a => ByteString -> ChildCollector a
fromChild ByteString
"iconSet"
      readConditionX ByteString
"notContainsBlanks" = Condition -> AttrParser Condition
forall (m :: * -> *) a. Monad m => a -> m a
return Condition
DoesNotContainBlanks
      readConditionX ByteString
"notContainsErrors" = Condition -> AttrParser Condition
forall (m :: * -> *) a. Monad m => a -> m a
return Condition
DoesNotContainErrors
      readConditionX ByteString
"notContainsText" =
        Text -> Condition
DoesNotContainText (Text -> Condition) -> AttrParser Text -> AttrParser Condition
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ByteString -> AttrParser Text
forall a. FromAttrBs a => ByteString -> AttrParser a
fromAttr ByteString
"text"
      readConditionX ByteString
"timePeriod" = TimePeriod -> Condition
InTimePeriod (TimePeriod -> Condition)
-> AttrParser TimePeriod -> AttrParser Condition
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ByteString -> AttrParser TimePeriod
forall a. FromAttrBs a => ByteString -> AttrParser a
fromAttr ByteString
"timePeriod"
      readConditionX ByteString
"top10" = do
        Bool
bottom <- ByteString -> Bool -> AttrParser Bool
forall a. FromAttrBs a => ByteString -> a -> AttrParser a
fromAttrDef ByteString
"bottom" Bool
False
        Bool
percent <- ByteString -> Bool -> AttrParser Bool
forall a. FromAttrBs a => ByteString -> a -> AttrParser a
fromAttrDef ByteString
"percent" Bool
False
        Int
rank <- ByteString -> AttrParser Int
forall a. FromAttrBs a => ByteString -> AttrParser a
fromAttr ByteString
"rank"
        case (Bool
bottom, Bool
percent) of
          (Bool
True, Bool
True) -> Condition -> AttrParser Condition
forall (m :: * -> *) a. Monad m => a -> m a
return (Condition -> AttrParser Condition)
-> Condition -> AttrParser Condition
forall a b. (a -> b) -> a -> b
$ Int -> Condition
BottomNPercent Int
rank
          (Bool
True, Bool
False) -> Condition -> AttrParser Condition
forall (m :: * -> *) a. Monad m => a -> m a
return (Condition -> AttrParser Condition)
-> Condition -> AttrParser Condition
forall a b. (a -> b) -> a -> b
$ Int -> Condition
BottomNValues Int
rank
          (Bool
False, Bool
True) -> Condition -> AttrParser Condition
forall (m :: * -> *) a. Monad m => a -> m a
return (Condition -> AttrParser Condition)
-> Condition -> AttrParser Condition
forall a b. (a -> b) -> a -> b
$ Int -> Condition
TopNPercent Int
rank
          (Bool
False, Bool
False) -> Condition -> AttrParser Condition
forall (m :: * -> *) a. Monad m => a -> m a
return (Condition -> AttrParser Condition)
-> Condition -> AttrParser Condition
forall a b. (a -> b) -> a -> b
$ Int -> Condition
TopNValues Int
rank
      readConditionX ByteString
"uniqueValues" = Condition -> AttrParser Condition
forall (m :: * -> *) a. Monad m => a -> m a
return Condition
UniqueValues
      readConditionX ByteString
x =
        Either Text Condition -> AttrParser Condition
forall a. Either Text a -> AttrParser a
toAttrParser (Either Text Condition -> AttrParser Condition)
-> (Text -> Either Text Condition) -> Text -> AttrParser Condition
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Either Text Condition
forall a b. a -> Either a b
Left (Text -> AttrParser Condition) -> Text -> AttrParser Condition
forall a b. (a -> b) -> a -> b
$ Text
"Unexpected conditional formatting type " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
T.pack (ByteString -> String
forall a. Show a => a -> String
show ByteString
x)

instance FromAttrVal TimePeriod where
    fromAttrVal :: Reader TimePeriod
fromAttrVal Text
"last7Days" = TimePeriod -> Either String (TimePeriod, Text)
forall a. a -> Either String (a, Text)
readSuccess TimePeriod
PerLast7Days
    fromAttrVal Text
"lastMonth" = TimePeriod -> Either String (TimePeriod, Text)
forall a. a -> Either String (a, Text)
readSuccess TimePeriod
PerLastMonth
    fromAttrVal Text
"lastWeek"  = TimePeriod -> Either String (TimePeriod, Text)
forall a. a -> Either String (a, Text)
readSuccess TimePeriod
PerLastWeek
    fromAttrVal Text
"nextMonth" = TimePeriod -> Either String (TimePeriod, Text)
forall a. a -> Either String (a, Text)
readSuccess TimePeriod
PerNextMonth
    fromAttrVal Text
"nextWeek"  = TimePeriod -> Either String (TimePeriod, Text)
forall a. a -> Either String (a, Text)
readSuccess TimePeriod
PerNextWeek
    fromAttrVal Text
"thisMonth" = TimePeriod -> Either String (TimePeriod, Text)
forall a. a -> Either String (a, Text)
readSuccess TimePeriod
PerThisMonth
    fromAttrVal Text
"thisWeek"  = TimePeriod -> Either String (TimePeriod, Text)
forall a. a -> Either String (a, Text)
readSuccess TimePeriod
PerThisWeek
    fromAttrVal Text
"today"     = TimePeriod -> Either String (TimePeriod, Text)
forall a. a -> Either String (a, Text)
readSuccess TimePeriod
PerToday
    fromAttrVal Text
"tomorrow"  = TimePeriod -> Either String (TimePeriod, Text)
forall a. a -> Either String (a, Text)
readSuccess TimePeriod
PerTomorrow
    fromAttrVal Text
"yesterday" = TimePeriod -> Either String (TimePeriod, Text)
forall a. a -> Either String (a, Text)
readSuccess TimePeriod
PerYesterday
    fromAttrVal Text
t           = Text -> Reader TimePeriod
forall a. Text -> Text -> Either String (a, Text)
invalidText Text
"TimePeriod" Text
t

instance FromAttrBs TimePeriod where
    fromAttrBs :: ByteString -> Either Text TimePeriod
fromAttrBs ByteString
"last7Days" = TimePeriod -> Either Text TimePeriod
forall (m :: * -> *) a. Monad m => a -> m a
return TimePeriod
PerLast7Days
    fromAttrBs ByteString
"lastMonth" = TimePeriod -> Either Text TimePeriod
forall (m :: * -> *) a. Monad m => a -> m a
return TimePeriod
PerLastMonth
    fromAttrBs ByteString
"lastWeek"  = TimePeriod -> Either Text TimePeriod
forall (m :: * -> *) a. Monad m => a -> m a
return TimePeriod
PerLastWeek
    fromAttrBs ByteString
"nextMonth" = TimePeriod -> Either Text TimePeriod
forall (m :: * -> *) a. Monad m => a -> m a
return TimePeriod
PerNextMonth
    fromAttrBs ByteString
"nextWeek"  = TimePeriod -> Either Text TimePeriod
forall (m :: * -> *) a. Monad m => a -> m a
return TimePeriod
PerNextWeek
    fromAttrBs ByteString
"thisMonth" = TimePeriod -> Either Text TimePeriod
forall (m :: * -> *) a. Monad m => a -> m a
return TimePeriod
PerThisMonth
    fromAttrBs ByteString
"thisWeek"  = TimePeriod -> Either Text TimePeriod
forall (m :: * -> *) a. Monad m => a -> m a
return TimePeriod
PerThisWeek
    fromAttrBs ByteString
"today"     = TimePeriod -> Either Text TimePeriod
forall (m :: * -> *) a. Monad m => a -> m a
return TimePeriod
PerToday
    fromAttrBs ByteString
"tomorrow"  = TimePeriod -> Either Text TimePeriod
forall (m :: * -> *) a. Monad m => a -> m a
return TimePeriod
PerTomorrow
    fromAttrBs ByteString
"yesterday" = TimePeriod -> Either Text TimePeriod
forall (m :: * -> *) a. Monad m => a -> m a
return TimePeriod
PerYesterday
    fromAttrBs ByteString
x           = Text -> ByteString -> Either Text TimePeriod
forall a. Text -> ByteString -> Either Text a
unexpectedAttrBs Text
"TimePeriod" ByteString
x

instance FromAttrVal CfvType where
  fromAttrVal :: Reader CfvType
fromAttrVal Text
"num"        = CfvType -> Either String (CfvType, Text)
forall a. a -> Either String (a, Text)
readSuccess CfvType
CfvtNum
  fromAttrVal Text
"percent"    = CfvType -> Either String (CfvType, Text)
forall a. a -> Either String (a, Text)
readSuccess CfvType
CfvtPercent
  fromAttrVal Text
"max"        = CfvType -> Either String (CfvType, Text)
forall a. a -> Either String (a, Text)
readSuccess CfvType
CfvtMax
  fromAttrVal Text
"min"        = CfvType -> Either String (CfvType, Text)
forall a. a -> Either String (a, Text)
readSuccess CfvType
CfvtMin
  fromAttrVal Text
"formula"    = CfvType -> Either String (CfvType, Text)
forall a. a -> Either String (a, Text)
readSuccess CfvType
CfvtFormula
  fromAttrVal Text
"percentile" = CfvType -> Either String (CfvType, Text)
forall a. a -> Either String (a, Text)
readSuccess CfvType
CfvtPercentile
  fromAttrVal Text
t            = Text -> Reader CfvType
forall a. Text -> Text -> Either String (a, Text)
invalidText Text
"CfvType" Text
t

instance FromAttrBs CfvType where
  fromAttrBs :: ByteString -> Either Text CfvType
fromAttrBs ByteString
"num"        = CfvType -> Either Text CfvType
forall (m :: * -> *) a. Monad m => a -> m a
return CfvType
CfvtNum
  fromAttrBs ByteString
"percent"    = CfvType -> Either Text CfvType
forall (m :: * -> *) a. Monad m => a -> m a
return CfvType
CfvtPercent
  fromAttrBs ByteString
"max"        = CfvType -> Either Text CfvType
forall (m :: * -> *) a. Monad m => a -> m a
return CfvType
CfvtMax
  fromAttrBs ByteString
"min"        = CfvType -> Either Text CfvType
forall (m :: * -> *) a. Monad m => a -> m a
return CfvType
CfvtMin
  fromAttrBs ByteString
"formula"    = CfvType -> Either Text CfvType
forall (m :: * -> *) a. Monad m => a -> m a
return CfvType
CfvtFormula
  fromAttrBs ByteString
"percentile" = CfvType -> Either Text CfvType
forall (m :: * -> *) a. Monad m => a -> m a
return CfvType
CfvtPercentile
  fromAttrBs ByteString
x            = Text -> ByteString -> Either Text CfvType
forall a. Text -> ByteString -> Either Text a
unexpectedAttrBs Text
"CfvType" ByteString
x

readCfValue :: (CfValue -> a) -> [a] -> [a] -> Cursor -> [a]
readCfValue :: (CfValue -> a) -> [a] -> [a] -> Cursor -> [a]
readCfValue CfValue -> a
f [a]
minVal [a]
maxVal Cursor
c = do
  CfvType
vType <- Name -> Cursor -> [CfvType]
forall a. FromAttrVal a => Name -> Cursor -> [a]
fromAttribute Name
"type" Cursor
c
  case CfvType
vType of
    CfvType
CfvtNum -> do
      Double
v <- Name -> Cursor -> [Double]
forall a. FromAttrVal a => Name -> Cursor -> [a]
fromAttribute Name
"val" Cursor
c
      a -> [a]
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> [a]) -> (CfValue -> a) -> CfValue -> [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CfValue -> a
f (CfValue -> [a]) -> CfValue -> [a]
forall a b. (a -> b) -> a -> b
$ Double -> CfValue
CfValue Double
v
    CfvType
CfvtFormula -> do
      Formula
v <- Name -> Cursor -> [Formula]
forall a. FromAttrVal a => Name -> Cursor -> [a]
fromAttribute Name
"val" Cursor
c
      a -> [a]
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> [a]) -> (CfValue -> a) -> CfValue -> [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CfValue -> a
f (CfValue -> [a]) -> CfValue -> [a]
forall a b. (a -> b) -> a -> b
$ Formula -> CfValue
CfFormula Formula
v
    CfvType
CfvtPercent -> do
      Double
v <- Name -> Cursor -> [Double]
forall a. FromAttrVal a => Name -> Cursor -> [a]
fromAttribute Name
"val" Cursor
c
      a -> [a]
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> [a]) -> (CfValue -> a) -> CfValue -> [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CfValue -> a
f (CfValue -> [a]) -> CfValue -> [a]
forall a b. (a -> b) -> a -> b
$ Double -> CfValue
CfPercent Double
v
    CfvType
CfvtPercentile -> do
      Double
v <- Name -> Cursor -> [Double]
forall a. FromAttrVal a => Name -> Cursor -> [a]
fromAttribute Name
"val" Cursor
c
      a -> [a]
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> [a]) -> (CfValue -> a) -> CfValue -> [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CfValue -> a
f (CfValue -> [a]) -> CfValue -> [a]
forall a b. (a -> b) -> a -> b
$ Double -> CfValue
CfPercentile Double
v
    CfvType
CfvtMin -> [a]
minVal
    CfvType
CfvtMax -> [a]
maxVal

readCfValueX ::
     (CfValue -> a)
  -> Either Text a
  -> Either Text a
  -> Xeno.Node
  -> Either Text a
readCfValueX :: (CfValue -> a)
-> Either Text a -> Either Text a -> Node -> Either Text a
readCfValueX CfValue -> a
f Either Text a
minVal Either Text a
maxVal Node
root =
  Node -> AttrParser a -> Either Text a
forall a. Node -> AttrParser a -> Either Text a
parseAttributes Node
root (AttrParser a -> Either Text a) -> AttrParser a -> Either Text a
forall a b. (a -> b) -> a -> b
$ do
    CfvType
vType <- ByteString -> AttrParser CfvType
forall a. FromAttrBs a => ByteString -> AttrParser a
fromAttr ByteString
"type"
    case CfvType
vType of
      CfvType
CfvtNum -> do
        Double
v <- ByteString -> AttrParser Double
forall a. FromAttrBs a => ByteString -> AttrParser a
fromAttr ByteString
"val"
        a -> AttrParser a
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> AttrParser a) -> (CfValue -> a) -> CfValue -> AttrParser a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CfValue -> a
f (CfValue -> AttrParser a) -> CfValue -> AttrParser a
forall a b. (a -> b) -> a -> b
$ Double -> CfValue
CfValue Double
v
      CfvType
CfvtFormula -> do
        Formula
v <- ByteString -> AttrParser Formula
forall a. FromAttrBs a => ByteString -> AttrParser a
fromAttr ByteString
"val"
        a -> AttrParser a
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> AttrParser a) -> (CfValue -> a) -> CfValue -> AttrParser a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CfValue -> a
f (CfValue -> AttrParser a) -> CfValue -> AttrParser a
forall a b. (a -> b) -> a -> b
$ Formula -> CfValue
CfFormula Formula
v
      CfvType
CfvtPercent -> do
        Double
v <- ByteString -> AttrParser Double
forall a. FromAttrBs a => ByteString -> AttrParser a
fromAttr ByteString
"val"
        a -> AttrParser a
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> AttrParser a) -> (CfValue -> a) -> CfValue -> AttrParser a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CfValue -> a
f (CfValue -> AttrParser a) -> CfValue -> AttrParser a
forall a b. (a -> b) -> a -> b
$ Double -> CfValue
CfPercent Double
v
      CfvType
CfvtPercentile -> do
        Double
v <- ByteString -> AttrParser Double
forall a. FromAttrBs a => ByteString -> AttrParser a
fromAttr ByteString
"val"
        a -> AttrParser a
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> AttrParser a) -> (CfValue -> a) -> CfValue -> AttrParser a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CfValue -> a
f (CfValue -> AttrParser a) -> CfValue -> AttrParser a
forall a b. (a -> b) -> a -> b
$ Double -> CfValue
CfPercentile Double
v
      CfvType
CfvtMin -> Either Text a -> AttrParser a
forall a. Either Text a -> AttrParser a
toAttrParser Either Text a
minVal
      CfvType
CfvtMax -> Either Text a -> AttrParser a
forall a. Either Text a -> AttrParser a
toAttrParser Either Text a
maxVal

failMinCfvType :: [a]
failMinCfvType :: [a]
failMinCfvType = String -> [a]
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"unexpected 'min' type"

failMinCfvTypeX :: Either Text a
failMinCfvTypeX :: Either Text a
failMinCfvTypeX = Text -> Either Text a
forall a b. a -> Either a b
Left Text
"unexpected 'min' type"

failMaxCfvType :: [a]
failMaxCfvType :: [a]
failMaxCfvType = String -> [a]
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"unexpected 'max' type"

failMaxCfvTypeX :: Either Text a
failMaxCfvTypeX :: Either Text a
failMaxCfvTypeX = Text -> Either Text a
forall a b. a -> Either a b
Left Text
"unexpected 'max' type"

instance FromCursor CfValue where
  fromCursor :: Cursor -> [CfValue]
fromCursor = (CfValue -> CfValue)
-> [CfValue] -> [CfValue] -> Cursor -> [CfValue]
forall a. (CfValue -> a) -> [a] -> [a] -> Cursor -> [a]
readCfValue CfValue -> CfValue
forall a. a -> a
id [CfValue]
forall a. [a]
failMinCfvType [CfValue]
forall a. [a]
failMaxCfvType

instance FromXenoNode CfValue where
  fromXenoNode :: Node -> Either Text CfValue
fromXenoNode Node
root = (CfValue -> CfValue)
-> Either Text CfValue
-> Either Text CfValue
-> Node
-> Either Text CfValue
forall a.
(CfValue -> a)
-> Either Text a -> Either Text a -> Node -> Either Text a
readCfValueX CfValue -> CfValue
forall a. a -> a
id Either Text CfValue
forall a. Either Text a
failMinCfvTypeX Either Text CfValue
forall a. Either Text a
failMaxCfvTypeX Node
root

instance FromCursor MinCfValue where
  fromCursor :: Cursor -> [MinCfValue]
fromCursor = (CfValue -> MinCfValue)
-> [MinCfValue] -> [MinCfValue] -> Cursor -> [MinCfValue]
forall a. (CfValue -> a) -> [a] -> [a] -> Cursor -> [a]
readCfValue CfValue -> MinCfValue
MinCfValue (MinCfValue -> [MinCfValue]
forall (m :: * -> *) a. Monad m => a -> m a
return MinCfValue
CfvMin) [MinCfValue]
forall a. [a]
failMaxCfvType

instance FromXenoNode MinCfValue where
  fromXenoNode :: Node -> Either Text MinCfValue
fromXenoNode Node
root =
    (CfValue -> MinCfValue)
-> Either Text MinCfValue
-> Either Text MinCfValue
-> Node
-> Either Text MinCfValue
forall a.
(CfValue -> a)
-> Either Text a -> Either Text a -> Node -> Either Text a
readCfValueX CfValue -> MinCfValue
MinCfValue (MinCfValue -> Either Text MinCfValue
forall (m :: * -> *) a. Monad m => a -> m a
return MinCfValue
CfvMin) Either Text MinCfValue
forall a. Either Text a
failMaxCfvTypeX Node
root

instance FromCursor MaxCfValue where
  fromCursor :: Cursor -> [MaxCfValue]
fromCursor = (CfValue -> MaxCfValue)
-> [MaxCfValue] -> [MaxCfValue] -> Cursor -> [MaxCfValue]
forall a. (CfValue -> a) -> [a] -> [a] -> Cursor -> [a]
readCfValue CfValue -> MaxCfValue
MaxCfValue [MaxCfValue]
forall a. [a]
failMinCfvType (MaxCfValue -> [MaxCfValue]
forall (m :: * -> *) a. Monad m => a -> m a
return MaxCfValue
CfvMax)

instance FromXenoNode MaxCfValue where
  fromXenoNode :: Node -> Either Text MaxCfValue
fromXenoNode Node
root =
    (CfValue -> MaxCfValue)
-> Either Text MaxCfValue
-> Either Text MaxCfValue
-> Node
-> Either Text MaxCfValue
forall a.
(CfValue -> a)
-> Either Text a -> Either Text a -> Node -> Either Text a
readCfValueX CfValue -> MaxCfValue
MaxCfValue Either Text MaxCfValue
forall a. Either Text a
failMinCfvTypeX (MaxCfValue -> Either Text MaxCfValue
forall (m :: * -> *) a. Monad m => a -> m a
return MaxCfValue
CfvMax) Node
root

defaultIconSet :: IconSetType
defaultIconSet :: IconSetType
defaultIconSet =  IconSetType
IconSet3TrafficLights1

instance FromCursor IconSetOptions where
  fromCursor :: Cursor -> [IconSetOptions]
fromCursor Cursor
cur = do
    IconSetType
_isoIconSet <- Name -> IconSetType -> Cursor -> [IconSetType]
forall a. FromAttrVal a => Name -> a -> Cursor -> [a]
fromAttributeDef Name
"iconSet" IconSetType
defaultIconSet Cursor
cur
    let _isoValues :: [CfValue]
_isoValues = Cursor
cur Cursor -> (Cursor -> [CfValue]) -> [CfValue]
forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$/ Name -> Axis
element (Text -> Name
n_ Text
"cfvo") Axis -> (Cursor -> [CfValue]) -> Cursor -> [CfValue]
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> Cursor -> [CfValue]
forall a. FromCursor a => Cursor -> [a]
fromCursor
    Bool
_isoReverse <- Name -> Bool -> Cursor -> [Bool]
forall a. FromAttrVal a => Name -> a -> Cursor -> [a]
fromAttributeDef Name
"reverse" Bool
False Cursor
cur
    Bool
_isoShowValue <- Name -> Bool -> Cursor -> [Bool]
forall a. FromAttrVal a => Name -> a -> Cursor -> [a]
fromAttributeDef Name
"showValue" Bool
True Cursor
cur
    IconSetOptions -> [IconSetOptions]
forall (m :: * -> *) a. Monad m => a -> m a
return IconSetOptions :: IconSetType -> [CfValue] -> Bool -> Bool -> IconSetOptions
IconSetOptions {Bool
[CfValue]
IconSetType
_isoShowValue :: Bool
_isoReverse :: Bool
_isoValues :: [CfValue]
_isoIconSet :: IconSetType
_isoShowValue :: Bool
_isoReverse :: Bool
_isoValues :: [CfValue]
_isoIconSet :: IconSetType
..}

instance FromXenoNode IconSetOptions where
  fromXenoNode :: Node -> Either Text IconSetOptions
fromXenoNode Node
root = do
    (IconSetType
_isoIconSet, Bool
_isoReverse, Bool
_isoShowValue) <-
      Node
-> AttrParser (IconSetType, Bool, Bool)
-> Either Text (IconSetType, Bool, Bool)
forall a. Node -> AttrParser a -> Either Text a
parseAttributes Node
root (AttrParser (IconSetType, Bool, Bool)
 -> Either Text (IconSetType, Bool, Bool))
-> AttrParser (IconSetType, Bool, Bool)
-> Either Text (IconSetType, Bool, Bool)
forall a b. (a -> b) -> a -> b
$ (,,) (IconSetType -> Bool -> Bool -> (IconSetType, Bool, Bool))
-> AttrParser IconSetType
-> AttrParser (Bool -> Bool -> (IconSetType, Bool, Bool))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ByteString -> IconSetType -> AttrParser IconSetType
forall a. FromAttrBs a => ByteString -> a -> AttrParser a
fromAttrDef ByteString
"iconSet" IconSetType
defaultIconSet
                                  AttrParser (Bool -> Bool -> (IconSetType, Bool, Bool))
-> AttrParser Bool
-> AttrParser (Bool -> (IconSetType, Bool, Bool))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ByteString -> Bool -> AttrParser Bool
forall a. FromAttrBs a => ByteString -> a -> AttrParser a
fromAttrDef ByteString
"reverse" Bool
False
                                  AttrParser (Bool -> (IconSetType, Bool, Bool))
-> AttrParser Bool -> AttrParser (IconSetType, Bool, Bool)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ByteString -> Bool -> AttrParser Bool
forall a. FromAttrBs a => ByteString -> a -> AttrParser a
fromAttrDef ByteString
"showValue" Bool
True
    [CfValue]
_isoValues <- Node -> ChildCollector [CfValue] -> Either Text [CfValue]
forall a. Node -> ChildCollector a -> Either Text a
collectChildren Node
root (ChildCollector [CfValue] -> Either Text [CfValue])
-> ChildCollector [CfValue] -> Either Text [CfValue]
forall a b. (a -> b) -> a -> b
$ ByteString -> ChildCollector [CfValue]
forall a. FromXenoNode a => ByteString -> ChildCollector [a]
fromChildList ByteString
"cfvo"
    IconSetOptions -> Either Text IconSetOptions
forall (m :: * -> *) a. Monad m => a -> m a
return IconSetOptions :: IconSetType -> [CfValue] -> Bool -> Bool -> IconSetOptions
IconSetOptions {Bool
[CfValue]
IconSetType
_isoValues :: [CfValue]
_isoShowValue :: Bool
_isoReverse :: Bool
_isoIconSet :: IconSetType
_isoShowValue :: Bool
_isoReverse :: Bool
_isoValues :: [CfValue]
_isoIconSet :: IconSetType
..}

instance FromAttrVal IconSetType where
  fromAttrVal :: Reader IconSetType
fromAttrVal Text
"3Arrows" = IconSetType -> Either String (IconSetType, Text)
forall a. a -> Either String (a, Text)
readSuccess IconSetType
IconSet3Arrows
  fromAttrVal Text
"3ArrowsGray" = IconSetType -> Either String (IconSetType, Text)
forall a. a -> Either String (a, Text)
readSuccess IconSetType
IconSet3ArrowsGray
  fromAttrVal Text
"3Flags" = IconSetType -> Either String (IconSetType, Text)
forall a. a -> Either String (a, Text)
readSuccess IconSetType
IconSet3Flags
  fromAttrVal Text
"3Signs" = IconSetType -> Either String (IconSetType, Text)
forall a. a -> Either String (a, Text)
readSuccess IconSetType
IconSet3Signs
  fromAttrVal Text
"3Symbols" = IconSetType -> Either String (IconSetType, Text)
forall a. a -> Either String (a, Text)
readSuccess IconSetType
IconSet3Symbols
  fromAttrVal Text
"3Symbols2" = IconSetType -> Either String (IconSetType, Text)
forall a. a -> Either String (a, Text)
readSuccess IconSetType
IconSet3Symbols2
  fromAttrVal Text
"3TrafficLights1" = IconSetType -> Either String (IconSetType, Text)
forall a. a -> Either String (a, Text)
readSuccess IconSetType
IconSet3TrafficLights1
  fromAttrVal Text
"3TrafficLights2" = IconSetType -> Either String (IconSetType, Text)
forall a. a -> Either String (a, Text)
readSuccess IconSetType
IconSet3TrafficLights2
  fromAttrVal Text
"4Arrows" = IconSetType -> Either String (IconSetType, Text)
forall a. a -> Either String (a, Text)
readSuccess IconSetType
IconSet4Arrows
  fromAttrVal Text
"4ArrowsGray" = IconSetType -> Either String (IconSetType, Text)
forall a. a -> Either String (a, Text)
readSuccess IconSetType
IconSet4ArrowsGray
  fromAttrVal Text
"4Rating" = IconSetType -> Either String (IconSetType, Text)
forall a. a -> Either String (a, Text)
readSuccess IconSetType
IconSet4Rating
  fromAttrVal Text
"4RedToBlack" = IconSetType -> Either String (IconSetType, Text)
forall a. a -> Either String (a, Text)
readSuccess IconSetType
IconSet4RedToBlack
  fromAttrVal Text
"4TrafficLights" = IconSetType -> Either String (IconSetType, Text)
forall a. a -> Either String (a, Text)
readSuccess IconSetType
IconSet4TrafficLights
  fromAttrVal Text
"5Arrows" = IconSetType -> Either String (IconSetType, Text)
forall a. a -> Either String (a, Text)
readSuccess IconSetType
IconSet5Arrows
  fromAttrVal Text
"5ArrowsGray" = IconSetType -> Either String (IconSetType, Text)
forall a. a -> Either String (a, Text)
readSuccess IconSetType
IconSet5ArrowsGray
  fromAttrVal Text
"5Quarters" = IconSetType -> Either String (IconSetType, Text)
forall a. a -> Either String (a, Text)
readSuccess IconSetType
IconSet5Quarters
  fromAttrVal Text
"5Rating" = IconSetType -> Either String (IconSetType, Text)
forall a. a -> Either String (a, Text)
readSuccess IconSetType
IconSet5Rating
  fromAttrVal Text
t = Text -> Reader IconSetType
forall a. Text -> Text -> Either String (a, Text)
invalidText Text
"IconSetType" Text
t

instance FromAttrBs IconSetType where
  fromAttrBs :: ByteString -> Either Text IconSetType
fromAttrBs ByteString
"3Arrows" = IconSetType -> Either Text IconSetType
forall (m :: * -> *) a. Monad m => a -> m a
return IconSetType
IconSet3Arrows
  fromAttrBs ByteString
"3ArrowsGray" = IconSetType -> Either Text IconSetType
forall (m :: * -> *) a. Monad m => a -> m a
return IconSetType
IconSet3ArrowsGray
  fromAttrBs ByteString
"3Flags" = IconSetType -> Either Text IconSetType
forall (m :: * -> *) a. Monad m => a -> m a
return IconSetType
IconSet3Flags
  fromAttrBs ByteString
"3Signs" = IconSetType -> Either Text IconSetType
forall (m :: * -> *) a. Monad m => a -> m a
return IconSetType
IconSet3Signs
  fromAttrBs ByteString
"3Symbols" = IconSetType -> Either Text IconSetType
forall (m :: * -> *) a. Monad m => a -> m a
return IconSetType
IconSet3Symbols
  fromAttrBs ByteString
"3Symbols2" = IconSetType -> Either Text IconSetType
forall (m :: * -> *) a. Monad m => a -> m a
return IconSetType
IconSet3Symbols2
  fromAttrBs ByteString
"3TrafficLights1" = IconSetType -> Either Text IconSetType
forall (m :: * -> *) a. Monad m => a -> m a
return IconSetType
IconSet3TrafficLights1
  fromAttrBs ByteString
"3TrafficLights2" = IconSetType -> Either Text IconSetType
forall (m :: * -> *) a. Monad m => a -> m a
return IconSetType
IconSet3TrafficLights2
  fromAttrBs ByteString
"4Arrows" = IconSetType -> Either Text IconSetType
forall (m :: * -> *) a. Monad m => a -> m a
return IconSetType
IconSet4Arrows
  fromAttrBs ByteString
"4ArrowsGray" = IconSetType -> Either Text IconSetType
forall (m :: * -> *) a. Monad m => a -> m a
return IconSetType
IconSet4ArrowsGray
  fromAttrBs ByteString
"4Rating" = IconSetType -> Either Text IconSetType
forall (m :: * -> *) a. Monad m => a -> m a
return IconSetType
IconSet4Rating
  fromAttrBs ByteString
"4RedToBlack" = IconSetType -> Either Text IconSetType
forall (m :: * -> *) a. Monad m => a -> m a
return IconSetType
IconSet4RedToBlack
  fromAttrBs ByteString
"4TrafficLights" = IconSetType -> Either Text IconSetType
forall (m :: * -> *) a. Monad m => a -> m a
return IconSetType
IconSet4TrafficLights
  fromAttrBs ByteString
"5Arrows" = IconSetType -> Either Text IconSetType
forall (m :: * -> *) a. Monad m => a -> m a
return IconSetType
IconSet5Arrows
  fromAttrBs ByteString
"5ArrowsGray" = IconSetType -> Either Text IconSetType
forall (m :: * -> *) a. Monad m => a -> m a
return IconSetType
IconSet5ArrowsGray
  fromAttrBs ByteString
"5Quarters" = IconSetType -> Either Text IconSetType
forall (m :: * -> *) a. Monad m => a -> m a
return IconSetType
IconSet5Quarters
  fromAttrBs ByteString
"5Rating" = IconSetType -> Either Text IconSetType
forall (m :: * -> *) a. Monad m => a -> m a
return IconSetType
IconSet5Rating
  fromAttrBs ByteString
x = Text -> ByteString -> Either Text IconSetType
forall a. Text -> ByteString -> Either Text a
unexpectedAttrBs Text
"IconSetType" ByteString
x

instance FromCursor DataBarOptions where
  fromCursor :: Cursor -> [DataBarOptions]
fromCursor Cursor
cur = do
    Int
_dboMaxLength <- Name -> Int -> Cursor -> [Int]
forall a. FromAttrVal a => Name -> a -> Cursor -> [a]
fromAttributeDef Name
"maxLength" Int
defaultDboMaxLength Cursor
cur
    Int
_dboMinLength <- Name -> Int -> Cursor -> [Int]
forall a. FromAttrVal a => Name -> a -> Cursor -> [a]
fromAttributeDef Name
"minLength" Int
defaultDboMinLength Cursor
cur
    Bool
_dboShowValue <- Name -> Bool -> Cursor -> [Bool]
forall a. FromAttrVal a => Name -> a -> Cursor -> [a]
fromAttributeDef Name
"showValue" Bool
True Cursor
cur
    let cfvos :: [Node]
cfvos = Cursor
cur Cursor -> (Cursor -> [Node]) -> [Node]
forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$/ Name -> Axis
element (Text -> Name
n_ Text
"cfvo") Axis -> (Cursor -> Node) -> Cursor -> [Node]
forall node a b.
(Cursor node -> [a]) -> (a -> b) -> Cursor node -> [b]
&| Cursor -> Node
forall node. Cursor node -> node
node
    case [Node]
cfvos of
      [Node
nMin, Node
nMax] -> do
        MinCfValue
_dboMinimum <- Cursor -> [MinCfValue]
forall a. FromCursor a => Cursor -> [a]
fromCursor (Node -> Cursor
fromNode Node
nMin)
        MaxCfValue
_dboMaximum <- Cursor -> [MaxCfValue]
forall a. FromCursor a => Cursor -> [a]
fromCursor (Node -> Cursor
fromNode Node
nMax)
        Color
_dboColor <- Cursor
cur Cursor -> (Cursor -> [Color]) -> [Color]
forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$/ Name -> Axis
element (Text -> Name
n_ Text
"color") Axis -> (Cursor -> [Color]) -> Cursor -> [Color]
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> Cursor -> [Color]
forall a. FromCursor a => Cursor -> [a]
fromCursor
        DataBarOptions -> [DataBarOptions]
forall (m :: * -> *) a. Monad m => a -> m a
return DataBarOptions :: Int
-> Int
-> Bool
-> MinCfValue
-> MaxCfValue
-> Color
-> DataBarOptions
DataBarOptions{Bool
Int
Color
MaxCfValue
MinCfValue
_dboColor :: Color
_dboMaximum :: MaxCfValue
_dboMinimum :: MinCfValue
_dboShowValue :: Bool
_dboMinLength :: Int
_dboMaxLength :: Int
_dboColor :: Color
_dboMaximum :: MaxCfValue
_dboMinimum :: MinCfValue
_dboShowValue :: Bool
_dboMinLength :: Int
_dboMaxLength :: Int
..}
      [Node]
ns -> do
        String -> [DataBarOptions]
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> [DataBarOptions]) -> String -> [DataBarOptions]
forall a b. (a -> b) -> a -> b
$ String
"expected minimum and maximum cfvo nodes but see instead " String -> ShowS
forall a. [a] -> [a] -> [a]
++
          Int -> String
forall a. Show a => a -> String
show ([Node] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Node]
ns) String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" cfvo nodes"

instance FromXenoNode DataBarOptions where
  fromXenoNode :: Node -> Either Text DataBarOptions
fromXenoNode Node
root = do
    (Int
_dboMaxLength, Int
_dboMinLength, Bool
_dboShowValue) <-
      Node -> AttrParser (Int, Int, Bool) -> Either Text (Int, Int, Bool)
forall a. Node -> AttrParser a -> Either Text a
parseAttributes Node
root (AttrParser (Int, Int, Bool) -> Either Text (Int, Int, Bool))
-> AttrParser (Int, Int, Bool) -> Either Text (Int, Int, Bool)
forall a b. (a -> b) -> a -> b
$ (,,) (Int -> Int -> Bool -> (Int, Int, Bool))
-> AttrParser Int -> AttrParser (Int -> Bool -> (Int, Int, Bool))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ByteString -> Int -> AttrParser Int
forall a. FromAttrBs a => ByteString -> a -> AttrParser a
fromAttrDef ByteString
"maxLength" Int
defaultDboMaxLength
                                  AttrParser (Int -> Bool -> (Int, Int, Bool))
-> AttrParser Int -> AttrParser (Bool -> (Int, Int, Bool))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ByteString -> Int -> AttrParser Int
forall a. FromAttrBs a => ByteString -> a -> AttrParser a
fromAttrDef ByteString
"minLength" Int
defaultDboMinLength
                                  AttrParser (Bool -> (Int, Int, Bool))
-> AttrParser Bool -> AttrParser (Int, Int, Bool)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ByteString -> Bool -> AttrParser Bool
forall a. FromAttrBs a => ByteString -> a -> AttrParser a
fromAttrDef ByteString
"showValue" Bool
True
    (MinCfValue
_dboMinimum, MaxCfValue
_dboMaximum, Color
_dboColor) <-
      Node
-> ChildCollector (MinCfValue, MaxCfValue, Color)
-> Either Text (MinCfValue, MaxCfValue, Color)
forall a. Node -> ChildCollector a -> Either Text a
collectChildren Node
root (ChildCollector (MinCfValue, MaxCfValue, Color)
 -> Either Text (MinCfValue, MaxCfValue, Color))
-> ChildCollector (MinCfValue, MaxCfValue, Color)
-> Either Text (MinCfValue, MaxCfValue, Color)
forall a b. (a -> b) -> a -> b
$ (,,) (MinCfValue
 -> MaxCfValue -> Color -> (MinCfValue, MaxCfValue, Color))
-> ChildCollector MinCfValue
-> ChildCollector
     (MaxCfValue -> Color -> (MinCfValue, MaxCfValue, Color))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ByteString -> ChildCollector MinCfValue
forall a. FromXenoNode a => ByteString -> ChildCollector a
fromChild ByteString
"cfvo"
                                  ChildCollector
  (MaxCfValue -> Color -> (MinCfValue, MaxCfValue, Color))
-> ChildCollector MaxCfValue
-> ChildCollector (Color -> (MinCfValue, MaxCfValue, Color))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ByteString -> ChildCollector MaxCfValue
forall a. FromXenoNode a => ByteString -> ChildCollector a
fromChild ByteString
"cfvo"
                                  ChildCollector (Color -> (MinCfValue, MaxCfValue, Color))
-> ChildCollector Color
-> ChildCollector (MinCfValue, MaxCfValue, Color)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ByteString -> ChildCollector Color
forall a. FromXenoNode a => ByteString -> ChildCollector a
fromChild ByteString
"color"
    DataBarOptions -> Either Text DataBarOptions
forall (m :: * -> *) a. Monad m => a -> m a
return DataBarOptions :: Int
-> Int
-> Bool
-> MinCfValue
-> MaxCfValue
-> Color
-> DataBarOptions
DataBarOptions{Bool
Int
Color
MaxCfValue
MinCfValue
_dboColor :: Color
_dboMaximum :: MaxCfValue
_dboMinimum :: MinCfValue
_dboShowValue :: Bool
_dboMinLength :: Int
_dboMaxLength :: Int
_dboColor :: Color
_dboMaximum :: MaxCfValue
_dboMinimum :: MinCfValue
_dboShowValue :: Bool
_dboMinLength :: Int
_dboMaxLength :: Int
..}

instance FromAttrVal Inclusion where
  fromAttrVal :: Reader Inclusion
fromAttrVal = ((Bool, Text) -> (Inclusion, Text))
-> Either String (Bool, Text) -> Either String (Inclusion, Text)
forall (a :: * -> * -> *) b c d.
ArrowChoice a =>
a b c -> a (Either d b) (Either d c)
right ((Bool -> Inclusion) -> (Bool, Text) -> (Inclusion, Text)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first ((Bool -> Inclusion) -> (Bool, Text) -> (Inclusion, Text))
-> (Bool -> Inclusion) -> (Bool, Text) -> (Inclusion, Text)
forall a b. (a -> b) -> a -> b
$ Inclusion -> Inclusion -> Bool -> Inclusion
forall a. a -> a -> Bool -> a
bool Inclusion
Exclusive Inclusion
Inclusive) (Either String (Bool, Text) -> Either String (Inclusion, Text))
-> (Text -> Either String (Bool, Text)) -> Reader Inclusion
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Either String (Bool, Text)
forall a. FromAttrVal a => Reader a
fromAttrVal

instance FromAttrBs Inclusion where
  fromAttrBs :: ByteString -> Either Text Inclusion
fromAttrBs = (Bool -> Inclusion) -> Either Text Bool -> Either Text Inclusion
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Inclusion -> Inclusion -> Bool -> Inclusion
forall a. a -> a -> Bool -> a
bool Inclusion
Exclusive Inclusion
Inclusive) (Either Text Bool -> Either Text Inclusion)
-> (ByteString -> Either Text Bool)
-> ByteString
-> Either Text Inclusion
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Either Text Bool
forall a. FromAttrBs a => ByteString -> Either Text a
fromAttrBs

instance FromAttrVal NStdDev where
  fromAttrVal :: Reader NStdDev
fromAttrVal = ((Int, Text) -> (NStdDev, Text))
-> Either String (Int, Text) -> Either String (NStdDev, Text)
forall (a :: * -> * -> *) b c d.
ArrowChoice a =>
a b c -> a (Either d b) (Either d c)
right ((Int -> NStdDev) -> (Int, Text) -> (NStdDev, Text)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first Int -> NStdDev
NStdDev) (Either String (Int, Text) -> Either String (NStdDev, Text))
-> (Text -> Either String (Int, Text)) -> Reader NStdDev
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Either String (Int, Text)
forall a. FromAttrVal a => Reader a
fromAttrVal

instance FromAttrBs NStdDev where
  fromAttrBs :: ByteString -> Either Text NStdDev
fromAttrBs = (Int -> NStdDev) -> Either Text Int -> Either Text NStdDev
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Int -> NStdDev
NStdDev (Either Text Int -> Either Text NStdDev)
-> (ByteString -> Either Text Int)
-> ByteString
-> Either Text NStdDev
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Either Text Int
forall a. FromAttrBs a => ByteString -> Either Text a
fromAttrBs

{-------------------------------------------------------------------------------
  Rendering
-------------------------------------------------------------------------------}

instance ToElement CfRule where
    toElement :: Name -> CfRule -> Element
toElement Name
nm CfRule{Int
Maybe Bool
Maybe Int
Condition
_cfrStopIfTrue :: Maybe Bool
_cfrPriority :: Int
_cfrDxfId :: Maybe Int
_cfrCondition :: Condition
_cfrStopIfTrue :: CfRule -> Maybe Bool
_cfrPriority :: CfRule -> Int
_cfrDxfId :: CfRule -> Maybe Int
_cfrCondition :: CfRule -> Condition
..} =
        let (Text
condType, Map Name Text
condAttrs, [Node]
condNodes) = Condition -> (Text, Map Name Text, [Node])
conditionData Condition
_cfrCondition
            baseAttrs :: Map Name Text
baseAttrs = [(Name, Text)] -> Map Name Text
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList ([(Name, Text)] -> Map Name Text)
-> ([Maybe (Name, Text)] -> [(Name, Text)])
-> [Maybe (Name, Text)]
-> Map Name Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Maybe (Name, Text)] -> [(Name, Text)]
forall a. [Maybe a] -> [a]
catMaybes ([Maybe (Name, Text)] -> Map Name Text)
-> [Maybe (Name, Text)] -> Map Name Text
forall a b. (a -> b) -> a -> b
$
                [ (Name, Text) -> Maybe (Name, Text)
forall a. a -> Maybe a
Just ((Name, Text) -> Maybe (Name, Text))
-> (Name, Text) -> Maybe (Name, Text)
forall a b. (a -> b) -> a -> b
$ Name
"type"       Name -> Text -> (Name, Text)
forall a. ToAttrVal a => Name -> a -> (Name, Text)
.=  Text
condType
                ,        Name
"dxfId"      Name -> Maybe Int -> Maybe (Name, Text)
forall a. ToAttrVal a => Name -> Maybe a -> Maybe (Name, Text)
.=? Maybe Int
_cfrDxfId
                , (Name, Text) -> Maybe (Name, Text)
forall a. a -> Maybe a
Just ((Name, Text) -> Maybe (Name, Text))
-> (Name, Text) -> Maybe (Name, Text)
forall a b. (a -> b) -> a -> b
$ Name
"priority"   Name -> Int -> (Name, Text)
forall a. ToAttrVal a => Name -> a -> (Name, Text)
.=  Int
_cfrPriority
                ,        Name
"stopIfTrue" Name -> Maybe Bool -> Maybe (Name, Text)
forall a. ToAttrVal a => Name -> Maybe a -> Maybe (Name, Text)
.=? Maybe Bool
_cfrStopIfTrue
                ]
        in Element :: Name -> Map Name Text -> [Node] -> Element
Element
           { elementName :: Name
elementName = Name
nm
           , elementAttributes :: Map Name Text
elementAttributes = Map Name Text -> Map Name Text -> Map Name Text
forall k a. Ord k => Map k a -> Map k a -> Map k a
M.union Map Name Text
baseAttrs Map Name Text
condAttrs
           , elementNodes :: [Node]
elementNodes = [Node]
condNodes
           }

conditionData :: Condition -> (Text, Map Name Text, [Node])
conditionData :: Condition -> (Text, Map Name Text, [Node])
conditionData (AboveAverage Inclusion
i Maybe NStdDev
sDevs) =
  (Text
"aboveAverage", [(Name, Text)] -> Map Name Text
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList ([(Name, Text)] -> Map Name Text)
-> [(Name, Text)] -> Map Name Text
forall a b. (a -> b) -> a -> b
$ [Name
"aboveAverage" Name -> Bool -> (Name, Text)
forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= Bool
True] [(Name, Text)] -> [(Name, Text)] -> [(Name, Text)]
forall a. [a] -> [a] -> [a]
++
                   [Maybe (Name, Text)] -> [(Name, Text)]
forall a. [Maybe a] -> [a]
catMaybes [ Name
"equalAverage" Name -> Maybe Inclusion -> Maybe (Name, Text)
forall a. ToAttrVal a => Name -> Maybe a -> Maybe (Name, Text)
.=? Inclusion -> Inclusion -> Maybe Inclusion
forall a. Eq a => a -> a -> Maybe a
justNonDef Inclusion
Exclusive Inclusion
i
                             , Name
"stdDev" Name -> Maybe NStdDev -> Maybe (Name, Text)
forall a. ToAttrVal a => Name -> Maybe a -> Maybe (Name, Text)
.=? Maybe NStdDev
sDevs], [])
conditionData (BeginsWith Text
t)         = (Text
"beginsWith", [(Name, Text)] -> Map Name Text
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList [ Name
"text" Name -> Text -> (Name, Text)
forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= Text
t], [])
conditionData (BelowAverage Inclusion
i Maybe NStdDev
sDevs) =
  (Text
"aboveAverage", [(Name, Text)] -> Map Name Text
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList ([(Name, Text)] -> Map Name Text)
-> [(Name, Text)] -> Map Name Text
forall a b. (a -> b) -> a -> b
$ [Name
"aboveAverage" Name -> Bool -> (Name, Text)
forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= Bool
False] [(Name, Text)] -> [(Name, Text)] -> [(Name, Text)]
forall a. [a] -> [a] -> [a]
++
                   [Maybe (Name, Text)] -> [(Name, Text)]
forall a. [Maybe a] -> [a]
catMaybes [ Name
"equalAverage" Name -> Maybe Inclusion -> Maybe (Name, Text)
forall a. ToAttrVal a => Name -> Maybe a -> Maybe (Name, Text)
.=? Inclusion -> Inclusion -> Maybe Inclusion
forall a. Eq a => a -> a -> Maybe a
justNonDef Inclusion
Exclusive Inclusion
i
                             , Name
"stdDev" Name -> Maybe NStdDev -> Maybe (Name, Text)
forall a. ToAttrVal a => Name -> Maybe a -> Maybe (Name, Text)
.=? Maybe NStdDev
sDevs], [])
conditionData (BottomNPercent Int
n)     = (Text
"top10", [(Name, Text)] -> Map Name Text
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList [ Name
"bottom" Name -> Bool -> (Name, Text)
forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= Bool
True, Name
"rank" Name -> Int -> (Name, Text)
forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= Int
n, Name
"percent" Name -> Bool -> (Name, Text)
forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= Bool
True ], [])
conditionData (BottomNValues Int
n)      = (Text
"top10", [(Name, Text)] -> Map Name Text
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList [ Name
"bottom" Name -> Bool -> (Name, Text)
forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= Bool
True, Name
"rank" Name -> Int -> (Name, Text)
forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= Int
n ], [])
conditionData (CellIs OperatorExpression
opExpr)        = (Text
"cellIs", [(Name, Text)] -> Map Name Text
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList [ Name
"operator" Name -> Text -> (Name, Text)
forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= Text
op], [Node]
formulas)
    where (Text
op, [Node]
formulas) = OperatorExpression -> (Text, [Node])
operatorExpressionData OperatorExpression
opExpr
conditionData (ColorScale2 MinCfValue
minv Color
minc MaxCfValue
maxv Color
maxc) =
  ( Text
"colorScale"
  , Map Name Text
forall k a. Map k a
M.empty
  , [ Element -> Node
NodeElement (Element -> Node) -> Element -> Node
forall a b. (a -> b) -> a -> b
$
      Name -> [Element] -> Element
elementListSimple
        Name
"colorScale"
        [ Name -> MinCfValue -> Element
forall a. ToElement a => Name -> a -> Element
toElement Name
"cfvo" MinCfValue
minv
        , Name -> MaxCfValue -> Element
forall a. ToElement a => Name -> a -> Element
toElement Name
"cfvo" MaxCfValue
maxv
        , Name -> Color -> Element
forall a. ToElement a => Name -> a -> Element
toElement Name
"color" Color
minc
        , Name -> Color -> Element
forall a. ToElement a => Name -> a -> Element
toElement Name
"color" Color
maxc
        ]
    ])
conditionData (ColorScale3 MinCfValue
minv Color
minc CfValue
midv Color
midc MaxCfValue
maxv Color
maxc) =
  ( Text
"colorScale"
  , Map Name Text
forall k a. Map k a
M.empty
  , [ Element -> Node
NodeElement (Element -> Node) -> Element -> Node
forall a b. (a -> b) -> a -> b
$
      Name -> [Element] -> Element
elementListSimple
        Name
"colorScale"
        [ Name -> MinCfValue -> Element
forall a. ToElement a => Name -> a -> Element
toElement Name
"cfvo" MinCfValue
minv
        , Name -> CfValue -> Element
forall a. ToElement a => Name -> a -> Element
toElement Name
"cfvo" CfValue
midv
        , Name -> MaxCfValue -> Element
forall a. ToElement a => Name -> a -> Element
toElement Name
"cfvo" MaxCfValue
maxv
        , Name -> Color -> Element
forall a. ToElement a => Name -> a -> Element
toElement Name
"color" Color
minc
        , Name -> Color -> Element
forall a. ToElement a => Name -> a -> Element
toElement Name
"color" Color
midc
        , Name -> Color -> Element
forall a. ToElement a => Name -> a -> Element
toElement Name
"color" Color
maxc
        ]
    ])
conditionData Condition
ContainsBlanks         = (Text
"containsBlanks", Map Name Text
forall k a. Map k a
M.empty, [])
conditionData Condition
ContainsErrors         = (Text
"containsErrors", Map Name Text
forall k a. Map k a
M.empty, [])
conditionData (ContainsText Text
t)       = (Text
"containsText", [(Name, Text)] -> Map Name Text
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList [ Name
"text" Name -> Text -> (Name, Text)
forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= Text
t], [])
conditionData (DataBar DataBarOptions
dbOpts)       = (Text
"dataBar", Map Name Text
forall k a. Map k a
M.empty, [Name -> DataBarOptions -> Node
forall a. ToElement a => Name -> a -> Node
toNode Name
"dataBar" DataBarOptions
dbOpts])
conditionData Condition
DoesNotContainBlanks   = (Text
"notContainsBlanks", Map Name Text
forall k a. Map k a
M.empty, [])
conditionData Condition
DoesNotContainErrors   = (Text
"notContainsErrors", Map Name Text
forall k a. Map k a
M.empty, [])
conditionData (DoesNotContainText Text
t) = (Text
"notContainsText", [(Name, Text)] -> Map Name Text
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList [ Name
"text" Name -> Text -> (Name, Text)
forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= Text
t], [])
conditionData Condition
DuplicateValues        = (Text
"duplicateValues", Map Name Text
forall k a. Map k a
M.empty, [])
conditionData (EndsWith Text
t)           = (Text
"endsWith", [(Name, Text)] -> Map Name Text
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList [ Name
"text" Name -> Text -> (Name, Text)
forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= Text
t], [])
conditionData (Expression Formula
formula)   = (Text
"expression", Map Name Text
forall k a. Map k a
M.empty, [Formula -> Node
formulaNode Formula
formula])
conditionData (InTimePeriod TimePeriod
period)  = (Text
"timePeriod", [(Name, Text)] -> Map Name Text
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList [ Name
"timePeriod" Name -> TimePeriod -> (Name, Text)
forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= TimePeriod
period ], [])
conditionData (IconSet IconSetOptions
isOptions)    = (Text
"iconSet", Map Name Text
forall k a. Map k a
M.empty, [Name -> IconSetOptions -> Node
forall a. ToElement a => Name -> a -> Node
toNode Name
"iconSet" IconSetOptions
isOptions])
conditionData (TopNPercent Int
n)        = (Text
"top10", [(Name, Text)] -> Map Name Text
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList [ Name
"rank" Name -> Int -> (Name, Text)
forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= Int
n, Name
"percent" Name -> Bool -> (Name, Text)
forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= Bool
True ], [])
conditionData (TopNValues Int
n)         = (Text
"top10", [(Name, Text)] -> Map Name Text
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList [ Name
"rank" Name -> Int -> (Name, Text)
forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= Int
n ], [])
conditionData Condition
UniqueValues           = (Text
"uniqueValues", Map Name Text
forall k a. Map k a
M.empty, [])

operatorExpressionData :: OperatorExpression -> (Text, [Node])
operatorExpressionData :: OperatorExpression -> (Text, [Node])
operatorExpressionData (OpBeginsWith Formula
f)          = (Text
"beginsWith", [Formula -> Node
formulaNode Formula
f])
operatorExpressionData (OpBetween Formula
f1 Formula
f2)         = (Text
"between", [Formula -> Node
formulaNode Formula
f1, Formula -> Node
formulaNode Formula
f2])
operatorExpressionData (OpContainsText Formula
f)        = (Text
"containsText", [Formula -> Node
formulaNode Formula
f])
operatorExpressionData (OpEndsWith Formula
f)            = (Text
"endsWith", [Formula -> Node
formulaNode Formula
f])
operatorExpressionData (OpEqual Formula
f)               = (Text
"equal", [Formula -> Node
formulaNode Formula
f])
operatorExpressionData (OpGreaterThan Formula
f)         = (Text
"greaterThan", [Formula -> Node
formulaNode Formula
f])
operatorExpressionData (OpGreaterThanOrEqual Formula
f)  = (Text
"greaterThanOrEqual", [Formula -> Node
formulaNode Formula
f])
operatorExpressionData (OpLessThan Formula
f)            = (Text
"lessThan", [Formula -> Node
formulaNode Formula
f])
operatorExpressionData (OpLessThanOrEqual Formula
f)     = (Text
"lessThanOrEqual", [Formula -> Node
formulaNode Formula
f])
operatorExpressionData (OpNotBetween Formula
f1 Formula
f2)      = (Text
"notBetween", [Formula -> Node
formulaNode Formula
f1, Formula -> Node
formulaNode Formula
f2])
operatorExpressionData (OpNotContains Formula
f)         = (Text
"notContains", [Formula -> Node
formulaNode Formula
f])
operatorExpressionData (OpNotEqual Formula
f)            = (Text
"notEqual", [Formula -> Node
formulaNode  Formula
f])

instance ToElement MinCfValue where
  toElement :: Name -> MinCfValue -> Element
toElement Name
nm MinCfValue
CfvMin = Name -> [(Name, Text)] -> Element
leafElement Name
nm [Name
"type" Name -> CfvType -> (Name, Text)
forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= CfvType
CfvtMin]
  toElement Name
nm (MinCfValue CfValue
cfv) = Name -> CfValue -> Element
forall a. ToElement a => Name -> a -> Element
toElement Name
nm CfValue
cfv

instance ToElement MaxCfValue where
  toElement :: Name -> MaxCfValue -> Element
toElement Name
nm MaxCfValue
CfvMax = Name -> [(Name, Text)] -> Element
leafElement Name
nm [Name
"type" Name -> CfvType -> (Name, Text)
forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= CfvType
CfvtMax]
  toElement Name
nm (MaxCfValue CfValue
cfv) = Name -> CfValue -> Element
forall a. ToElement a => Name -> a -> Element
toElement Name
nm CfValue
cfv

instance ToElement CfValue where
  toElement :: Name -> CfValue -> Element
toElement Name
nm (CfValue Double
v) = Name -> [(Name, Text)] -> Element
leafElement Name
nm [Name
"type" Name -> CfvType -> (Name, Text)
forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= CfvType
CfvtNum, Name
"val" Name -> Double -> (Name, Text)
forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= Double
v]
  toElement Name
nm (CfPercent Double
v) =
    Name -> [(Name, Text)] -> Element
leafElement Name
nm [Name
"type" Name -> CfvType -> (Name, Text)
forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= CfvType
CfvtPercent, Name
"val" Name -> Double -> (Name, Text)
forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= Double
v]
  toElement Name
nm (CfPercentile Double
v) =
    Name -> [(Name, Text)] -> Element
leafElement Name
nm [Name
"type" Name -> CfvType -> (Name, Text)
forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= CfvType
CfvtPercentile, Name
"val" Name -> Double -> (Name, Text)
forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= Double
v]
  toElement Name
nm (CfFormula Formula
f) =
    Name -> [(Name, Text)] -> Element
leafElement Name
nm [Name
"type" Name -> CfvType -> (Name, Text)
forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= CfvType
CfvtFormula, Name
"val" Name -> Text -> (Name, Text)
forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= Formula -> Text
unFormula Formula
f]

instance ToAttrVal CfvType where
  toAttrVal :: CfvType -> Text
toAttrVal CfvType
CfvtNum = Text
"num"
  toAttrVal CfvType
CfvtPercent = Text
"percent"
  toAttrVal CfvType
CfvtMax = Text
"max"
  toAttrVal CfvType
CfvtMin = Text
"min"
  toAttrVal CfvType
CfvtFormula = Text
"formula"
  toAttrVal CfvType
CfvtPercentile = Text
"percentile"

instance ToElement IconSetOptions where
  toElement :: Name -> IconSetOptions -> Element
toElement Name
nm IconSetOptions {Bool
[CfValue]
IconSetType
_isoShowValue :: Bool
_isoReverse :: Bool
_isoValues :: [CfValue]
_isoIconSet :: IconSetType
_isoShowValue :: IconSetOptions -> Bool
_isoReverse :: IconSetOptions -> Bool
_isoValues :: IconSetOptions -> [CfValue]
_isoIconSet :: IconSetOptions -> IconSetType
..} =
    Name -> [(Name, Text)] -> [Element] -> Element
elementList Name
nm [(Name, Text)]
attrs ([Element] -> Element) -> [Element] -> Element
forall a b. (a -> b) -> a -> b
$ (CfValue -> Element) -> [CfValue] -> [Element]
forall a b. (a -> b) -> [a] -> [b]
map (Name -> CfValue -> Element
forall a. ToElement a => Name -> a -> Element
toElement Name
"cfvo") [CfValue]
_isoValues
    where
      attrs :: [(Name, Text)]
attrs = [Maybe (Name, Text)] -> [(Name, Text)]
forall a. [Maybe a] -> [a]
catMaybes
        [ Name
"iconSet" Name -> Maybe IconSetType -> Maybe (Name, Text)
forall a. ToAttrVal a => Name -> Maybe a -> Maybe (Name, Text)
.=? IconSetType -> IconSetType -> Maybe IconSetType
forall a. Eq a => a -> a -> Maybe a
justNonDef IconSetType
defaultIconSet IconSetType
_isoIconSet
        , Name
"reverse" Name -> Maybe Bool -> Maybe (Name, Text)
forall a. ToAttrVal a => Name -> Maybe a -> Maybe (Name, Text)
.=? Bool -> Maybe Bool
justTrue Bool
_isoReverse
        , Name
"showValue" Name -> Maybe Bool -> Maybe (Name, Text)
forall a. ToAttrVal a => Name -> Maybe a -> Maybe (Name, Text)
.=? Bool -> Maybe Bool
justFalse Bool
_isoShowValue
        ]

instance ToAttrVal IconSetType where
  toAttrVal :: IconSetType -> Text
toAttrVal IconSetType
IconSet3Arrows = Text
"3Arrows"
  toAttrVal IconSetType
IconSet3ArrowsGray = Text
"3ArrowsGray"
  toAttrVal IconSetType
IconSet3Flags = Text
"3Flags"
  toAttrVal IconSetType
IconSet3Signs = Text
"3Signs"
  toAttrVal IconSetType
IconSet3Symbols = Text
"3Symbols"
  toAttrVal IconSetType
IconSet3Symbols2 = Text
"3Symbols2"
  toAttrVal IconSetType
IconSet3TrafficLights1 = Text
"3TrafficLights1"
  toAttrVal IconSetType
IconSet3TrafficLights2 = Text
"3TrafficLights2"
  toAttrVal IconSetType
IconSet4Arrows = Text
"4Arrows"
  toAttrVal IconSetType
IconSet4ArrowsGray = Text
"4ArrowsGray"
  toAttrVal IconSetType
IconSet4Rating = Text
"4Rating"
  toAttrVal IconSetType
IconSet4RedToBlack = Text
"4RedToBlack"
  toAttrVal IconSetType
IconSet4TrafficLights = Text
"4TrafficLights"
  toAttrVal IconSetType
IconSet5Arrows = Text
"5Arrows"
  toAttrVal IconSetType
IconSet5ArrowsGray = Text
"5ArrowsGray"
  toAttrVal IconSetType
IconSet5Quarters = Text
"5Quarters"
  toAttrVal IconSetType
IconSet5Rating = Text
"5Rating"

instance ToElement DataBarOptions where
  toElement :: Name -> DataBarOptions -> Element
toElement Name
nm DataBarOptions {Bool
Int
Color
MaxCfValue
MinCfValue
_dboColor :: Color
_dboMaximum :: MaxCfValue
_dboMinimum :: MinCfValue
_dboShowValue :: Bool
_dboMinLength :: Int
_dboMaxLength :: Int
_dboColor :: DataBarOptions -> Color
_dboMaximum :: DataBarOptions -> MaxCfValue
_dboMinimum :: DataBarOptions -> MinCfValue
_dboShowValue :: DataBarOptions -> Bool
_dboMinLength :: DataBarOptions -> Int
_dboMaxLength :: DataBarOptions -> Int
..} = Name -> [(Name, Text)] -> [Element] -> Element
elementList Name
nm [(Name, Text)]
attrs [Element]
elements
    where
      attrs :: [(Name, Text)]
attrs = [Maybe (Name, Text)] -> [(Name, Text)]
forall a. [Maybe a] -> [a]
catMaybes
        [ Name
"maxLength" Name -> Maybe Int -> Maybe (Name, Text)
forall a. ToAttrVal a => Name -> Maybe a -> Maybe (Name, Text)
.=? Int -> Int -> Maybe Int
forall a. Eq a => a -> a -> Maybe a
justNonDef Int
defaultDboMaxLength Int
_dboMaxLength
        , Name
"minLength" Name -> Maybe Int -> Maybe (Name, Text)
forall a. ToAttrVal a => Name -> Maybe a -> Maybe (Name, Text)
.=? Int -> Int -> Maybe Int
forall a. Eq a => a -> a -> Maybe a
justNonDef Int
defaultDboMinLength Int
_dboMinLength
        , Name
"showValue" Name -> Maybe Bool -> Maybe (Name, Text)
forall a. ToAttrVal a => Name -> Maybe a -> Maybe (Name, Text)
.=? Bool -> Maybe Bool
justFalse Bool
_dboShowValue
        ]
      elements :: [Element]
elements =
        [ Name -> MinCfValue -> Element
forall a. ToElement a => Name -> a -> Element
toElement Name
"cfvo" MinCfValue
_dboMinimum
        , Name -> MaxCfValue -> Element
forall a. ToElement a => Name -> a -> Element
toElement Name
"cfvo" MaxCfValue
_dboMaximum
        , Name -> Color -> Element
forall a. ToElement a => Name -> a -> Element
toElement Name
"color" Color
_dboColor
        ]

toNode :: ToElement a => Name -> a -> Node
toNode :: Name -> a -> Node
toNode Name
nm = Element -> Node
NodeElement (Element -> Node) -> (a -> Element) -> a -> Node
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Name -> a -> Element
forall a. ToElement a => Name -> a -> Element
toElement Name
nm

formulaNode :: Formula -> Node
formulaNode :: Formula -> Node
formulaNode = Name -> Formula -> Node
forall a. ToElement a => Name -> a -> Node
toNode Name
"formula"

instance ToAttrVal TimePeriod where
    toAttrVal :: TimePeriod -> Text
toAttrVal TimePeriod
PerLast7Days = Text
"last7Days"
    toAttrVal TimePeriod
PerLastMonth = Text
"lastMonth"
    toAttrVal TimePeriod
PerLastWeek  = Text
"lastWeek"
    toAttrVal TimePeriod
PerNextMonth = Text
"nextMonth"
    toAttrVal TimePeriod
PerNextWeek  = Text
"nextWeek"
    toAttrVal TimePeriod
PerThisMonth = Text
"thisMonth"
    toAttrVal TimePeriod
PerThisWeek  = Text
"thisWeek"
    toAttrVal TimePeriod
PerToday     = Text
"today"
    toAttrVal TimePeriod
PerTomorrow  = Text
"tomorrow"
    toAttrVal TimePeriod
PerYesterday = Text
"yesterday"

instance ToAttrVal Inclusion where
  toAttrVal :: Inclusion -> Text
toAttrVal = Bool -> Text
forall a. ToAttrVal a => a -> Text
toAttrVal (Bool -> Text) -> (Inclusion -> Bool) -> Inclusion -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Inclusion -> Inclusion -> Bool
forall a. Eq a => a -> a -> Bool
== Inclusion
Inclusive)

instance ToAttrVal NStdDev where
  toAttrVal :: NStdDev -> Text
toAttrVal (NStdDev Int
n) = Int -> Text
forall a. ToAttrVal a => a -> Text
toAttrVal Int
n