module Web.Lightning.Plots.Map
(
MapPlot(..)
, Visualization (..)
, mapPlot
)
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 MapPlot =
MapPlot { mppRegions :: [T.Text]
, mppWeights :: [Double]
, mppColorMap :: Maybe T.Text
}
deriving (Show, Eq)
instance Default MapPlot where
def = MapPlot [] [] Nothing
instance ToJSON MapPlot where
toJSON (MapPlot rs vs cm) =
omitNulls [ "regions" .= rs
, "values" .= vs
, "colormap" .= cm
]
instance ValidatablePlot MapPlot where
validatePlot (MapPlot r v cm) = do
r' <- validateRegion r
cm' <- validateColorMap cm
return $ MapPlot r' v cm'
mapPlot :: Monad m => MapPlot
-> LightningT m Visualization
mapPlot mapPlt = do
url <- ask
viz <- sendPlot "map" mapPlt R.plot
return $ viz { vizBaseUrl = Just url }