module Graphics.Plotly.Simple where
import Data.Aeson
import Data.Text (Text)
import Lens.Micro
import Graphics.Plotly.Base
scatterPlot :: (ToJSON a, ToJSON b) => [(a, b)] -> Trace
scatterPlot xys = scatter
& x ?~ fmap (toJSON . fst) xys
& y ?~ fmap (toJSON . snd) xys
& mode ?~ [Markers]
linePlot :: (ToJSON a, ToJSON b) => [(a, b)] -> Trace
linePlot xys = scatter
& x ?~ fmap (toJSON . fst) xys
& y ?~ fmap (toJSON . snd) xys
& mode ?~ [Lines]
hbarChart :: [(Text, Double)] -> Trace
hbarChart tvs = bars
& y ?~ fmap (toJSON . fst) tvs
& x ?~ fmap (toJSON . snd) tvs
& orientation ?~ Horizontal
vbarChart :: [(Text, Double)] -> Trace
vbarChart tvs = bars
& x ?~ fmap (toJSON . fst) tvs
& y ?~ fmap (toJSON . snd) tvs
& orientation ?~ Vertical
fanPlot :: Double -> [(Double, (Double, Double))] -> Trace
fanPlot sdCount tmnsds = scatter
& x ?~ fmap toJSON xs
& y ?~ fmap toJSON ys
& fill ?~ ToZeroY
where
xs = fmap fst tmnsds ++ reverse (fmap fst tmnsds)
ys = fmap ((\(m, sd) -> m + sdCount * sd) . snd) tmnsds
++ reverse (fmap ((\(m, sd) -> m - sdCount * sd) . snd) tmnsds)