packages feed

plot 0.1.4 → 0.1.4.1

raw patch · 6 files changed

+156/−76 lines, 6 files

Files

CHANGES view
@@ -68,3 +68,7 @@ 		* fix bar width for Candle/Whisker 		* fix x coordinate of Whisker 		* change bar width for Bar++0.1.4.1:+		* refactor renderSeries+		* fixed error bars for non-points
README view
@@ -21,11 +21,9 @@       package.      * The Haskell cairo bindings, which are packaged as part of-      gtk2hs.  Unfortunately, for various technical reasons, gtk2hs is-      not cabalized and cannot be downloaded and installed from-      Hackage.  To get gtk2hs you will need to go to the gtk2hs-      website (http://www.haskell.org/gtk2hs/) and follow the-      instructions to download and build it.+      gtk2hs.  +           cabal install gtk2hs-buildtools+	   cabal install gtk      * The colour library, which is available from Hackage.  If you use       the cabal-install build option described below, the colour
lib/Graphics/Rendering/Plot/Figure/Plot/Data.hs view
@@ -529,23 +529,23 @@  instance Ordinate Function                           where toOrdinate f         = OrdFunction Lower f Nothing instance Ordinate Series                             where toOrdinate s         = OrdPoints Lower (Plain s) Nothing-instance Ordinate (Series,ErrorSeries)               where toOrdinate (s,e)     = OrdPoints Lower (Error s (e,e)) Nothing-instance Ordinate (Series,(ErrorSeries,ErrorSeries)) where toOrdinate (s,(l,u)) = OrdPoints Lower (Error s (l,u)) Nothing+instance Ordinate (Series,ErrorSeries)               where toOrdinate (s,e)     = OrdPoints Lower (Error s (Left e)) Nothing+instance Ordinate (Series,(ErrorSeries,ErrorSeries)) where toOrdinate (s,(l,u)) = OrdPoints Lower (Error s (Right (l,u))) Nothing instance Ordinate (MinMaxSeries,(ErrorSeries,ErrorSeries)) where toOrdinate (s,(l,u)) = OrdPoints Lower (MinMax s (Just (l,u))) Nothing instance Ordinate (Function,AxisSide)                         where toOrdinate (f,ax)       = OrdFunction ax f Nothing instance Ordinate (Series,AxisSide)                           where toOrdinate (s,ax)       = OrdPoints ax (Plain s) Nothing-instance Ordinate (Series,ErrorSeries,AxisSide)               where toOrdinate (s,e,ax)     = OrdPoints ax (Error s (e,e)) Nothing-instance Ordinate (Series,(ErrorSeries,ErrorSeries),AxisSide) where toOrdinate (s,(l,u),ax) = OrdPoints ax (Error s (l,u)) Nothing+instance Ordinate (Series,ErrorSeries,AxisSide)               where toOrdinate (s,e,ax)     = OrdPoints ax (Error s (Left e)) Nothing+instance Ordinate (Series,(ErrorSeries,ErrorSeries),AxisSide) where toOrdinate (s,(l,u),ax) = OrdPoints ax (Error s (Right (l,u))) Nothing instance Ordinate (MinMaxSeries,(ErrorSeries,ErrorSeries),AxisSide) where toOrdinate (s,(l,u),ax) = OrdPoints ax (MinMax s (Just (l,u))) Nothing instance Ordinate (Function,SeriesLabel)                         where toOrdinate (f,la)       = OrdFunction Lower f (Just la) instance Ordinate (Series,SeriesLabel)                           where toOrdinate (s,la)       = OrdPoints Lower (Plain s) (Just la)-instance Ordinate (Series,ErrorSeries,SeriesLabel)               where toOrdinate (s,e,la)     = OrdPoints Lower (Error s (e,e)) (Just la)-instance Ordinate (Series,(ErrorSeries,ErrorSeries),SeriesLabel) where toOrdinate (s,(l,u),la) = OrdPoints Lower (Error s (l,u)) (Just la)+instance Ordinate (Series,ErrorSeries,SeriesLabel)               where toOrdinate (s,e,la)     = OrdPoints Lower (Error s (Left e)) (Just la)+instance Ordinate (Series,(ErrorSeries,ErrorSeries),SeriesLabel) where toOrdinate (s,(l,u),la) = OrdPoints Lower (Error s (Right (l,u))) (Just la)  instance Ordinate (Function,AxisSide,SeriesLabel)                          where toOrdinate (f,ax,la)       = OrdFunction ax f (Just la) instance Ordinate (Series,AxisSide,SeriesLabel)                            where toOrdinate (s,ax,la)       = OrdPoints ax (Plain s) (Just la)-instance Ordinate (Series,ErrorSeries,AxisSide,SeriesLabel)                where toOrdinate (s,e,ax,la)     = OrdPoints ax (Error s (e,e)) (Just la)-instance Ordinate (Series,(ErrorSeries,ErrorSeries),AxisSide,SeriesLabel)  where toOrdinate (s,(l,u),ax,la) = OrdPoints ax (Error s (l,u)) (Just la)+instance Ordinate (Series,ErrorSeries,AxisSide,SeriesLabel)                where toOrdinate (s,e,ax,la)     = OrdPoints ax (Error s (Left e)) (Just la)+instance Ordinate (Series,(ErrorSeries,ErrorSeries),AxisSide,SeriesLabel)  where toOrdinate (s,(l,u),ax,la) = OrdPoints ax (Error s (Right (l,u))) (Just la) instance Ordinate (MinMaxSeries,(ErrorSeries,ErrorSeries),AxisSide,SeriesLabel) where toOrdinate (s,(l,u),ax,la) = OrdPoints ax (MinMax s (Just (l,u))) (Just la)  class Decorations a where
lib/Graphics/Rendering/Plot/Render/Plot/Data.hs view
@@ -52,6 +52,7 @@ import Graphics.Rendering.Plot.Render.Plot.Format import Graphics.Rendering.Plot.Render.Plot.Glyph --import Graphics.Rendering.Plot.Render.Plot.Annotation+import Graphics.Rendering.Plot.Defaults  import Prelude hiding(min,max,abs) import qualified Prelude@@ -162,107 +163,179 @@              -- could filter annotations as well   return () +logSeries :: Scale -> Vector Double -> Vector Double+logSeries Log a = logBase 10 $ mapVector zeroToOne a+logSeries _   a = a++midpoints(mi,v) = let v' = subVector 1 (dim v - 1) v+                      w' = subVector 0 (dim v - 1) v+                  in (mi,(v'+w')/2.0)++logSeriesMinMax :: Scale -> (Vector Double,Vector Double) -> (Vector Double,Vector Double)+logSeriesMinMax Log    (v,w) = (logSeries Log v,logSeries Log w)+logSeriesMinMax Linear x     = x+ renderSeries :: Scale -> Scale               -> Double -> Double -> Double -> Double               -> (Abscissae,DecoratedSeries) -> Render () renderSeries xsc ysc xmin xmax xscale yscale (abs,(DecSeries o d)) = do-  dat' <- case o of+  dat  <- case o of           (OrdFunction _ f _)            -> do                  (BoundingBox _ _ w _) <- get-                 let t = linspace (round w) (xmin,xmax)-                 return $ Left [((True,t),mapVector f t)]+                 let t = logSeries xsc $ linspace (round w) (xmin,xmax)+                 return $ Left $ Left ((True,t),logSeries ysc $ mapVector f t)           (OrdPoints _ (Plain o') _)     -> do                  let t = case abs of                            AbsFunction      -> if isHist d                                               then (True,fromList [0.0..(fromIntegral $ dim o')])                                               else (True,fromList [1.0..(fromIntegral $ dim o')])                            AbsPoints mi t'  -> (mi,t')-                 return $ Left [(t,o')]-          (OrdPoints _ (Error o' (l,h)) _) -> do+                 return $ Left $ Left ((fst t,logSeries xsc $ snd t),logSeries ysc $ o')+          (OrdPoints _ (Error o' (Left e)) _) -> do                  let t = case abs of                            AbsFunction      -> if isHist d                                               then (True,fromList [0.0..(fromIntegral $ dim o')])                                               else (True,fromList [1.0..(fromIntegral $ dim o')])                            AbsPoints mi t'  -> (mi,t')-                 return $ Left [(t,o'),(t,o'-l),(t,o'+h)]+                 let t' = (fst t,logSeries xsc $ snd t)+                 return $ Left $ Right $ Left ((t',logSeries ysc $ o'),(t',logSeries ysc $ e))+          (OrdPoints _ (Error o' (Right (l,h))) _) -> do+                 let t = case abs of+                           AbsFunction      -> if isHist d+                                              then (True,fromList [0.0..(fromIntegral $ dim o')])+                                              else (True,fromList [1.0..(fromIntegral $ dim 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      -> (True,fromList [1.0..(fromIntegral $ dim $ 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      -> (True,fromList [1.0..(fromIntegral $ dim l)])                            AbsPoints mi t'  -> (mi,t')-                 return $ Right [((t,o'),(t,(l,h)))]-  let dat = case dat' of-            Left dat'' → map (\((m,a),b) -> Left (if xsc == Log then (m,logBase 10 a) else (m,a)-                                                ,if ysc == Log then (logBase 10 b) else b)) dat''-            Right dat''' -> map (\(((m1,a),(bl,bu)),((m2,c),(dl,du))) → let (a',c') = if xsc == Log then (logBase 10 $ mapVector zeroToOne a,logBase 10 $ mapVector zeroToOne c) else (a,c)-                                                                            (bl',bu',dl',du') = if ysc == Log then (logBase 10 bl,logBase 10 bu,logBase 10 dl,logBase 10 du) else (bl,bu,dl,du) -                                                                       in Right (((m1,a'),(bl',bu')),((m2,c'),(dl',du')))) dat'''+                 let t' = (fst t,logSeries xsc $ snd t)+                 return $ Right $ Right ((t',logSeriesMinMax ysc o'),(t',(logSeries ysc l,logSeries ysc h)))   case d of     (DecLine lt)   -> do            formatLineSeries lt-           mapM_ (\(t',y') -> renderSamples xscale yscale xmin xmax Nothing -                             renderLineSample endLineSample t' y') (map (either id (error "MinMax data")) dat)+           case dat of+             Left (Left (t',y')) -> do+               renderSamples xscale yscale xmin xmax Nothing renderLineSample endLineSample t' y'+             _  -> error "Data.hs renderSeries: cannot have error bars with line type"     (DecPoint pt)  -> do            (pz,g) <- formatPointSeries pt-           let gs = g : Bot : Top : []-           mapM_ (\(g',(t',y')) -> renderSamples xscale yscale xmin xmax Nothing -                                  (renderPointSample pz g') endPointSample t' y') -                     (zip gs (map (either id (error "MinMax data")) dat))+           case dat of+             Left (Left (t',y')) -> do+               renderSamples xscale yscale xmin xmax Nothing (renderPointSample pz g) endPointSample t' y'+             Left (Right (Left _)) -> do+               error "Data.hs renderSeries: cannot have single error value with points type"        +             Left (Right (Right ((t',y'),(_,l),(_,h)))) -> do+               renderSamples xscale yscale xmin xmax Nothing (renderPointSample pz g) endPointSample t' y'+               renderSamples xscale yscale xmin xmax Nothing (renderPointSample pz Bot) endPointSample t' l +               renderSamples xscale yscale xmin xmax Nothing (renderPointSample pz Top) endPointSample t' h +             _  -> error "Data.hs renderSeries: cannot have MinMax data series with point type"     (DecLinPt lt pt) -> do            formatLineSeries lt-           mapM_ (\(t',y') -> renderSamples xscale yscale xmin xmax Nothing -                             renderLineSample endLineSample t' y') (map (either id (error "MinMax data")) dat)            (pz,g) <- formatPointSeries pt-           let gs = g : Bot : Top : []-           mapM_ (\(g',(t',y')) -> renderSamples xscale yscale xmin xmax Nothing -                                  (renderPointSample pz g') endPointSample t' y')-                     (zip gs (map (either id  (error "MinMax data")) dat))+           case dat of+             Left (Left (t',y')) -> do+               renderSamples xscale yscale xmin xmax Nothing renderLineSample endLineSample t' y'+               renderSamples xscale yscale xmin xmax Nothing (renderPointSample pz g) endPointSample t' y'+             Left (Right (Left _)) -> do+               error "Data.hs renderSeries: cannot have single error value with line-points type"        +             Left (Right (Right ((t',y'),(_,l),(_,h)))) -> do+               renderSamples xscale yscale xmin xmax Nothing renderLineSample endLineSample t' y'+               renderSamples xscale yscale xmin xmax Nothing (renderPointSample pz g) endPointSample t' y'+               renderSamples xscale yscale xmin xmax Nothing (renderPointSample pz Bot) endPointSample t' l +               renderSamples xscale yscale xmin xmax Nothing (renderPointSample pz Top) endPointSample t' h +             _  -> error "Data.hs renderSeries: cannot have MinMax data series with line-point type"     (DecImpulse lt) -> do            formatLineSeries lt-           mapM_ (\(t',y') -> renderSamples xscale yscale xmin xmax Nothing -                             renderImpulseSample endImpulseSample t' y') (map (either id (error "MinMax data")) dat)+           case dat of+             Left (Left (t',y')) -> do+               renderSamples xscale yscale xmin xmax Nothing renderImpulseSample endImpulseSample t' y'+             _  -> error "Data.hs renderSeries: cannot have error bars with impulse type"     (DecStep lt) -> do            formatLineSeries lt-           mapM_ (\(t',y') -> renderSamples xscale yscale xmin xmax Nothing -                             renderStepSample endStepSample t' y') (map (either id (error "MinMax data")) dat)+           case dat of+             Left (Left (t',y')) -> do+               renderSamples xscale yscale xmin xmax Nothing renderStepSample endStepSample t' y'+             _  -> error "Data.hs renderSeries: cannot have error bars with step type"     (DecArea lt) -> do            formatLineSeries lt-           let Left hd = head dat-               ln = dim $ snd $ fst hd-               xmin_ix = findMinIdx (snd $ fst hd) xmin 0 (ln-1)-               x0 = (snd $ fst hd) @> xmin_ix-               y0 = (snd hd) @> xmin_ix-           mapM_ (\(t',y') -> renderSamples xscale yscale xmin xmax Nothing -                             renderAreaSample (endAreaSample x0 y0) t' y') (map (either id (error "MinMax data")) dat)+           case dat of+             Left (Left (t',y')) -> do+                let ln = dim $ snd t'+                    xmin_ix = findMinIdx (snd t') xmin 0 (ln-1)+                    x0 = (snd t') @> xmin_ix+                    y0 = y' @> xmin_ix+                renderSamples xscale yscale xmin xmax Nothing renderAreaSample (endAreaSample x0 y0) t' y'+             _  -> error "Data.hs renderSeries: cannot have error bars with area type"     (DecBar bt)   -> do-           (bw,bc,c) <- formatBarSeries bt-           mapM_ (\(t',y') -> renderSamples xscale yscale xmin xmax Nothing -                             (renderBarSample bw bc c) endBarSample t' y') (map (either id (error "MinMax data")) dat)+         (bw,bc,c) <- formatBarSeries bt+         (gw,_) <- formatPointSeries defaultPointType +         case dat of+             Left (Left (t',y')) -> do+               renderSamples xscale yscale xmin xmax Nothing (renderBarSample bw bc c) endBarSample t' y' +             Left (Right (Left ((t',y'),(_,e')))) -> do+               renderSamples xscale yscale xmin xmax Nothing (renderBarSample bw bc c) endBarSample t' y' +               renderSamples xscale yscale xmin xmax Nothing (renderPointSampleUpDown gw) endPointSample t' e'+             Left (Right (Right ((t',y'),(_,l'),(_,h')))) -> do+               renderSamples xscale yscale xmin xmax Nothing (renderBarSample bw bc c) endBarSample t' y' +               renderSamples xscale yscale xmin xmax Nothing (renderPointSample gw Bot) endPointSample t' l'+               renderSamples xscale yscale xmin xmax Nothing (renderPointSample gw Top) endPointSample t' h'+             _  -> error "Data.hs renderSeries: cannot have MinMax data series with bar type"     (DecHist bt)  -> do-           (bw,bc,c) <- formatBarSeries bt-           let Left hd = head dat-               ln = dim $ snd $ fst hd-               xmin_ix = findMinIdx (snd $ fst hd) xmin 0 (ln-1)-               rest (m,v) = (m,subVector 1 (dim v - 1) v)-               x0 = (snd $ fst hd) @> xmin_ix-               y0 = 0-           mapM_ (\(t',y') -> renderSamples xscale yscale xmin xmax (Just $ C.moveTo x0 y0) -                             (renderHistSample bw bc c) endHistSample (rest t') y') (map (either id (error "MinMax data")) dat)+         (bw,bc,c) <- formatBarSeries bt+         (gw,_) <- formatPointSeries defaultPointType +         case dat of+             Left (Left (t',y')) -> do+               let ln = dim $ 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+                   y0 = 0+               renderSamples xscale yscale xmin xmax (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'+                   xmin_ix = findMinIdx (snd t') xmin 0 (ln-1)+                   rest (m,v) = (m,subVector 1 (dim v - 1) v)+                   x0 = (snd t') @> xmin_ix+                   y0 = 0+               renderSamples xscale yscale xmin xmax (Just $ C.moveTo x0 y0) (renderHistSample bw bc c) endHistSample (rest t') y'+               renderSamples xscale yscale xmin xmax Nothing (renderPointSampleUpDown gw) endPointSample (midpoints t') e'+             Left (Right (Right ((t',y'),(_,l'),(_,h')))) -> do+               let ln = dim $ 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+                   y0 = 0+               renderSamples xscale yscale xmin xmax (Just $ C.moveTo x0 y0) (renderHistSample bw bc c) endHistSample (rest t') y'+               renderSamples xscale yscale xmin xmax Nothing (renderPointSample gw Bot) endPointSample (midpoints t') l'+               renderSamples xscale yscale xmin xmax Nothing (renderPointSample gw Top) endPointSample (midpoints t') h'+             _  -> error "Data.hs renderSeries: cannot have MinMax data series with histogram type"     (DecCand bt)  → do       (bw,bc,c) ← formatBarSeries bt-      mapM_ (\((t',y'),(_,e')) → do-               renderMinMaxSamples xscale yscale xmin xmax Nothing-                          (renderWhiskerSample bw bc c False) endWhiskerSample t' e'-               renderMinMaxSamples xscale yscale xmin xmax Nothing-                          (renderCandleSample bw bc c) endCandleSample t' y'-            ) (map (either (error "Single data") id) dat)+      case dat of +          Left _ -> error "Candles series requires two data series (MinMax series)"+          Right (Left (t',y')) -> do+               renderMinMaxSamples xscale yscale xmin xmax Nothing (renderCandleSample bw bc c) endCandleSample t' y'+          Right (Right ((t',y'),(_,e'))) → do+               renderMinMaxSamples xscale yscale xmin xmax Nothing (renderWhiskerSample bw bc c False) endWhiskerSample t' e'+               renderMinMaxSamples xscale yscale xmin xmax Nothing (renderCandleSample bw bc c) endCandleSample t' y'     (DecWhisk bt)  → do       (bw,bc,c) ← formatBarSeries bt-      mapM_ (\((t',y'),(_,e')) → do-               renderMinMaxSamples xscale yscale xmin xmax Nothing-                          (renderWhiskerSample bw bc c True) endWhiskerSample t' e'-               renderMinMaxSamples xscale yscale xmin xmax Nothing-                          (renderCandleSample bw bc c) endCandleSample t' y'-            ) (map (either (error "Single data") id) dat)+      case dat of +          Left _ -> error "Candles series requires two data series (MinMax series)"+          Right (Left (t',y')) -> do+               renderMinMaxSamples xscale yscale xmin xmax Nothing (renderCandleSample bw bc c) endCandleSample t' y'+          Right (Right ((t',y'),(_,e'))) → do+               renderMinMaxSamples xscale yscale xmin xmax Nothing (renderWhiskerSample bw bc c True) endWhiskerSample t' e'+               renderMinMaxSamples xscale yscale xmin xmax Nothing (renderCandleSample bw bc c) endCandleSample t' y'   return ()  -----------------------------------------------------------------------------@@ -359,6 +432,11 @@ renderPointSample pz g xscale yscale x y = do   C.moveTo (x*xscale) (y*yscale)   renderGlyph pz g++renderPointSampleUpDown :: LineWidth -> Double -> Double -> Double -> Double -> C.Render ()+renderPointSampleUpDown pz xscale yscale x y = do+  C.moveTo (x*xscale) (y*yscale)+  renderGlyph pz (if y < 0 then Bot else Top)  endPointSample :: Double -> Double -> C.Render () endPointSample _ _ = return ()
lib/Graphics/Rendering/Plot/Types.hs view
@@ -270,7 +270,7 @@ --instance Show Function where show _ = "<<function>>"  data OrdSeries = Plain Series-               | Error Series (ErrorSeries,ErrorSeries)+               | Error Series (Either ErrorSeries (ErrorSeries,ErrorSeries))                | MinMax MinMaxSeries (Maybe (ErrorSeries,ErrorSeries))  getOrdData :: OrdSeries -> Series
plot.cabal view
@@ -1,8 +1,8 @@ Name:                plot-Version:             0.1.4+Version:             0.1.4.1 License:             BSD3 License-file:        LICENSE-Copyright:           (c) A.V.H. McPhail 2010+Copyright:           (c) A.V.H. McPhail 2010, 2012 Author:              Vivian McPhail Maintainer:          haskell.vivian.mcphail <at> gmail <dot> com Stability:           experimental