/haskell-text-and-plots

Haskell EDSL to create documents with plots based on the C3.js library.

Primary LanguageHaskellMIT LicenseMIT

The text-and-plots package

text-and-plots is a Haskell EDSL to create documents with embedded plots.

Here is an example:

import Text.DocL
import Data.Foldable (fold)

main = renderToFile "out.html" $ fold
  [ header "Stirling's approximation"
  , text $ fold
      [ "A simple approximation of the factorial function is given by "
      , "Stirling's approximation." ]
  , plot [1..50] (col "n" id)
      [ col "log(n!)" $ \n -> sum $ map log [1..n]
      , col "n log n - n" $ \n -> n * log n - n ]
  ]

The above code produces the output:

Stirling's approximation

A simple approximation of the factorial function is given by Stirling's approximation.

a plot

Details

The render function converts the document to HTML with plots based on the C3.js libray. text-and-plots does not try to wrap every aspect of the C3.js library, but instead exposes it directly if needed.