{-# LANGUAGE OverloadedStrings #-}
module Graphics.Vega.VegaLite.Theme
( theme
, defaultConfig
, Config (..)
) where
import Data.Maybe (catMaybes)
import Graphics.Vega.VegaLite
import qualified Data.Text as T
data Config = Config { configFontSize :: Maybe Double
, configFont :: T.Text
, configLabelFont :: T.Text
, configAxisColor :: T.Text
, configHeight :: Maybe Double
, configWidth :: Maybe Double
, configLabelAngle :: Maybe Double
}
defaultConfig :: Config
defaultConfig = Config { configFontSize = Nothing
, configFont = "Arial"
, configLabelFont = "Arial"
, configAxisColor = "#000000"
, configHeight = Nothing
, configWidth = Nothing
, configLabelAngle = Nothing
}
theme :: Config -> [ConfigureSpec] -> (VLProperty, VLSpec)
theme c = configure
. configuration (ViewStyle $ viewConfig c)
. configuration (LegendStyle $ legendConfig c)
. configuration (TitleStyle $ titleConfig c)
. configuration (Axis $ axisConfig (c { configLabelAngle = Nothing }))
. configuration (AxisX $ axisConfig c)
. configuration (AxisY $ axisConfig (c { configLabelAngle = Nothing}))
viewConfig :: Config -> [ViewConfig]
viewConfig c = catMaybes
[ fmap ViewContinuousHeight $ configHeight c
, fmap ViewContinuousWidth $ configWidth c
, Just $ ViewStrokeOpacity 0
]
legendConfig :: Config -> [LegendConfig]
legendConfig c = catMaybes
[ fmap LeLabelFontSize $ configFontSize c
, fmap LeTitleFontSize $ configFontSize c
]
titleConfig :: Config -> [TitleConfig]
titleConfig c = catMaybes
[ fmap TFontSize $ configFontSize c
, Just $ TFont $ configFont c
, Just $ TColor "#000000"
, Just $ TFontWeight Normal
]
axisConfig :: Config -> [AxisConfig]
axisConfig c = catMaybes
[ Just $ Grid False
, Just $ DomainColor "#000000"
, Just $ LabelFont $ configLabelFont c
, fmap LabelFontSize $ configFontSize c
, fmap LabelAngle $ configLabelAngle c
, Just $ TickColor $ configAxisColor c
, Just $ TitleFont $ configFont c
, fmap TitleFontSize $ configFontSize c
, Just $ TitleFontWeight Normal
]