plot-light-examples 0.2.0.0 → 0.3.0.0
raw patch · 4 files changed
+98/−58 lines, 4 filesdep ~plot-lightnew-component:exe:histogram
Dependency ranges changed: plot-light
Files
- app/histogram/Main.hs +19/−0
- app/scatter/Main.hs +12/−8
- app/timeseries/Main.hs +49/−46
- plot-light-examples.cabal +18/−4
+ app/histogram/Main.hs view
@@ -0,0 +1,19 @@+module Main where++import Control.Monad (forM_)++import qualified Data.Colour as C+import qualified Data.Colour.Names as C+import Data.Scientific (Scientific, toRealFloat)+import qualified Data.Text as T +import qualified Data.Text.IO as T (writeFile)+import Text.Blaze.Svg.Renderer.String (renderSvg)++import Graphics.Rendering.Plot.Light+import Graphics.Rendering.Plot.Light.Internal.Geometry++++main = print "hello!"++
app/scatter/Main.hs view
@@ -14,36 +14,40 @@ import Data.Parsers ++ xPlot = 400 yPlot = 300-fnameOut = "data/scatter-1.svg"+fnameOut = "data/scatter-2.svg" fdat = FigureData xPlot yPlot 0.1 0.8 0.1 0.9 10 dats = zipWith LabeledPoint p_ l_ where l_ = [-5, -4 .. ]- p_ = zipWith Point [4,7,12,23,90,34,24,5,6,12,3] [43,23,1,23,8,11,17,25,4,5]+ p_ = zipWith Point [46,30,4,7,73,12,23,90,34,24,5,6,12,3,55,61] [20,35,43,23,20,1,23,8,11,17,25,4,5,26, 30] -spdata = ScatterPointData Circle 3 3 C.red+spdata = ScatterPointData Plus 3 3 C.black 0.8 +main :: IO () main = do let frameTo = frameFromFigData fdat frameFrom = frameFromPoints $ _lp <$> dats vmin = minimum $ _lplabel <$> dats vmax = maximum $ _lplabel <$> dats - f l sz = 10/(1 + exp(-(0.3 * x)))+ f l sz = 15 / (1 + exp(- (0.3 * x)) ) where x = l + sz- g _ w = w- h l col = C.blend l' C.blue col+ g l w = w * (1 + l / (1 + abs l))+ h l col = C.blend l' C.red col where l' = (l - vmin)/(vmax - vmin)+ i l alp = alp * ( 1 + l / (1 + abs l)) dats' = moveLabeledPointBwFrames frameFrom frameTo False True <$> dats svg_t = svgHeader xPlot yPlot $ do axes fdat frameFrom 2 C.black 10 10- scatterLP f g h spdata dats'- scatterLPBar fdat 50 vmin vmax 3 TopRight 100 f g h spdata+ scatterLP f g h i spdata dats'+ scatterLPBar fdat 50 vmin vmax 3 TopRight 100 f g h i spdata -- putStrLn $ renderSvg svg_t T.writeFile fnameOut $ T.pack $ renderSvg svg_t
app/timeseries/Main.hs view
@@ -4,7 +4,7 @@ -- import Control.Arrow ((***), (&&&)) import Graphics.Rendering.Plot.Light-import Graphics.Rendering.Plot.Light.PlotTypes+-- import Graphics.Rendering.Plot.Light.PlotTypes import qualified Data.Attoparsec.Text as A import qualified Attoparsec.Time.Text as AT@@ -17,7 +17,7 @@ import Control.Applicative ((<|>)) import Data.Time (Day, TimeOfDay) -import Data.Parsers+-- import Data.Parsers fname = "data/forex" @@ -27,40 +27,41 @@ fdat = FigureData xPlot yPlot 0.1 0.9 0.1 0.85 10 +main = print "timeseries example unavailable for now" -main = do- dat <- T.readFile fname- let pd = A.parseOnly parseFxDataset dat- case pd of Left e -> error e- Right d -> - do- let- lps = tspToLP fhi (\_ x -> x) <$> d- -- figure = tsAxis fdat fop fcl fhi flo 1 C.black (-45) Nothing Nothing lps - figure = tsAxis' fdat flo fhi C.magenta lps- svg_t = svgHeader xPlot yPlot figure- -- putStrLn $ renderSvg svg_t- T.writeFile fnameOut $ T.pack $ renderSvg svg_t- where- fhi = toFloat . rateHigh- flo = toFloat . rateLow- fop = toFloat . rateOpen- fcl = toFloat . rateClose +-- main = do+-- dat <- T.readFile fname+-- let pd = A.parseOnly parseFxDataset dat+-- case pd of Left e -> error e+-- Right d -> +-- do+-- let+-- lps = tspToLP fhi (\_ x -> x) <$> d+-- -- figure = tsAxis fdat fop fcl fhi flo 1 C.black (-45) Nothing Nothing lps +-- figure = tsAxis' fdat flo fhi C.magenta lps+-- svg_t = svgHeader xPlot yPlot figure+-- -- putStrLn $ renderSvg svg_t+-- T.writeFile fnameOut $ T.pack $ renderSvg svg_t+-- where+-- fhi = toFloat . rateHigh+-- flo = toFloat . rateLow+-- fop = toFloat . rateOpen+-- fcl = toFloat . rateClose -avgTs :: FxRow Scientific -> Float-avgTs x = 0.5 * (h + l) where- h = toFloat (rateHigh x)- l = toFloat (rateLow x) +-- avgTs :: FxRow Scientific -> Float+-- avgTs x = 0.5 * (h + l) where+-- h = toFloat (rateHigh x)+-- l = toFloat (rateLow x) --- Forex time series parsers - related +-- -- Forex time series parsers - related @@ -69,27 +70,29 @@ --- * Forex dataset -parseFxDataset :: A.Parser [TsPoint (FxRow Scientific)]-parseFxDataset = A.sepBy parseFxRow A.endOfLine+-- -- * Forex dataset -parseFxRow :: A.Parser (TsPoint (FxRow Scientific))-parseFxRow = do- (d, t) <- parseDateTime- _ <- comma- open <- A.scientific- _ <- comma- hi <- A.scientific- _ <- comma- lo <- A.scientific- _ <- comma- close <- A.scientific- pure $ Tsp (Tick d t) (FxRow open hi lo close)+-- parseFxDataset :: A.Parser [TsPoint (FxRow Scientific)]+-- parseFxDataset = A.sepBy parseFxRow A.endOfLine -parseDateTime :: A.Parser (Day, TimeOfDay)-parseDateTime = do- d <- AT.dayInISO8601- _ <- space- t <- AT.timeOfDayInISO8601- return (d, t)+-- parseFxRow :: A.Parser (TsPoint (FxRow Scientific))+-- parseFxRow = do+-- (d, t) <- parseDateTime+-- _ <- comma+-- open <- A.scientific+-- _ <- comma+-- hi <- A.scientific+-- _ <- comma+-- lo <- A.scientific+-- _ <- comma+-- close <- A.scientific+-- pure $ Tsp (Tick d t) (FxRow open hi lo close)+++-- parseDateTime :: A.Parser (Day, TimeOfDay)+-- parseDateTime = do+-- d <- AT.dayInISO8601+-- _ <- space+-- t <- AT.timeOfDayInISO8601+-- return (d, t)
plot-light-examples.cabal view
@@ -1,5 +1,5 @@ name: plot-light-examples-version: 0.2.0.0+version: 0.3.0.0 synopsis: Example binaries for plot-light description: Example binaries for plot-light homepage: https://github.com/ocramz/plot-light-examples@@ -31,13 +31,27 @@ hs-source-dirs: app/scatter main-is: Main.hs build-depends: base >= 4.7 && < 5- , plot-light > 0.3.2+ , plot-light > 0.4 , plot-light-examples , attoparsec , text , colour , blaze-svg , scientific++executable histogram+ default-language: Haskell2010+ ghc-options: -threaded -rtsopts -with-rtsopts=-N+ hs-source-dirs: app/histogram+ main-is: Main.hs+ build-depends: base >= 4.7 && < 5+ , plot-light > 0.4+ , plot-light-examples+ , attoparsec+ , text+ , colour+ , blaze-svg+ , scientific executable timeseries default-language: Haskell2010@@ -45,7 +59,7 @@ hs-source-dirs: app/timeseries main-is: Main.hs build-depends: base >= 4.7 && < 5- , plot-light > 0.3.2+ , plot-light > 0.4 , plot-light-examples , attoparsec , attoparsec-time >= 1@@ -61,7 +75,7 @@ hs-source-dirs: app/heatmap main-is: Main.hs build-depends: base >= 4.7 && < 5- , plot-light > 0.3.2+ , plot-light > 0.4 , plot-light-examples , attoparsec , time