plotlyhs 0.2.1 → 0.2.2
raw patch · 4 files changed
+103/−27 lines, 4 filesnew-uploader
Files
- plotlyhs.cabal +4/−4
- src/Graphics/Plotly.hs +1/−1
- src/Graphics/Plotly/Base.hs +38/−4
- src/Graphics/Plotly/GoG.hs +60/−18
plotlyhs.cabal view
@@ -1,5 +1,5 @@ Name: plotlyhs-Version: 0.2.1+Version: 0.2.2 Synopsis: Haskell bindings to Plotly.js Description: Generate web-based plots with the Plotly.js library.@@ -9,11 +9,11 @@ License: MIT License-file: LICENSE Author: Tom Nielsen-Maintainer: tanielsen@gmail.com+Maintainer: jonathan@jonreeve.com build-type: Simple Cabal-Version: >= 1.10-homepage: https://github.com/diffusionkinetics/open/plotlyhs-bug-reports: https://github.com/diffusionkinetics/open/issues+homepage: https://github.com/JonathanReeve/plotlyhs+bug-reports: https://github.com/diffusionkinetics/open/plotlyhs/open/issues category: Graphics, Charts Tested-With: GHC == 7.8.4, GHC == 7.10.2, GHC == 7.10.3, GHC == 8.0.1
src/Graphics/Plotly.hs view
@@ -14,7 +14,7 @@ ) where import Graphics.Plotly.Base as Base - hiding (x,y, _x, _y, _size, _line, size, line)+ hiding (x,y, z, _x, _y, _z, _size, _line, size, line) import Graphics.Plotly.Simple as Simple import Graphics.Plotly.GoG as GoG
src/Graphics/Plotly/Base.hs view
@@ -60,7 +60,14 @@ toJSON = toJSON . intercalate "+" . map (map toLower . dropInitial "Mode" . show) -- | What kind of plot type are we building - scatter (inluding line plots) or bars?-data TraceType = Scatter | Scatter3D | Bar | Mesh3D | Pie | Contour deriving Show+data TraceType = Scatter+ | Scatter3D+ | Bar+ | Box+ | Mesh3D+ | Pie+ | Contour+ deriving Show instance ToJSON TraceType where toJSON = toJSON . map toLower . show@@ -199,6 +206,20 @@ toJSON (HoverPlus elems) = toJSON . intercalate "+" $ (map toLower . dropInitial "Hover" . show) <$> elems toJSON x = toJSON . map toLower . dropInitial "Hover" $ show x +data HoverMode = X | Y | Closest | False | XUnified | YUnified++instance ToJSON HoverMode where+ toJSON mode = toJSON ( showMode mode ) where+ showMode :: HoverMode -> Value+ showMode m = case m of+ X -> "x" + Y -> "y"+ Closest -> "closest"+ Graphics.Plotly.Base.False -> "False"+ XUnified -> "x unified"+ YUnified -> "y unified"++ data HoverOn = HoverPoints | HoverFills deriving (Generic, Show) instance {-# OVERLAPS #-} ToJSON [HoverOn] where@@ -239,6 +260,10 @@ , _hoveron :: Maybe [HoverOn] , _connectgaps :: Maybe Bool + -- Stacked Area Charts+ , _stackgroup :: Maybe Text+ , _fillcolor :: Maybe Text+ -- Pie , _sort :: Maybe Bool @@ -257,8 +282,12 @@ makeLenses ''Trace mkTrace :: TraceType -> Trace-mkTrace tt = Trace Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing tt Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing+mkTrace tt = Trace Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing tt Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing +-- TODO: there must be a way to avoid all that nothing. Something like this?+-- mkTrace :: TraceType -> Trace+-- mkTrace tt = Trace { _tracetype = tt + -- |an empty scatter plot scatter :: Trace scatter = mkTrace Scatter@@ -271,6 +300,10 @@ bars :: Trace bars = mkTrace Bar +-- |an empty box plot+box :: Trace+box = mkTrace Box+ -- |an empty 3D mesh plot mesh3d :: Trace mesh3d = mkTrace Mesh3D@@ -407,6 +440,7 @@ , _height :: Maybe Int , _width :: Maybe Int , _barmode :: Maybe Barmode+ , _hovermode :: Maybe HoverMode , _margin :: Maybe Margin , _font :: Maybe Font , _annotations :: Maybe [Annotation]@@ -414,9 +448,9 @@ makeLenses ''Layout --- |a defaultlayout+-- -- |a defaultlayout defLayout :: Layout-defLayout = Layout Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing+defLayout = Layout Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing instance ToJSON Layout where toJSON = genericToJSON jsonOptions
src/Graphics/Plotly/GoG.hs view
@@ -38,6 +38,8 @@ instance AxisValue Int instance AxisValue Day +instance AxisValue a => AxisValue [a]+ data RGB a = RGB a a a data RGBA a = RGBA a a a a @@ -65,63 +67,74 @@ type family XVal a type family YVal a+type family ZVal a type family CVal a type family SVal a -type instance XVal (x,y,c,s) = x-type instance YVal (x,y,c,s) = y-type instance CVal (x,y,c,s) = c-type instance SVal (x,y,c,s) = s+type instance XVal (x,y,z,c,s) = x+type instance YVal (x,y,z,c,s) = y+type instance ZVal (x,y,z,c,s) = z+type instance CVal (x,y,z,c,s) = c+type instance SVal (x,y,z,c,s) = s data Aes t a = Aes { _x :: a -> XVal t , _y :: a -> YVal t+ , _z :: a -> ZVal t , _color :: Maybe (a -> CVal t) , _size :: Maybe (a -> SVal t) } -aes :: Aes ((), (), (), ()) a-aes = Aes (const ()) (const ()) Nothing Nothing+aes :: Aes ((), (), (), (), ()) a+aes = Aes (const ()) (const ()) (const ()) Nothing Nothing setx :: (AxisValue v)- => Aes (vx,vy,vc,vs) a -> (a -> v) -> Aes (v, vy, vc, vs) a-setx (Aes _ fy fc fs) f = Aes f fy fc fs+ => Aes (vx,vy,vz,vc,vs) a -> (a -> v) -> Aes (v, vy, vz, vc, vs) a+setx (Aes _ fy fz fc fs) f = Aes f fy fz fc fs x :: (AxisValue v)- => Lens (Aes (vx,vy, vc, vs) a) (Aes (v,vy, vc, vs) a) (a -> vx) (a -> v)+ => Lens (Aes (vx,vy, vz, vc, vs) a) (Aes (v,vy, vz, vc, vs) a) (a -> vx) (a -> v) x = lens _x setx sety :: (AxisValue v)- => Aes (vx,vy, vc, vs) a -> (a -> v) -> Aes (vx, v, vc, vs) a-sety (Aes fx _ fc fs) f = Aes fx f fc fs+ => Aes (vx,vy, vz, vc, vs) a -> (a -> v) -> Aes (vx, v, vz, vc, vs) a+sety (Aes fx _ fz fc fs) f = Aes fx f fz fc fs y :: (AxisValue v)- => Lens (Aes (vx,vy, vc, vs) a) (Aes (vx,v, vc, vs) a) (a -> vy) (a -> v)+ => Lens (Aes (vx,vy, vz, vc, vs) a) (Aes (vx,v, vz, vc, vs) a) (a -> vy) (a -> v) y = lens _y sety +setz :: (AxisValue v)+ => Aes (vx,vy, vz, vc, vs) a -> (a -> v) -> Aes (vx, vy, v, vc, vs) a+setz (Aes fx fy _ fc fs) f = Aes fx fy f fc fs ++z :: (AxisValue v)+ => Lens (Aes (vx,vy, vz, vc, vs) a) (Aes (vx,vy, v, vc, vs) a) (a -> vz) (a -> v)+z = lens _z setz+ setcol :: (IsColor v)- => Aes (vx,vy, vc, vs) a -> Maybe (a -> v) -> Aes (vx, vy, v, vs) a-setcol (Aes fx fy _ fs) f = Aes fx fy f fs+ => Aes (vx,vy, vz, vc, vs) a -> Maybe (a -> v) -> Aes (vx, vy, vz, v, vs) a+setcol (Aes fx fy fz _ fs) f = Aes fx fy fz f fs color :: (IsColor v)- => Lens (Aes (vx,vy, vc, vs) a) (Aes (vx,vy,v,vs) a) (Maybe (a -> vc)) (Maybe (a -> v))+ => Lens (Aes (vx,vy, vz, vc, vs) a) (Aes (vx,vy,vz, v,vs) a) (Maybe (a -> vc)) (Maybe (a -> v)) color = lens _color setcol setsize :: (AxisValue v, Num v)- => Aes (vx,vy, vc, vs) a -> Maybe (a -> v) -> Aes (vx, vy, vc, v) a-setsize (Aes fx fy fc _) = Aes fx fy fc+ => Aes (vx,vy, vz, vc, vs) a -> Maybe (a -> v) -> Aes (vx, vy, vz, vc, v) a+setsize (Aes fx fy fz fc _) = Aes fx fy fz fc size :: (AxisValue v, Num v)- => Lens (Aes (vx,vy, vc, vs) a) (Aes (vx,vy,vc,v) a) (Maybe (a -> vs)) (Maybe (a -> v))+ => Lens (Aes (vx,vy, vz, vc, vs) a) (Aes (vx,vy,vz, vc,v) a) (Maybe (a -> vs)) (Maybe (a -> v)) size = lens _size setsize @@ -144,9 +157,38 @@ & Plot.y ?~ map (toJSON . _y a) xs & Plot.mode ?~ [Plot.Lines] +-- | Render an Aes (styling header) <a> and data <xs> into a `Plot.Trace box`+-- e.g. `hbox myAes [1,1,4,5,6,9,9]`+--+hbox :: (AxisValue (XVal t), Num (XVal t))+ => Aes t a+ -> [a]+ -> Plot.Trace+hbox a xs = Plot.box+ & Plot.x ?~ map (toJSON . _x a) xs+ & Plot.mode ?~ [Plot.Lines]++-- | Render an Aes (styling header) <a> and data <ys> into a `Plot.Trace box`+-- e.g. `vbox myAes [1,1,4,5,6,9,9]`+--+vbox :: (AxisValue (YVal t), Num (YVal t))+ => Aes t a+ -> [a]+ -> Plot.Trace+vbox a ys = Plot.box+ & Plot.y ?~ map (toJSON . _y a) ys+ & Plot.mode ?~ [Plot.Lines]+ hbars :: (AxisValue (XVal t), AxisValue (YVal t)) => Aes t a -> [a] -> Plot.Trace hbars a xs = Plot.bars & Plot.x ?~ map (toJSON . _x a) xs & Plot.y ?~ map (toJSON . _y a) xs & Plot.orientation ?~ Plot.Horizontal +hcontour :: (AxisValue (XVal t), AxisValue (YVal t), AxisValue (ZVal t))+ => Aes t a -> [a] -> Plot.Trace+hcontour a xs = Plot.contour+ & Plot.x ?~ map (toJSON . _x a) xs+ & Plot.y ?~ map (toJSON . _y a) xs+ & Plot.z ?~ map (toJSON . _z a) xs+ & Plot.orientation ?~ Plot.Horizontal