-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Declarative visualization on a web browser with DSL approach. -- -- A library for visualization on a web browser. This works as a DSL that -- generates JavaScript source code working with D3.js -- (http:d3js.org/) library. -- -- You can compose operations with a typed DSL with Haskell's abstraction -- power. -- -- This is still an alpha version, and the structure may be changed in -- the near future. -- -- -- --
--   import Control.Monad
--   import qualified Data.Text as T
--   import D3JS
--   
--   test :: Int -> IO ()
--   test n = T.writeFile "generated.js" $ reify (box "#div1" (300,300) >>= bars n 300 (Data1D [100,20,80,60,120]))
--   
-- -- You can just put the JavaScript file in an HTML file like the -- following to show a chart. -- --
--   <html>
--   <head>
--     <title>Chart</title>
--   </head>
--   <body>
--     <div id='div1'></div>
--     <script charset='utf-8' src='http://d3js.org/d3.v3.min.js'></script>
--     <script charset='utf-8' src='generated.js'></script>
--   </body>
--   </html>
--   
-- -- See D3JS.Example for more examples. @package d3js @version 0.1.0.0 module D3JS.Type -- | This represents a method chain with an initial type of a and -- a final type of b Chains are composable by functions in -- Control.Category module. See D3JS.Chart for examples. data Chain a b Val :: Var -> Chain () b Val' :: b -> Chain () b Val'' :: Var' b -> Chain () b Func :: JSFunc a params b -> Chain a b Concat :: Chain c b -> Chain a c -> Chain a b Nil :: Chain a a type Var = Text type Selector = Text data Data1D Data1D :: [Double] -> Data1D data Data2D Data2D :: [(Double, Double)] -> Data2D data Selection Selection :: Selection data SelData a SelData :: SelData a data Transition Transition :: Transition -- | Instances of Reifiable can generate a JavaScript code fragment. class Reifiable a reify :: Reifiable a => a -> Text -- | Used just as a tag for typing method chains. Used in D3JS.Func. class Sel a -- | Used just as a tag for typing method chains. Used in D3JS.Func. class Sel2 a -- | Function call data JSFunc a c b JSFunc :: FuncName -> [JSParam] -> JSFunc a c b type FuncName = Text -- | Parameter for a function call data JSParam ParamVar :: Var -> JSParam PText :: Text -> JSParam PDouble :: Double -> JSParam PFunc :: FuncDef -> JSParam -- | Function definition used for a callback. data FuncDef FuncTxt :: Text -> FuncDef FuncExp :: (NumFunc r) -> FuncDef -- | Representation of JavaScript function for a callback. data NumFunc r NInt :: Int -> NumFunc Int NDouble :: Double -> NumFunc Double Add :: NumFunc r -> NumFunc r -> NumFunc r Subt :: NumFunc r -> NumFunc r -> NumFunc r Mult :: NumFunc r -> NumFunc r -> NumFunc r Div :: NumFunc r -> NumFunc r -> NumFunc r Index :: Int -> NumFunc [r] -> NumFunc r Field :: Text -> NumFunc a -> NumFunc r NVar :: Var -> NumFunc r DataParam :: NumFunc r -- | This should not be used directly by users. Users should use -- assign to get a variable instead. data Var' dat Var' :: Var -> Var' dat instance Sel2 (Chain () b) instance Sel2 (SelData a) instance Sel2 Selection instance Sel (SelData a) instance Sel Selection instance Category Chain -- | This module defines original functions of D3.js, as well as some -- low-level helper functions. module D3JS.Func -- | d3 object in D3.js d3Root :: Chain () Selection -- | select() in D3.js select :: Selector -> Chain Selection Selection -- | selectAll() selectAll :: Sel2 a => Selector -> Chain a Selection -- | data() in D3.js. Assigns new data to selection. dataD3 :: Var' r -> Chain Selection (SelData r) -- | enter() enter :: Chain (SelData r) (SelData r) -- | exit() exit :: Sel a => Chain a a -- | append() appendD3 :: Text -> Chain (SelData a) (SelData a) attr :: Text -> JSParam -> Chain a a attrf :: Text -> JSParam -> Chain a a attrt :: Text -> Text -> Chain a a attrd :: Text -> Double -> Chain a a style :: Text -> Text -> Chain a a -- | classed(). Take a list of classes as an argument. classed :: [Text] -> Chain a a property :: Text -> Text -> Chain a a text :: Text -> Chain a a html :: Text -> Chain a a width :: Double -> Chain a a height :: Double -> Chain a a transform :: Text -> Chain a a transform' :: Double -> Double -> Double -> Double -> Double -> Chain a a opacity :: Sel a => Double -> Chain a a fill :: Sel a => Text -> Chain a a -- | transition() transition :: Sel2 a => Chain a Transition -- | trasition().delay(time) transition' :: Sel2 a => Double -> Chain a Transition -- | delay() delay :: JSParam -> Chain Transition Transition func :: FuncName -> [JSParam] -> Chain a b funct1 :: FuncName -> Text -> Chain a b funcd1 :: FuncName -> Double -> Chain a b -- | Function that does not change type in a method chain. func' :: FuncName -> [JSParam] -> Chain a a funcTxt :: Text -> JSParam funcExp :: NumFunc r -> JSParam module D3JS.Reify show' :: Show a => a -> Text surround :: Text -> Text instance Reifiable (NumFunc r) instance Reifiable JSParam instance Reifiable (JSFunc a c b) instance Reifiable Data2D instance Reifiable Data1D instance Reifiable (Chain a b) instance Reifiable Var module D3JS.Syntax -- | St (which means Statement) monad represents JavaScript statements. -- D3JS.Chart uses St monad extensively. type St r = RWS () Text Int r getUniqueNum :: St Int execute :: Chain () b -> St () -- | d[0] as a user-defined function. idx0 :: NumFunc r -- | d[1] as a user-defined function. idx1 :: NumFunc r -- | d.x as a user-defined function. _x :: NumFunc r -- | d.y as a user-defined function. _y :: NumFunc r class Assignable a where assign chain = do { v@(Var' n) <- newVar; tell $ concat ["var ", n, " = ", reify chain, ";"]; return v } newVar :: Assignable a => St (Var' a) assign :: Assignable a => Chain () a -> St (Var' a) newVar' :: Text -> St (Var' a) instance Assignable Selection instance Assignable (SelData Data2D) instance Assignable Data2D instance Reifiable (St r) -- | This modules provides high-level functions for drawing common charts, -- such as bar charts and scatter plots. Those functions also exemplify -- how to compose primitive functions to achieve complex drawing. This -- module will be expanded in the near future. module D3JS.Chart -- | box parent (w,h) makes an SVG container in a parent element with -- dimension w x h. box :: Selector -> (Double, Double) -> St (Var' Selection) bars :: Int -> Double -> Data1D -> Var' Selection -> St () scatter :: Data2D -> Var' Selection -> St (Var' (SelData Data2D)) -- | Add rectangles with an array of objects {x: x, y: y, width: w , -- height: h} addRect :: Sel2 a => Var' RectData -> Chain a (SelData RectData) mkRectData :: Double -> Data1D -> RectData addCircles :: Sel2 a => Var' Data2D -> Chain a (SelData Data2D) -- | disappear delay duration disappear :: Sel2 a => Double -> Double -> Var' a -> St () addFrame :: Sel2 a => (Double, Double) -> (Double, Double) -> Var' a -> St () data RectData RectData :: [(Double, Double, Double, Double)] -> RectData instance Assignable RectData instance Reifiable RectData -- | You only need to import this module to use this library. This module -- exports all modules except D3JS.Example module D3JS module D3JS.Example -- | Scatter plot with a frame. Generate 'test1.html' file. test1 :: IO () -- | Scatter plot with dissolving transition. Generate 'generated.js' file. -- -- Scatter plot with a frame. Generate 'test1.html' file. test2 :: IO () -- | Bar chart. Generate 'generated.js' file. -- -- Scatter plot with a frame. Generate 'test1.html' file. test3 :: IO () -- | Output a single excutable HTML file with embedded JS code. writeToHtml :: Reifiable a => FilePath -> a -> IO ()