module Web.Lightning.Plots.Circle
( CirclePlot(..)
, Visualization (..)
, circlePlot
) 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 CirclePlot =
CirclePlot {
cpConn :: [[Double]]
, cpGroup :: Maybe [Int]
, cpColor :: Maybe [Int]
, cpLabels :: Maybe [T.Text]
}
deriving (Show, Eq)
instance Default CirclePlot where
def = CirclePlot [[]] Nothing Nothing Nothing
instance ToJSON CirclePlot where
toJSON (CirclePlot conn gs cs ls) =
omitNulls [ "links" .= getLinks conn
, "nodes" .= getNodes conn
, "group" .= gs
, "color" .= cs
, "labels" .= ls
]
instance ValidatablePlot CirclePlot where
validatePlot (CirclePlot conn grp cs lbl) = do
conn' <- validateConn conn
cs' <- validateColor cs
return $ CirclePlot conn' grp cs' lbl
circlePlot :: Monad m => CirclePlot
-> LightningT m Visualization
circlePlot circlePlt = do
url <- ask
viz <- sendPlot "circle" circlePlt R.plot
return $ viz { vizBaseUrl = Just url }