module Web.Lightning.Plots.Matrix
(
MatrixPlot(..)
, Visualization (..)
, matrixPlot
)
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 MatrixPlot =
MatrixPlot { mpMatrix :: [[Double]]
, mpRowLabels :: Maybe [T.Text]
, mpColLabels :: Maybe [T.Text]
, mpColorMap :: Maybe T.Text
, mpNumbers :: Maybe Bool
}
deriving (Show, Eq)
instance Default MatrixPlot where
def = MatrixPlot [[]] Nothing Nothing Nothing (Just False)
instance ToJSON MatrixPlot where
toJSON (MatrixPlot m rls cls cm nbrs) =
omitNulls [ "matrix" .= m
, "rowLabels" .= rls
, "colLabels" .= cls
, "colormap" .= cm
, "numbers" .= nbrs
]
instance ValidatablePlot MatrixPlot where
validatePlot (MatrixPlot mtx rlbl clbl cm nbr) = do
mtx' <- validateConn mtx
cm' <- validateColorMap cm
return $ MatrixPlot mtx' rlbl clbl cm' nbr
matrixPlot :: Monad m => MatrixPlot
-> LightningT m Visualization
matrixPlot matrixPlt = do
url <- ask
viz <- sendPlot "matrix" matrixPlt R.plot
return $ viz { vizBaseUrl = Just url }