Copyright | 2015 Anders Jellinggaard |
---|---|
License | MIT |
Maintainer | anders.jel@gmail.com |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
Haskell mini-language to create HTML documents with a mixture of markup and plots based on the C3.js library.
See the github page for an introduction.
Notes:
- The generated documents relies on https://cdnjs.com/ to serve C3.js and friends.
- This library should not be used on a public facing server with input supplied by the user. The library has not been properly vetted for security issues.
- data Doc
- text :: String -> Doc
- header :: String -> Doc
- markdown :: String -> Doc
- html :: Html -> Doc
- render :: Doc -> ByteString
- renderToFile :: FilePath -> Doc -> IO ()
- data Column a
- col :: String -> (a -> Double) -> Column a
- col' :: ToObj b => String -> (a -> b) -> Column a
- plot :: Foldable f => f a -> Column a -> [Column a] -> Doc
- plot' :: Foldable f => f a -> Column a -> [Column a] -> [Prop] -> Doc
- rawPlot :: [Prop] -> Doc
- linspace :: Fractional a => a -> a -> Int -> [a]
- (/:) :: ToObj a => String -> a -> Prop
- javascript :: String -> Obj
Documentation
Base type representing a document. This type allows composition via the
Monoid
instance.
Markup
Creates a Doc
representing plain text. The string will be properly
escaped.
header :: String -> Doc Source
Creates a Doc
representing <h1>
header tag. The string will be
properly escaped.
Output
render :: Doc -> ByteString Source
Render a document to a lazy ByteString
.
renderToFile :: FilePath -> Doc -> IO () Source
If the file exists, it will be overwritten.
Plotting
col :: String -> (a -> Double) -> Column a Source
Data sets are supplied to plot
as a collection of elements of type a.
This function sets up a Column
, which knows how to extract one Double
value from each value of type a in the collection.
The first argument to col
is the header of the column, which is used in the
legend of the plot.
The simplest plot that can be created consist of one column for the x values and one column for the y values.
-- Plot x² vs x. plot [1..10] (col "x" id) [col "x²" $ \x -> x*x]
plot :: Foldable f => f a -> Column a -> [Column a] -> Doc Source
plot ds x ys
Plots the data in ds using the column x for the values on the x-axis
and with one line on the plot for each column in ys. See also col
.
plot' :: Foldable f => f a -> Column a -> [Column a] -> [Prop] -> Doc Source
Same as plot
, but takes a final argument which is merged with the
configuration object supplied to C3.js. This allows the
caller to customize the plot.
-- Plot x² vs x with the points hidden. plot' [1..10] (col "x" id) [col "x²" $ \x -> x*x] $ ["point" /: ["show" /: False]]
See http://c3js.org/reference.html for the many properties that can be used here.
Utilities
linspace :: Fractional a => a -> a -> Int -> [a] Source
linspace
x y n generates n evenly spaced values from x to y.
Re-exports from Text.DocL.Javascript
(/:) :: ToObj a => String -> a -> Prop Source
Constructs a Prop
.
>>>
toObj ["tail" /: True, "nose" /: "wet"]
{"nose":"wet","tail":true}
javascript :: String -> Obj Source
Raw unescaped javascript.
>>>
toObj ["speak" /: javascript "function(){alert('Woof!');}"]
{"speak":function(){alert('Woof!');}}