plot 0.2.3.4 → 0.2.3.5
raw patch · 10 files changed
+76/−79 lines, 10 filesdep ~hmatrix
Dependency ranges changed: hmatrix
Files
- CHANGES +7/−3
- examples/Test.hs +6/−5
- lib/Graphics/Rendering/Plot/Figure/Plot.hs +4/−8
- lib/Graphics/Rendering/Plot/Figure/Plot/Data.hs +3/−2
- lib/Graphics/Rendering/Plot/Figure/Simple.hs +3/−3
- lib/Graphics/Rendering/Plot/Render/Plot/Annotation.hs +3/−6
- lib/Graphics/Rendering/Plot/Render/Plot/Axis.hs +2/−2
- lib/Graphics/Rendering/Plot/Render/Plot/Data.hs +42/−43
- lib/Graphics/Rendering/Plot/Types.hs +2/−3
- plot.cabal +4/−4
CHANGES view
@@ -123,8 +123,12 @@ * allow v0.13 of pango/cairo 0.2.3.3:- * Update AMP Changes for ghc 7.10+ * Update AMP Changes for ghc 7.10 0.2.3.4:- * clean up warnings- * use transformers instead of MaybeT+ * clean up warnings+ * use transformers instead of MaybeT++0.2.3.5:+ * update for hmatrix 0.17+
examples/Test.hs view
@@ -117,12 +117,13 @@ glyph (4,0.2) (return ()) text (3,0.0) (setText "from the α to the Ω") cairo (\_ _ _ _ -> do- C.newPath- C.moveTo 3 0.75- C.lineTo 4 (-0.5)+ --C.stroke+ --C.newPath+ C.moveTo 1 0.75+ C.lineTo 2 (-0.5) C.stroke- C.rectangle (pi/2) (-1) (pi/2) 1- C.fill+ --C.rectangle (pi/2) (-0.75) (pi/2) 1+ --C.fill ) -- setRange YAxis Lower Log (-1.25) 1.25 -- setLegend True NorthEast Inside
lib/Graphics/Rendering/Plot/Figure/Plot.hs view
@@ -88,11 +88,7 @@ --import Data.Bool.Unicode --import Data.Ord.Unicode ---import Data.Packed.Vector---import Data.Packed.Matrix-import Numeric.Container----import Numeric.LinearAlgebra(eps)+import Numeric.LinearAlgebra.Data hiding(Range) import qualified Data.Array.IArray as A @@ -288,10 +284,10 @@ findMinMax :: Abscissae -> Ordinates -> (Double,Double) findMinMax (AbsFunction _) (OrdFunction _ f _) = - let v = mapVector f (linspace 100 (-1,1))+ let v = cmap f (linspace 100 (-1,1)) in (minElement v,maxElement v) findMinMax (AbsPoints _ x) (OrdFunction _ f _) = - let v = mapVector f x+ let v = cmap f x in (minElement v,maxElement v) -- what if errors go beyond plot? findMinMax _ (OrdPoints _ (Plain o) _) = (minElement o,maxElement o)@@ -307,7 +303,7 @@ ordDim :: Ordinates -> Int ordDim (OrdFunction _ _ _) = 1-ordDim (OrdPoints _ o _) = dim $ getOrdData o+ordDim (OrdPoints _ o _) = size $ getOrdData o calculateRanges :: DataSeries -> ((Double,Double),(Double,Double))
lib/Graphics/Rendering/Plot/Figure/Plot/Data.hs view
@@ -40,7 +40,8 @@ ----------------------------------------------------------------------------- -import Data.Packed.Vector+import Numeric.LinearAlgebra.Data hiding (format,step)+import Numeric.LinearAlgebra.Devel import Data.Maybe @@ -903,7 +904,7 @@ {-# INLINE monoStep #-} isMonotoneIncreasing :: Vector Double -> Bool-isMonotoneIncreasing v = maybe False (\_ -> True) $ evalState (runMaybeT $ (mapVectorM_ monoStep (subVector 1 (dim v -1) v))) (v @> 0)+isMonotoneIncreasing v = maybe False (\_ -> True) $ evalState (runMaybeT $ (mapVectorM_ monoStep (subVector 1 (size v -1) v))) (v `atIndex` 0) -----------------------------------------------------------------------------
lib/Graphics/Rendering/Plot/Figure/Simple.hs view
@@ -1,7 +1,7 @@ ----------------------------------------------------------------------------- -- | -- Module : Graphics.Rendering.Plot.Figure--- Copyright : (c) A. V. H. McPhail 2010+-- Copyright : (c) A. V. H. McPhail 2010, 2015 -- License : BSD3 -- -- Maintainer : haskell.vivian.mcphail <at> gmail <dot> com@@ -34,7 +34,7 @@ ----------------------------------------------------------------------------- -import Numeric.Container+import Numeric.LinearAlgebra.Data import Graphics.Rendering.Plot.Figure @@ -101,7 +101,7 @@ setPlots 1 1 withPlot (1,1) $ do let t = linspace n (l,h)- setDataset (Line,mapVector fx t,[mapVector fy t])+ setDataset (Line,cmap fx t,[cmap fy t]) addAxis XAxis (Side Lower) $ return () addAxis YAxis (Side Lower) $ return () setRangeFromData XAxis Lower Linear
lib/Graphics/Rendering/Plot/Render/Plot/Annotation.hs view
@@ -138,15 +138,12 @@ _ <- renderText te TRight TTop (x1) (y1) cairo $ C.restore return ()-renderAnnotation _xscale _yscale (AnnCairo r) = do+renderAnnotation xscale yscale (AnnCairo r) = do (BoundingBox x y w h) <- get cairo $ do C.save- --let (x,y) = (x'*xscale,y'*yscale)- --let (w,h) = (w'*xscale,h'*yscale)- --flipVertical- --C.translate x y- --C.scale (xscale) (yscale)+ --C.translate (x) (y)+ C.scale (xscale) (yscale) r x y w h C.restore
lib/Graphics/Rendering/Plot/Render/Plot/Axis.hs view
@@ -1,7 +1,7 @@ ----------------------------------------------------------------------------- -- | -- Module : Graphics.Rendering.Plot.Render.Plot.Axis--- Copyright : (c) A. V. H. McPhail 2010+-- Copyright : (c) A. V. H. McPhail 2010, 2015 -- License : BSD3 -- -- Maintainer : haskell.vivian.mcphail <at> gmail <dot> com@@ -27,7 +27,7 @@ import Data.List -import Data.Packed.Vector+import Numeric.LinearAlgebra.Data hiding (Range) import qualified Graphics.Rendering.Cairo as C import qualified Graphics.Rendering.Pango as P
lib/Graphics/Rendering/Plot/Render/Plot/Data.hs view
@@ -5,7 +5,7 @@ ----------------------------------------------------------------------------- -- | -- Module : Graphics.Rendering.Plot.Render.Plot.Data--- Copyright : (c) A. V. H. McPhail 2010, 2013+-- Copyright : (c) A. V. H. McPhail 2010, 2013, 2015 -- License : BSD3 -- -- Maintainer : haskell.vivian.mcphail <at> gmail <dot> com@@ -29,10 +29,9 @@ --import Foreign.Storable --import Foreign.Ptr ---import Data.Packed.Vector---import Data.Packed.Matrix---import Data.Packed() import Numeric.LinearAlgebra+--import Numeric.LinearAlgebra.Data+import Numeric.LinearAlgebra.Devel import qualified Data.Array.IArray as A --import qualified Data.Array.MArray as M@@ -64,12 +63,12 @@ findMinIdx, findMaxIdx :: Vector Double -> Double -> Int -> Int -> Int findMinIdx v x n max | n >= max = error "findMinIdx: data not in range"- | v @> n >= x = n+ | v `atIndex` n >= x = n | otherwise = findMinIdx v x (n+1) max findMaxIdx v x n min | n < 0 = error "findMaxIdx: data not in range"- | v @> n <= x = n+ | v `atIndex` n <= x = n | otherwise = findMaxIdx v x (n-1) min -----------------------------------------------------------------------------@@ -83,7 +82,7 @@ mn = minElement m mapM_ (\ri -> mapM_ (\(rj,ci) -> do let mi = ((rj `div` r')*c) + (ci `div` c')- let e = round . (* 255) . (/ (mx-mn)) . (\x -> x - mn) $ (fm @> mi)+ let e = round . (* 255) . (/ (mx-mn)) . (\x -> x - mn) $ (fm `atIndex` mi) let si = (rj*stride) + ci B.unsafeWrite s si e) $ zip (repeat ri) [0..((c*c')-1)]) [0..((r*r')-1)] @@ -167,13 +166,13 @@ return () logSeries :: Scale -> Vector Double -> Vector Double-logSeries Log a = logBase 10 $ mapVector zeroToOne a+logSeries Log a = logBase 10 $ cmap zeroToOne a logSeries _ a = a -midpoints :: (Num (Vector t), Container Vector t) +midpoints :: (Fractional t, Num (Vector t), Container Vector t) => (t1, Vector t) -> (t1, Vector t)-midpoints(mi,v) = let v' = subVector 1 (dim v - 1) v- w' = subVector 0 (dim v - 1) v+midpoints(mi,v) = let v' = subVector 1 (size v - 1) v+ w' = subVector 0 (size v - 1) v in (mi,(v'+w')/2.0) logSeriesMinMax :: Scale -> (Vector Double,Vector Double) -> (Vector Double,Vector Double)@@ -200,7 +199,7 @@ shiftAbscissa :: (Integer,(Abscissae,DecoratedSeries,BarType)) -> Double -> (Integer,(Abscissae,DecoratedSeries)) shiftAbscissa (j,(AbsFunction f,ds,_)) s = (j,(AbsFunction ((+) s . f),ds))-shiftAbscissa (j,(AbsPoints mi t,ds,_)) s = (j,(AbsPoints mi (addConstant s t),ds))+shiftAbscissa (j,(AbsPoints mi t,ds,_)) s = (j,(AbsPoints mi ((+) (vector [s]) t),ds)) replaceBars :: [(Integer,(Abscissae,DecoratedSeries))] -> [(Abscissae,DecoratedSeries)] @@ -255,8 +254,8 @@ return aos' BarStack -> do let od = (getOrdData' . (\(_,b,_) -> b) . snd . head) bars- let ln = dim $ od- let zero = constant 0 ln+ let ln = size $ od+ let zero = konst 0 ln let pairs = pair $ scanl scanStacked zero bars let candles = zipWith mkCandlesFromBars pairs bars let aos' = replaceBars candles aos@@ -274,21 +273,21 @@ (OrdFunction _ f _) -> do (BoundingBox _ _ w _) <- get let t = logSeries xsc $ linspace (round w) (xmin,xmax)- return $ Left $ Left ((True,t),logSeries ysc $ mapVector f t)+ return $ Left $ Left ((True,t),logSeries ysc $ cmap f t) (OrdPoints _ (Plain o') _) -> do let t = case abs of AbsFunction f -> if isHist d- then (True,mapVector f $ fromList [0.0..(fromIntegral $ dim o')])- else (True,mapVector f $ fromList [1.0..(fromIntegral $ dim o')])+ then (True,cmap f $ fromList [0.0..(fromIntegral $ size o')])+ else (True,cmap f $ fromList [1.0..(fromIntegral $ size o')]) AbsPoints mi t' -> (mi,t') return $ Left $ Left ((fst t,logSeries xsc $ snd t),logSeries ysc $ o') (OrdPoints _ (Error o' (Left e)) _) -> do let t = case abs of AbsFunction f -> if isHist d- then (True,mapVector f $ fromList [0.0..(fromIntegral $ dim o')])- else (True,mapVector f $ fromList [1.0..(fromIntegral $ dim o')])+ then (True,cmap f $ fromList [0.0..(fromIntegral $ size o')])+ else (True,cmap f $ fromList [1.0..(fromIntegral $ size o')]) AbsPoints mi t' -> (mi,t') let t' = (fst t,logSeries xsc $ snd t) return $ Left $ Right $ Left ((t',logSeries ysc $ o'),(t',logSeries ysc $ e))@@ -296,20 +295,20 @@ let t = case abs of AbsFunction f -> if isHist d- then (True,mapVector f $ fromList [0.0..(fromIntegral $ dim o')])- else (True,mapVector f $ fromList [1.0..(fromIntegral $ dim o')])+ then (True,cmap f $ fromList [0.0..(fromIntegral $ size o')])+ else (True,cmap f $ fromList [1.0..(fromIntegral $ size o')]) AbsPoints mi t' -> (mi,t') let t' = (fst t,logSeries xsc $ snd t) return $ Left $ Right $ Right ((t',logSeries ysc $ o'),(t',logSeries ysc $ l),(t',logSeries ysc $ h)) (OrdPoints _ (MinMax o' Nothing) _) -> do let t = case abs of- AbsFunction f -> (True,mapVector f $ fromList [1.0..(fromIntegral $ dim $ fst o')])+ AbsFunction f -> (True,cmap f $ fromList [1.0..(fromIntegral $ size $ fst o')]) AbsPoints mi t' -> (mi,t') let t' = (fst t,logSeries xsc $ snd t) return $ Right $ Left (t',logSeriesMinMax ysc $ o') (OrdPoints _ (MinMax o' (Just (l,h))) _) -> do let t = case abs of- AbsFunction f -> (True,mapVector f $ fromList [1.0..(fromIntegral $ dim l)])+ AbsFunction f -> (True,cmap f $ fromList [1.0..(fromIntegral $ size l)]) AbsPoints mi t' -> (mi,t') let t' = (fst t,logSeries xsc $ snd t) return $ Right $ Right ((t',logSeriesMinMax ysc o'),(t',(logSeries ysc l,logSeries ysc h)))@@ -369,10 +368,10 @@ formatLineSeries lt case dat of Left (Left (t',y')) -> do- let ln = dim $ snd t'+ let ln = size $ snd t' xmin_ix = findMinIdx (snd t') xmin 0 (ln-1)- x0 = (snd t') @> xmin_ix- y0 = y' @> xmin_ix+ x0 = (snd t') `atIndex` xmin_ix+ y0 = y' `atIndex` xmin_ix renderSamples xscale yscale xmin xmax sd Nothing renderAreaSample (endAreaSample x0 y0) t' y' _ -> error "Data.hs renderSeries: cannot have error bars with area type" (DecBar bt) -> do@@ -394,25 +393,25 @@ (gw,_) <- formatPointSeries defaultPointType case dat of Left (Left (t',y')) -> do- let ln = dim $ snd $ t'+ let ln = size $ snd $ t' xmin_ix = findMinIdx (snd t') xmin 0 (ln-1)- rest (m,v) = (m,subVector 1 (dim v - 1) v)- x0 = (snd t') @> xmin_ix+ rest (m,v) = (m,subVector 1 (size v - 1) v)+ x0 = (snd t') `atIndex` xmin_ix y0 = 0 renderSamples xscale yscale xmin xmax sd (Just $ C.moveTo x0 y0) (renderHistSample bw bc c) endHistSample (rest t') y' Left (Right (Left ((t',y'),(_,e')))) -> do- let ln = dim $ snd $ t'+ let ln = size $ snd $ t' xmin_ix = findMinIdx (snd t') xmin 0 (ln-1)- rest (m,v) = (m,subVector 1 (dim v - 1) v)- x0 = (snd t') @> xmin_ix+ rest (m,v) = (m,subVector 1 (size v - 1) v)+ x0 = (snd t') `atIndex` xmin_ix y0 = 0 renderSamples xscale yscale xmin xmax sd (Just $ C.moveTo x0 y0) (renderHistSample bw bc c) endHistSample (rest t') y' renderSamples xscale yscale xmin xmax sd Nothing (renderPointSampleUpDown gw) endPointSample (midpoints t') e' Left (Right (Right ((t',y'),(_,l'),(_,h')))) -> do- let ln = dim $ snd $ t'+ let ln = size $ snd $ t' xmin_ix = findMinIdx (snd t') xmin 0 (ln-1)- rest (m,v) = (m,subVector 1 (dim v - 1) v)- x0 = (snd t') @> xmin_ix+ rest (m,v) = (m,subVector 1 (size v - 1) v)+ x0 = (snd t') `atIndex` xmin_ix y0 = 0 renderSamples xscale yscale xmin xmax sd (Just $ C.moveTo x0 y0) (renderHistSample bw bc c) endHistSample (rest t') y' renderSamples xscale yscale xmin xmax sd Nothing (renderPointSample gw Bot) endPointSample (midpoints t') l'@@ -448,7 +447,7 @@ -> (Bool,Vector Double) -> Vector Double -> Render () renderSamples xscale yscale xmin xmax sd s f e (mono,t) y = do (BoundingBox _ _ w _) <- get- let ln = dim t+ let ln = size t (xmin_ix,xmax_ix,num_pts) = if mono then (findMinIdx t xmin 0 (ln-1) ,findMaxIdx t xmax (ln-1) 0@@ -459,7 +458,7 @@ diff = if mono then if sd then diff' else 1 else 1 cairo $ do case s of- Nothing -> C.moveTo ((t @> xmin_ix)*xscale) ((y @> xmin_ix)*yscale)+ Nothing -> C.moveTo ((t `atIndex` xmin_ix)*xscale) ((y `atIndex` xmin_ix)*yscale) Just s' -> s' _ <- runMaybeT $ do mapVectorWithIndexM_ (\j y' -> do@@ -478,7 +477,7 @@ -> (Bool,Vector Double) -> (Vector Double,Vector Double) -> Render () renderMinMaxSamples xscale yscale xmin xmax sd s f e (mono,t) y = do (BoundingBox _ _ w _) <- get- let ln = dim t+ let ln = size t (xmin_ix,xmax_ix,num_pts) = if mono then (findMinIdx t xmin 0 (ln-1) ,findMaxIdx t xmax (ln-1) 0@@ -489,7 +488,7 @@ diff = if mono then if sd then diff' else 1 else 1 cairo $ do case s of- Nothing -> C.moveTo ((t @> xmin_ix)*xscale) (((fst $ y) @> xmin_ix)*yscale)+ Nothing -> C.moveTo ((t `atIndex` xmin_ix)*xscale) (((fst $ y) `atIndex` xmin_ix)*yscale) Just s' -> s' _ <- runMaybeT $ mapVectorWithIndexM_ (\j t' -> do when (j >= xmin_ix && j `mod` diff == 0)@@ -504,10 +503,10 @@ -> Double -> MaybeT C.Render () renderSample ix xmax_ix t f y | ix >= xmax_ix = do- lift $ f (t @> ix) y+ lift $ f (t `atIndex` ix) y fail "end of bounded area" | otherwise = do- lift $ f (t @> ix) y+ lift $ f (t `atIndex` ix) y renderMinMaxSample :: Int -> Int -> Double -> (Double -> (Double,Double) -> C.Render ()) -> C.Render () @@ -515,11 +514,11 @@ renderMinMaxSample ix xmax_ix t f e (yl,yu) | ix >= xmax_ix = do lift $ do- f t (yl @> ix,yu @> ix)+ f t (yl `atIndex` ix,yu `atIndex` ix) e fail "end of bounded area" | otherwise = do- lift $ f t (yl @> ix,yu @> ix)+ lift $ f t (yl `atIndex` ix,yu `atIndex` ix) -----------------------------------------------------------------------------
lib/Graphics/Rendering/Plot/Types.hs view
@@ -7,7 +7,7 @@ ----------------------------------------------------------------------------- -- | -- Module : Graphics.Rendering.Plot.Types--- Copyright : (c) A. V. H. McPhail 2010+-- Copyright : (c) A. V. H. McPhail 2010, 2015 -- License : BSD3 -- -- Maintainer : haskell.vivian.mcphail <at> gmail <dot> com@@ -22,8 +22,7 @@ ----------------------------------------------------------------------------- -import Data.Packed.Vector-import Data.Packed.Matrix+import Numeric.LinearAlgebra.Data hiding(Range) import Data.Colour.SRGB import Data.Colour()
plot.cabal view
@@ -1,8 +1,8 @@ Name: plot-Version: 0.2.3.4+Version: 0.2.3.5 License: BSD3 License-file: LICENSE-Copyright: (c) A.V.H. McPhail 2010, 2012, 2013, 2014+Copyright: (c) A.V.H. McPhail 2010, 2012, 2013, 2014, 2015 Author: Vivian McPhail Maintainer: haskell.vivian.mcphail <at> gmail <dot> com Stability: experimental@@ -35,7 +35,7 @@ . Category: Graphics -Tested-with: GHC==7.8.3+Tested-with: GHC==7.10.2 Cabal-version: >= 1.8 Build-type: Simple @@ -53,7 +53,7 @@ transformers > 0.2 && < 0.5, pango >= 0.11.2 && < 0.14, cairo >= 0.11.1 && < 0.14, colour >= 2.2.1 && < 2.4,- hmatrix >= 0.10+ hmatrix >= 0.17 Extensions: MultiParamTypeClasses GeneralizedNewtypeDeriving