plot 0.1.5.1 → 0.1.6
raw patch · 3 files changed
+63/−20 lines, 3 files
Files
- CHANGES +6/−0
- lib/Graphics/Rendering/Plot/Render/Plot/Axis.hs +56/−19
- plot.cabal +1/−1
CHANGES view
@@ -83,3 +83,9 @@ * fixed bug in location of `Value` axis * added data labels to axes * fix some warnings++0.1.5.1:+ * changed _data_label to _tick_label++0.1.6:+ * added TickValue renderer
lib/Graphics/Rendering/Plot/Render/Plot/Axis.hs view
@@ -27,6 +27,8 @@ import Data.List +import Data.Packed.Vector+ import qualified Graphics.Rendering.Cairo as C import qualified Graphics.Rendering.Pango as P @@ -315,14 +317,23 @@ lineTo (x+w) (y+h+lw) C.stroke -tickPosition :: Scale -> Double -> Double -> Int -> [(Double,Double)]-tickPosition sc min max n = - let pos = map (\x -> min + (max-min)*(x)/(fromIntegral (n-1))) (take n [(0 :: Double)..])+tickPosition :: Scale -> Double -> Double -> Either Int [Double] -> [(Double,Double)]+tickPosition sc min max (Left n) = + let ticks = take n [(0::Double)..]+ l = fromIntegral $ n-1+ pos = map (\x -> min + (max-min)*(x)/l) ticks val = if sc == Log- then map (\x -> logBase 10 min + (x/(fromIntegral (n-1))) * (logBase 10 max - logBase 10 min))- (take n [(0 :: Double)..])+ then map (\x -> logBase 10 min + (x/l) * (logBase 10 max - logBase 10 min)) pos else pos in zip pos val+tickPosition sc min max (Right vs) = + let ticks = vs+ l = fromIntegral $ length vs - 1+ pos = ticks -- map (\x -> min + (max-min)*(x/l)) ticks+ val = if sc == Log+ then map (\x -> logBase 10 min + (x/l) * (logBase 10 max - logBase 10 min)) pos+ else pos+ in zip pos val {- tickPosition min max n = let diff = max - min (sc,sd) = scaleDiff 1.0 diff n@@ -336,8 +347,7 @@ renderAxisTicks :: Ranges -> AxisType -> AxisPosn -> Maybe Ticks -> Maybe Ticks -> TickFormat -> [TextEntry] -> Render ()-renderAxisTicks (Ranges xrange yrange) ax sd- (Just (Ticks gmin (TickNumber tmin))) (Just (Ticks gmaj (TickNumber tmaj))) tf dl = do+renderAxisTicks (Ranges xrange yrange) ax sd tmn tmj tf dl = do (BoundingBox x y w h) <- get to <- asks (_textoptions . _renderoptions) pc <- asks _pangocontext@@ -371,19 +381,46 @@ in Value (y+h*(t-v)/(t-b)) YAxis -> let (Range _ b t) = lowerRange xrange in Value (x+w*(v-b)/(t-b))- let (pos,val) = unzip (tickPosition sc min max tmaj) - let ln = length pos- let dl' = if null dl then replicate ln Nothing else map Just dl- let majpos = let ones = 1.0 : ones- in zip4 pos (take ln ones) val dl'- (pos',val') = unzip (tickPosition sc min max tmin)- ln' = length pos'- minpos' = zip4 pos' (minorTickLengths tmin tmaj) val' - (replicate ln' Nothing)- minpos = filter (not . (\(p,_,_,_) -> elem p pos)) minpos' + let renderAxisTick' = renderAxisTick pc to x y w h sc min max ax sd' tf - mapM_ (renderAxisTick' Minor gmin) minpos - mapM_ (renderAxisTick' Major gmaj) majpos+ (majpos',gmaj',tjpos,tmaj') <- case tmj of+ (Just (Ticks gmaj (TickNumber tmaj))) -> do+ let (pos,val) = unzip (tickPosition sc min max (Left tmaj)) + let ln = length pos+ let dl' = if null dl then replicate ln Nothing else map Just dl+ let majpos = let ones = 1.0 : ones+ in zip4 pos (take ln ones) val dl'+ return $ (Just majpos,Just gmaj,Just pos,Just tmaj)+ (Just (Ticks gmaj (TickValues tmaj))) -> do+ let (pos,val) = unzip (tickPosition sc min max (Right $ toList tmaj))+ ln = length pos+ let dl' = if null dl then replicate ln Nothing else map Just dl+ let majpos = let ones = 1.0 : ones+ in zip4 pos (take ln ones) val dl'+ return $ (Just majpos,Just gmaj,Just pos,Nothing)+ Nothing -> return (Nothing,Nothing,Nothing,Nothing)+ (minpos',gmin') <- case tmn of+ (Just (Ticks gmin (TickNumber tmin))) -> do+ let (pos',val') = unzip (tickPosition sc min max (Left tmin))+ ln' = length pos'+ minpos' = zip4 pos' (minorTickLengths tmin (maybe 0 id tmaj')) val' + (replicate ln' Nothing)+ minpos = filter (not . (\(p,_,_,_) -> elem p (maybe [] id tjpos))) minpos'+ return $ (Just minpos,Just gmin)+ (Just (Ticks gmin (TickValues tmin))) -> do+ let (pos,val) = unzip (tickPosition sc min max (Right $ toList tmin))+ ln = length pos+ minpos' = let halves = 0.7 : halves+ in zip4 pos halves pos (replicate ln Nothing)+ minpos = filter (not . (\(p,_,_,_) -> elem p (maybe [] id tjpos))) minpos'+ return $ (Just minpos,Just gmin)+ Nothing -> return (Nothing,Nothing)+ case majpos' of+ (Just m) -> mapM_ (renderAxisTick' Major (maybe NoLine id gmaj')) m+ Nothing -> return ()+ case minpos' of+ (Just m) -> mapM_ (renderAxisTick' Minor (maybe NoLine id gmin')) m+ Nothing -> return () return () return ()
plot.cabal view
@@ -1,5 +1,5 @@ Name: plot-Version: 0.1.5.1+Version: 0.1.6 License: BSD3 License-file: LICENSE Copyright: (c) A.V.H. McPhail 2010, 2012