packages feed

plot-light 0.4.2 → 0.4.3

raw patch · 5 files changed

+151/−26 lines, 5 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Graphics.Rendering.Plot.Light: Plot1DOptions :: a -> LineStroke_ a -> StrokeLineJoin_ -> Colour Double -> Plot1DOptions a
+ Graphics.Rendering.Plot.Light: [p1oStrokeColour] :: Plot1DOptions a -> Colour Double
+ Graphics.Rendering.Plot.Light: [p1oStrokeJoinType] :: Plot1DOptions a -> StrokeLineJoin_
+ Graphics.Rendering.Plot.Light: [p1oStrokeType] :: Plot1DOptions a -> LineStroke_ a
+ Graphics.Rendering.Plot.Light: [p1oWidth] :: Plot1DOptions a -> a
+ Graphics.Rendering.Plot.Light: data Plot1DOptions a
+ Graphics.Rendering.Plot.Light: histogram :: Foldable v => ShapeCol Double -> Int -> v Double -> Svg
+ Graphics.Rendering.Plot.Light: plotFun :: Functor f => (t -> t) -> f (Point t) -> f (Point t)
+ Graphics.Rendering.Plot.Light: shapeColBoth :: Colour Double -> Colour Double -> a -> a -> ShapeCol a
+ Graphics.Rendering.Plot.Light: shapeColNoBorder :: Colour Double -> a -> ShapeCol a
+ Graphics.Rendering.Plot.Light: shapeColNoFill :: Colour Double -> a -> a -> ShapeCol a

Files

plot-light.cabal view
@@ -1,5 +1,5 @@ name:                plot-light-version:             0.4.2+version:             0.4.3 synopsis:            A lightweight plotting library, exporting to SVG description:         This library provides drawing and plotting datastructures and functions; it is aimed in particular at scientific visualization, but it also exposes its plotting primitives and a small but general purpose 2D geometry library.                      
src/Graphics/Rendering/Plot/Light.hs view
@@ -126,25 +126,38 @@  module Graphics.Rendering.Plot.Light (   -- * Plot types+  -- ** 1D plot+  plotFun, Plot1DOptions(..),   -- ** Heatmap   heatmap, heatmap', plotFun2, colourBar,   -- ** Scatter   scatter, scatterLP, scatterLPBar, ScatterPointData(..), GlyphShape_(..),   -- * Plot elements   -- ** Geometric primitives-  rect, rectCentered, squareCentered, circle, line, text, polyline, filledPolyline, pixel, pixel', +  -- *** Rectangle, square+  rect, rectCentered, squareCentered,+  -- *** Circle+  circle,+  -- *** Line+  line,+  -- *** Text+  text, TextAnchor_(..), +  -- *** Polyline+  polyline, filledPolyline, StrokeLineJoin_(..), +  -- *** Pixel+  pixel, pixel',    -- ** Composite plot elements-  filledBand, candlestick,+  filledBand, candlestick, histogram,   -- ** Plot utilities   axes, toPlot, FigureData(..),   -- ** Element attributes-  LineStroke_(..), StrokeLineJoin_(..), TextAnchor_(..), LegendPosition_(..),+  LineStroke_(..), LegendPosition_(..),   -- ** Operations on frames   frameFromPoints, frameFromFigData, mkFrame, mkFrameOrigin, width, height, figFWidth, figFHeight,     -- ** Colour utilities   blendTwo, palette, pickColour,   -- *** ShapeCol-related-  ShapeCol(..), Col(..),+  ShapeCol(..), Col(..), shapeColNoBorder, shapeColNoFill, shapeColBoth,   -- ** TimeSeries utilities   fromTick, toTick,   -- ** SVG utilities
src/Graphics/Rendering/Plot/Light/Internal.hs view
@@ -10,10 +10,24 @@     -- * LabeledPoint   , LabeledPoint(..), mkLabeledPoint, labelPoint, mapLabel, Axis(..), axes, meshGrid, subdivSegment,     -- * SVG elements-    svgHeader, rect, rectCentered, squareCentered, circle, line, tick, ticks, axis, toPlot, text, pixel, pixel', pickColour, colourBar, legendBar, plusGlyph, crossGlyph, polyline, filledPolyline, filledBand, candlestick, strokeLineJoin, LineStroke_(..), StrokeLineJoin_(..), TextAnchor_(..), LegendPosition_(..)+    svgHeader, toPlot,+    -- ** Rectangle/square+    rect, rectCentered, rectCenteredMidpointBase, squareCentered,+    -- ** Circle+    circle,+    -- ** Lines+    line, tick, ticks, axis,+    -- ** Polylines+    polyline, filledPolyline, filledBand, strokeLineJoin, LineStroke_(..), StrokeLineJoin_(..),+    -- ** Text+    text, TextAnchor_(..), +    -- ** Specialized plot elements+    pixel, pixel', plusGlyph, crossGlyph, candlestick, +    -- ** Plot legend+    pickColour, colourBar, legendBar, LegendPosition_(..),      -- * Geometry     -- ** R^2 Vectors-  , V2(..), e1, e2, norm2, normalize2, v2fromEndpoints, v2fromPoint, (-.), pointRange+    V2(..), e1, e2, norm2, normalize2, v2fromEndpoints, v2fromPoint, (-.), pointRange     -- ** R^2 -> R^2 Matrices   , Mat2(..), DiagMat2(..), diagMat2     -- ** Typeclasses@@ -105,9 +119,11 @@  -- | A Col is both a 'Colour' and an alpha (opacity) coefficient data Col a = Col {-    cColour :: C.Colour Double-  , cAlpha :: a } deriving (Eq, Show)+    cColour :: C.Colour Double  -- ^ Colour+  , cAlpha :: a                 -- ^ Opacity, [0 .. 1]+  } deriving (Eq, Show) +-- | 'Col' constructor col :: C.Colour Double -> a -> Col a col = Col @@ -126,12 +142,15 @@   | BothCol (Col a) (Col a) a -- ^ Fill and border colours   deriving (Eq, Show) +-- | Construct a 'ShapeCol' for shapes that have no border stroke (i.e. have only the fill colour) shapeColNoBorder :: C.Colour Double -> a -> ShapeCol a shapeColNoBorder c a = NoBorderCol $ col c a +-- | Construct a 'ShapeCol' for shapes that have no fill colour (i.e. have only the stroke colour) shapeColNoFill :: C.Colour Double -> a -> a -> ShapeCol a shapeColNoFill c a = NoFillCol $ col c a  +-- | Construct a 'ShapeCol' for shapes that have both fill and stroke colour shapeColBoth ::      C.Colour Double  -- ^ Fill colour   -> C.Colour Double  -- ^ Stroke colour@@ -186,7 +205,19 @@     x0c = x0 - (wid / 2)     y0c = y0 - (hei / 2)    +-- | A rectangle, defined by the coordinates of the midpoint of its base+rectCenteredMidpointBase :: (Show a, RealFrac a) =>+     a                       -- ^ Width+  -> a                       -- ^ Height+  -> ShapeCol a              -- ^ Colour and alpha information+  -> Point a                 -- ^ Base midpoint coordinates     +  -> Svg+rectCenteredMidpointBase wid hei col (Point x0 y0) =+  rect wid hei col p' where+    p' = Point x0c y0+    x0c = x0 - (wid / 2) + -- | A square, defined by its center coordinates and side length -- -- > > putStrLn $ renderSvg $ squareCentered 30 (shapeColBoth C.blue C.red 1 5) (Point 20 30)@@ -530,6 +561,9 @@   +++ -- | A filled polyline -- -- > > putStrLn $ renderSvg $ filledPolyline C.coral 0.3 [(Point 0 1), (Point 10 40), Point 34 50, Point 30 5]@@ -649,21 +683,28 @@   -+-- | A 'pixel' is a filled square shape used for populating 'heatmap' plots , coloured from a palette pixel :: (Show a, RealFrac a) =>          [C.Colour Double]         -- ^ Palette       -> a                         -- ^ Width       -> a                         -- ^ Height-      -> Scientific          -      -> Scientific+      -> Scientific                -- ^ Function minimum+      -> Scientific               -- ^ Function maximum       -> LabeledPoint Scientific a       -> Svg pixel pal w h vmin vmax (LabeledPoint p l) = rect w h col p where   col = pickColour pal (toFloat vmin) (toFloat vmax) (toFloat l) +-- | A 'pixel'' is a filled square shape used for populating 'heatmap' plots , coloured from a palette pixel'   :: (Show a, RealFrac a, RealFrac t) =>-     [C.Colour Double] -> a -> a -> t -> t -> LabeledPoint t a -> Svg+     [C.Colour Double]  -- ^ Palette+  -> a                  -- ^ Width +  -> a -- ^ Height+  -> t -- ^ Function minimum +  -> t -- ^ Function maximum+  -> LabeledPoint t a+  -> Svg pixel' pal w h vmin vmax (LabeledPoint p l) = rect w h col p where   col = pickColour pal vmin vmax l   
src/Graphics/Rendering/Plot/Light/PlotTypes/Histogram.hs view
@@ -1,10 +1,13 @@ {-# language FlexibleContexts #-}-module Graphics.Rendering.Plot.Light.PlotTypes.Histogram where+module Graphics.Rendering.Plot.Light.PlotTypes.Histogram (histogram) where  import Graphics.Rendering.Plot.Light.Internal  import Control.Monad (forM_)--- import Text.Blaze.Svg++import Text.Blaze.Svg+import Text.Blaze.Svg.Renderer.String (renderSvg)+ import qualified Data.Colour as C -- import qualified Data.Colour.Palette.BrewerSet as CP import qualified Data.Colour.Names as C@@ -17,18 +20,40 @@ import qualified Data.Vector.Unboxed as VU import qualified Data.Vector.Generic as VG --- histogram figdata =-  - +import qualified Data.Text as T+import qualified Data.Text.IO as T   -histogram col h = undefined where-  (binCenters, binCounts) = unzip $ H.asList h-  binXOffset = - head binCenters + 0.5 * binSize-  binSize = H.binSize $ H.bins h-  -- hcol = case col of-  --   NoBorderCol c a +xPlot = 400+yPlot = 300+fnameOut = "data/histogram-1.svg"++dats = [46,30,4,7,73,12,23,90,34,24,5,6,12,3,55,61]++main = do+  let+    kol = shapeColNoBorder C.red 1+    svg_t = svgHeader xPlot yPlot $ histogram kol 5 dats+  T.writeFile fnameOut $ T.pack $ renderSvg svg_t+++++histogram :: Foldable v =>+             ShapeCol Double -- ^ Colour information (fill, stroke, opacity)+          -> Int             -- ^ Number of histogram bins+          -> v Double        -- ^ Data+          -> Svg+histogram col nBins dats = forM_ pshs $ \(p, h) -> rectCenteredMidpointBase binW (hMult * h) col p where+  his = histo nBins dats+  p1 = Point (head binCenters) 0+  p2 = Point (last binCenters) 0+  ps = pointRange nBins p1 p2+  pshs = zip ps binCounts +  (binCenters, binCounts) = unzip $ H.asList his+  binW = H.binSize $ H.bins his  -- bin width+  hMult = 10 -- height multiplication coeff. (hack)   
src/Graphics/Rendering/Plot/Light/PlotTypes/Plot1D.hs view
@@ -1,6 +1,52 @@-module Graphics.Rendering.Plot.Light.PlotTypes.Plot1D (plotFun) where+module Graphics.Rendering.Plot.Light.PlotTypes.Plot1D (+    plotFun, Plot1DOptions(..)+  , plotf, plotf'+  , Plot1DDomain(..)+  , plot, plot'+  ) where  import Graphics.Rendering.Plot.Light.Internal+import qualified Data.Colour as C+import qualified Data.Colour.Names as C+import Text.Blaze.Svg +-- | Graph a 1D function+plotFun :: Functor f => (t -> t) -> f (Point t) -> f (Point t) plotFun f = fmap f' where-  f' p@(Point x _) = LabeledPoint p (f x)+  f' (Point x _) = Point x (f x)++-- | Plot the graph of a 1D function+plotf :: (Show a, RealFrac a) => (a -> a) -> Svg+plotf = plotf' plot1dDomainDefaults++plotf' :: (Show a, RealFrac a) => Plot1DDomain a -> (a -> a) -> Svg+plotf' (Plot1DDomain n x1 x2) f = plot $ plotFun f ps where+  ps = pointRange n (Point x1 0) (Point x2 0)++plot :: (Foldable t, Show a, RealFrac a) => t (Point a) -> Svg+plot = plot' plot1DDefaults++plot' :: (Foldable t, Show a, RealFrac a) =>+         Plot1DOptions a+      -> t (Point a)+      -> Svg+plot' (Plot1DOptions sw ty sjt sc) = polyline sw ty sjt sc ++data Plot1DOptions a = Plot1DOptions {+    p1oWidth :: a             -- ^ Stroke width+  , p1oStrokeType :: LineStroke_ a   -- ^ Stroke type +  , p1oStrokeJoinType :: StrokeLineJoin_ -- ^ Stroke join type +  , p1oStrokeColour :: C.Colour Double -- ^ Stroke colour+                                     } deriving (Eq, Show)++plot1DDefaults :: RealFrac a => Plot1DOptions a+plot1DDefaults = Plot1DOptions 3 Continuous Round C.blue++data Plot1DDomain a = Plot1DDomain {+    p1dNPoints :: Int+  , p1dPoint1 :: a+  , p1dPoint2 :: a+                                   } deriving (Eq, Show)++plot1dDomainDefaults :: RealFrac a => Plot1DDomain a+plot1dDomainDefaults = Plot1DDomain 100 (-10) 10