module Web.Lightning.Plots.Line
(
LinePlot(..)
, Visualization (..)
, linePlot
)
where
import Control.Monad.Reader
import Data.Aeson
import Data.Default.Class
import qualified Data.Text as T
import qualified Web.Lightning.Routes as R
import Web.Lightning.Types.Lightning
import Web.Lightning.Types.Visualization (Visualization (..))
import Web.Lightning.Utilities
data LinePlot =
LinePlot { lpSeries :: [[Double]]
, lpIndex :: Maybe [Int]
, lpColor :: Maybe [Int]
, lpGroup :: Maybe [Int]
, lpThickness :: Maybe [Int]
, lpXaxis :: Maybe T.Text
, lpYaxis :: Maybe T.Text
, lpZoom :: Maybe Bool
}
deriving (Show, Eq)
instance Default LinePlot where
def = LinePlot [[]] Nothing Nothing Nothing Nothing Nothing Nothing (Just True)
instance ToJSON LinePlot where
toJSON (LinePlot ss is cs gs t xa ya z) =
omitNulls [ "series" .= ss
, "index" .= is
, "color" .= cs
, "group" .= gs
, "thickness" .= t
, "xaxis" .= xa
, "yaxis" .= ya
, "zoom" .= z
]
instance ValidatablePlot LinePlot where
validatePlot (LinePlot s i c g t xa ya z) = do
i' <- validateIndex i
c' <- validateColor c
t' <- validateThickness t
return $ LinePlot s i' c' g t' xa ya z
linePlot :: Monad m => LinePlot
-> LightningT m Visualization
linePlot linePlt = do
url <- ask
viz <- sendPlot "line" linePlt R.plot
return $ viz { vizBaseUrl = Just url }