packages feed

plot-light 0.4 → 0.4.1

raw patch · 6 files changed

+80/−55 lines, 6 filesbinary-addedPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Graphics.Rendering.Plot.Light: BothCol :: (Col a) -> (Col a) -> a -> ShapeCol a
+ Graphics.Rendering.Plot.Light: Col :: Colour Double -> a -> Col a
+ Graphics.Rendering.Plot.Light: NoBorderCol :: (Col a) -> ShapeCol a
+ Graphics.Rendering.Plot.Light: NoFillCol :: (Col a) -> a -> ShapeCol a
+ Graphics.Rendering.Plot.Light: [cAlpha] :: Col a -> a
+ Graphics.Rendering.Plot.Light: [cColour] :: Col a -> Colour Double
+ Graphics.Rendering.Plot.Light: data Col a
+ Graphics.Rendering.Plot.Light: data ShapeCol a

Files

+ doc/fig/scatter-2.png view

binary file changed (absent → 7533 bytes)

− doc/fig/scatter.png

binary file changed (13903 → absent bytes)

plot-light.cabal view
@@ -1,5 +1,5 @@ name:                plot-light-version:             0.4+version:             0.4.1 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.                      @@ -14,7 +14,7 @@ extra-source-files:  README.md                      CHANGELOG.md extra-doc-files:     doc/fig/heatmap.png-                     doc/fig/scatter.png+                     doc/fig/scatter-2.png cabal-version:       >=1.18 tested-with:         GHC == 8.0.2, GHC == 8.2.2, GHC == 8.4.1, GHC == 8.4.2 
src/Graphics/Rendering/Plot/Light.hs view
@@ -38,11 +38,12 @@ -- -- > xPlot = 400 -- > yPlot = 300--- >+-- > fnameOut = "heatmap.svg"+--  -- > fdat = FigureData xPlot yPlot 0.1 0.8 0.1 0.9 10--- >+--  -- > palette0 = palette [C.red, C.white, C.blue] 15--- > +--  -- > plotFun2ex1 = do -- >  let  -- >    p1 = Point (-2) (-2)@@ -64,7 +65,7 @@ -- >       axes fdat frame 2 C.black 10 10 -- >       pixels -- >       cbar--- >  T.writeFile "heatmap.svg" $ T.pack $ renderSvg svg_t+-- >  T.writeFile fnameOut $ T.pack $ renderSvg svg_t -- -- This example demonstrates how to plot a 2D scalar function and write the output to SVG file. --@@ -83,46 +84,45 @@ -- -- === 2. Scatter plot of 3D data ----- <<doc/fig/scatter.png>>+-- <<doc/fig/scatter-2.png>> -- -- This example shows how to plot a collection of labelled points in the plane. Each sample row is represented by a `LabeledPoint`, in which the label is a scalar quantity. ----- The `scatterLP` function renders each data row as a glyph, by modifying a `ScatterPointData` record of default values via three functions that control the glyph size, contour line thickness and colour. This functionality can be exploited in creative ways to achieve effective infographics.---+-- The `scatterLP` function renders each data row as a glyph, by modifying a `ScatterPointData` record of default values via four functions that control the glyph size, contour line thickness, colour and opacity. This functionality can be exploited in creative ways to achieve effective infographics. -- -- > xPlot = 400 -- > yPlot = 300--- > fnameOut = "data/scatter-1.svg"--- >+-- > fnameOut = "scatter.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]--- >--- > spdata = ScatterPointData Circle 3 3 C.red--- >--- >+-- >   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 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)))--- >      where x = l + sz--- >    g _ w = w--- >    h l col = C.blend l' C.blue col--- >      where--- >        l' = (l - vmin)/(vmax - vmin)--- >    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+-- >   let+-- >     frameTo = frameFromFigData fdat+-- >     frameFrom = frameFromPoints $ _lp <$> dats+-- >     vmin = minimum $ _lplabel <$> dats+-- >     vmax = maximum $ _lplabel <$> dats     +-- >     f l sz = 15 / (1 + exp(- (0.3 * x)) )+-- >       where x = l + sz+-- >     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 i spdata dats'+-- >       scatterLPBar fdat 50 vmin vmax 3 TopRight 100 f g h i spdata -- >   T.writeFile fnameOut $ T.pack $ renderSvg svg_t------+--   module Graphics.Rendering.Plot.Light (   -- * Plot types@@ -131,7 +131,7 @@   -- ** Scatter   scatter, scatterLP, scatterLPBar, ScatterPointData(..), GlyphShape_(..),   -- * Plot elements-  -- ** Geometrical primitives+  -- ** Geometric primitives   rect, rectCentered, squareCentered, circle, line, text, polyline, filledPolyline, pixel, pixel',    -- ** Composite plot elements   filledBand, candlestick,@@ -142,12 +142,19 @@   -- ** Operations on frames   frameFromPoints, frameFromFigData, mkFrame, mkFrameOrigin, width, height, figFWidth, figFHeight,     -- ** Colour utilities-  blendTwo, palette, pickColour, +  blendTwo, palette, pickColour,+  -- *** ShapeCol-related+  ShapeCol(..), Col(..),    -- ** SVG utilities   svgHeader, translateSvg, toSvgFrame, toSvgFrameLP,-  -- * Types-  Frame(..), Point(..), LabeledPoint(..), labelPoint, mapLabel, Axis(..),-  -- ** Helpers+  -- * Geometric types+  -- ** Frame+  Frame(..),+  -- ** Point, LabeledPoint+  Point(..), LabeledPoint(..), labelPoint, mapLabel,+  -- ** Axis+  Axis(..),+  -- * Helpers   meshGrid,   -- *** Misc.   toFloat, wholeDecimal
src/Graphics/Rendering/Plot/Light/Internal.hs view
@@ -172,8 +172,8 @@  -- | A rectangle, defined by its center coordinates and side lengths ----- > > putStrLn $ renderSvg $ rectCentered 15 30 (Just C.blue) (Just C.red) (Point 20 30)-+-- > > putStrLn $ renderSvg $ rectCentered 15 30 (shapeColBoth C.blue C.red 1 5) (Point 20 30)+-- > <rect x="12.5" y="15.0" width="15.0" height="30.0" fill-opacity="1.0" fill="#0000ff" stroke-opacity="1.0" stroke="#ff0000" stroke-width="5.0" /> rectCentered :: (Show a, RealFrac a) =>      a                       -- ^ Width   -> a                       -- ^ Height@@ -188,12 +188,14 @@   -- | A square, defined by its center coordinates and side length-squareCentered-  :: (Show a, RealFrac a) =>-     a                          -- ^ Side length-     -> ShapeCol a              -- ^ Colour and alpha information-     -> Point a                 -- ^ Center coordinates-     -> Svg+--+-- > > putStrLn $ renderSvg $ squareCentered 30 (shapeColBoth C.blue C.red 1 5) (Point 20 30)+-- > <rect x="5.0" y="15.0" width="30.0" height="30.0" fill-opacity="1.0" fill="#0000ff" stroke-opacity="1.0" stroke="#ff0000" stroke-width="5.0" />+squareCentered :: (Show a, RealFrac a) =>+                  a                          -- ^ Side length+               -> ShapeCol a              -- ^ Colour and alpha information+               -> Point a                 -- ^ Center coordinates+               -> Svg squareCentered w = rectCentered w w  lineColourDefault :: C.Colour Double
src/Graphics/Rendering/Plot/Light/PlotTypes/Scatter.hs view
@@ -6,12 +6,15 @@ import Data.Fixed import Data.Maybe (fromMaybe) import Control.Monad (forM_)+ 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 import qualified Data.Text as T-+import qualified Data.Text.IO as T  -- | Scatter plot --@@ -33,7 +36,7 @@              (l -> b -> a)            -- ^ Modifies the glyph size           -> (l -> b -> a)         -- ^ Modifies the glyph stroke width           -> (l -> C.Colour Double -> C.Colour Double)  -- ^ Modifies the glyph colour-          -> (l -> b -> a)+          -> (l -> b -> a)        -- ^ Modifies the glyph opacity           -> ScatterPointData b    -- ^ Glyph style defaults           -> t (LabeledPoint l a) -- ^ Data           -> Svg@@ -80,11 +83,11 @@ -- | Parameters for a scatterplot glyph data ScatterPointData a = ScatterPointData   {-    spGlyphShape :: GlyphShape_-  , spSize :: a-  , spStrokeWidth :: a-  , spColour :: C.Colour Double-  , spAlpha :: a+    spGlyphShape :: GlyphShape_   -- ^ Glyph shape+  , spSize :: a                   -- ^ Glyph size+  , spStrokeWidth :: a            -- ^ Glyph stroke width+  , spColour :: C.Colour Double   -- ^ Glyph colour+  , spAlpha :: a                  -- ^ Glyph opacity   } deriving (Eq, Show)  @@ -128,6 +131,19 @@ -- -- | Utility function for cycling glyph colours and shapes (i.e. unique combinations of these make it easy to tell different datasets apart) -- cycleGlyphCols :: (CP.ColorCat, Int) -> Int -> [(CP.Kolor, GlyphShape_)] -- cycleGlyphCols (pal, n) nsets = take nsets $ zip (cycle $ CP.brewerSet pal n ) (cycle [Square, Circle ..])+++++++    ++++++