module Graphics.Vega.VegaLite.Data
( DataValue(..)
, DataValues(..)
, dataValueSpec
, dataValuesSpecs
) where
import qualified Data.Aeson as A
import qualified Data.Text as T
import Data.Aeson (toJSON)
import Graphics.Vega.VegaLite.Specification (VLSpec)
import Graphics.Vega.VegaLite.Time
( DateTime
, dateTimeSpec
)
data DataValue
= Boolean Bool
| DateTime [DateTime]
| Number Double
| Str T.Text
| NullValue
dataValueSpec :: DataValue -> VLSpec
dataValueSpec :: DataValue -> VLSpec
dataValueSpec (Boolean Bool
b) = Bool -> VLSpec
forall a. ToJSON a => a -> VLSpec
toJSON Bool
b
dataValueSpec (DateTime [DateTime]
dt) = [DateTime] -> VLSpec
dateTimeSpec [DateTime]
dt
dataValueSpec (Number Double
x) = Double -> VLSpec
forall a. ToJSON a => a -> VLSpec
toJSON Double
x
dataValueSpec (Str Text
t) = Text -> VLSpec
forall a. ToJSON a => a -> VLSpec
toJSON Text
t
dataValueSpec DataValue
NullValue = VLSpec
A.Null
data DataValues
= Booleans [Bool]
| DateTimes [[DateTime]]
| Numbers [Double]
| Strings [T.Text]
dataValuesSpecs :: DataValues -> [VLSpec]
dataValuesSpecs :: DataValues -> [VLSpec]
dataValuesSpecs (Booleans [Bool]
bs) = (Bool -> VLSpec) -> [Bool] -> [VLSpec]
forall a b. (a -> b) -> [a] -> [b]
map Bool -> VLSpec
forall a. ToJSON a => a -> VLSpec
toJSON [Bool]
bs
dataValuesSpecs (DateTimes [[DateTime]]
dtss) = ([DateTime] -> VLSpec) -> [[DateTime]] -> [VLSpec]
forall a b. (a -> b) -> [a] -> [b]
map [DateTime] -> VLSpec
dateTimeSpec [[DateTime]]
dtss
dataValuesSpecs (Numbers [Double]
xs) = (Double -> VLSpec) -> [Double] -> [VLSpec]
forall a b. (a -> b) -> [a] -> [b]
map Double -> VLSpec
forall a. ToJSON a => a -> VLSpec
toJSON [Double]
xs
dataValuesSpecs (Strings [Text]
ss) = (Text -> VLSpec) -> [Text] -> [VLSpec]
forall a b. (a -> b) -> [a] -> [b]
map Text -> VLSpec
forall a. ToJSON a => a -> VLSpec
toJSON [Text]
ss