diff --git a/README.md b/README.md
index daec7a2..3d604b4 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,7 @@ Experimental bindings for generating Bokeh Graphs in Haskell. Project originally
## Roadmap
- 1. *Safe* helper functions for inserting lines, possibly monoidal
+ 1. ~~*Safe* helper functions for inserting lines, possibly monoidal~~
2. More models, particularly glyphs
@@ -10,4 +10,6 @@ Experimental bindings for generating Bokeh Graphs in Haskell. Project originally
4. Better file generation, plot composition
- 5. Performace optimizations, type-safety improvements
+ 5. Performace/Space efficiency optimizations, type-safety improvements.
+
+ 6. As a subproject of the above, implementing the Python implementations of DataSource and DataSpec in a typesafe manner.
diff --git a/bokeHS.cabal b/bokeHS.cabal
index d15aeff..a3e5219 100644
--- a/bokeHS.cabal
+++ b/bokeHS.cabal
@@ -39,6 +39,7 @@ library
other-modules: Graphics.BokeHS.Serialize
Graphics.BokeHS.Models
+ Graphics.BokeHS.CDS
Graphics.BokeHS.Helpers
Graphics.BokeHS.Prim
Graphics.BokeHS.GlyphConfig
diff --git a/example.hs b/example.hs
index 0e2e98f..463d9e3 100644
--- a/example.hs
+++ b/example.hs
@@ -1,20 +1,26 @@
+{-# LANGUAGE FlexibleInstances #-}
+{-# LANGUAGE MultiParamTypeClasses #-}
+{-# LANGUAGE DataKinds #-}
{-# LANGUAGE OverloadedStrings #-}
+
import Graphics.BokeHS
-import Data.ByteString.Lazy as BS
+import qualified Data.ByteString.Lazy as BS
import Control.Monad
import System.Process
+import Data.Scientific
+import GHC.TypeLits
myPlot :: Plot
myPlot = plt
- $> addLinearAxis BBelow
- |> addLinearAxis BLeft
- |> addLine myData2 fst snd def
+ %> addLinearAxis BBelow
+ %> addLinearAxis BLeft
+ %> addLine myData2 (Key :: Key "x") (Key :: Key "y") def
{ lineColor = red
, lineAlpha = 0.6
, lineWidth = 6
, lineCap = Rounded
}
- |> addLine myData fst snd def
+ %> addLine myData (Key :: Key "x") (Key :: Key "y2") def
{ lineColor = green
, lineDash = DotDash
, lineWidth = 3
@@ -33,32 +39,14 @@ main = do
BS.writeFile "sample.html" plotHTML
void $ system "firefox --new-window sample.html"
-myData :: [(BNum, BNum)]
-myData = Prelude.zip xcols ycols
- where
- xcols = [-0.5,
- 1.8333333333333335,
- 4.166666666666667,
- 6.5,
- 8.833333333333334,
- 11.166666666666668,
- 13.5,
- 15.833333333333336,
- 18.166666666666668,
- 20.5]
- ycols = [2.75,
- 3.916666666666667,
- 5.083333333333334,
- 6.25,
- 10.416666666666667,
- 2.583333333333334,
- 7.75,
- 5.916666666666668,
- 19.083333333333334,
- 13.25]
+-- Automatic deriving for record types
+
+data CustomData = CD
+ { x :: Scientific
+ , y :: Scientific }
-myData2 :: [(BNum, BNum)]
-myData2 = Prelude.zip xcols ycols
+myData2 :: [CustomData]
+myData2 = zipWith CD xcols ycols
where
xcols = [-0.5,
1.8333333333333335,
@@ -80,3 +68,35 @@ myData2 = Prelude.zip xcols ycols
11.916666666666668,
13.083333333333334,
14.25]
+
+-- Or define your own:
+
+instance HasColumn (Scientific, Double) "x" Scientific where
+ getValue _ (x, y) = x
+
+instance HasColumn (Scientific, Double) "y2" Scientific where
+ getValue _ (x, y) = fromFloatDigits y
+
+myData :: [(Scientific, Double)]
+myData = zip xcols ycols
+ where
+ xcols = [-0.5,
+ 1.8333333333333335,
+ 4.166666666666667,
+ 6.5,
+ 8.833333333333334,
+ 11.166666666666668,
+ 13.5,
+ 15.833333333333336,
+ 18.166666666666668,
+ 20.5]
+ ycols = [2.75,
+ 3.916666666666667,
+ 5.083333333333334,
+ 6.25,
+ 10.416666666666667,
+ 2.583333333333334,
+ 7.75,
+ 5.916666666666668,
+ 19.083333333333334,
+ 13.25]
diff --git a/sample.html b/sample.html
index 350da20..82cd645 100644
--- a/sample.html
+++ b/sample.html
@@ -18,7 +18,7 @@