From 6277517735d259ab7e9305968f05433e6d895a10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Buckwalter?= Date: Tue, 23 May 2017 13:33:41 +0200 Subject: [PATCH 1/3] Whitespace cleanup (courtesy of Atom). --- chart/Graphics/Rendering/Chart/Axis/Floating.hs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/chart/Graphics/Rendering/Chart/Axis/Floating.hs b/chart/Graphics/Rendering/Chart/Axis/Floating.hs index cee0a362..3c12b261 100644 --- a/chart/Graphics/Rendering/Chart/Axis/Floating.hs +++ b/chart/Graphics/Rendering/Chart/Axis/Floating.hs @@ -186,7 +186,7 @@ data LinearAxisParams a = LinearAxisParams { } instance (Show a, RealFloat a) => Default (LinearAxisParams a) where - def = LinearAxisParams + def = LinearAxisParams { _la_labelf = showDs , _la_nLabels = 5 , _la_nTicks = 50 @@ -249,7 +249,7 @@ autoSteps nSteps vs = map fromRational $ steps (fromIntegral nSteps) r ---------------------------------------------------------------------- instance (Show a, RealFloat a) => Default (LogAxisParams a) where - def = LogAxisParams + def = LogAxisParams { _loga_labelf = showDs } @@ -299,17 +299,17 @@ logTicks (low,high) = (major,minor,major) maximum (1:filter (\x -> log10 (fromRational x) <= r) l)*10^^i upper a l = let (i,r) = pf (log10 a) in minimum (10:filter (\x -> r <= log10 (fromRational x)) l)*10^^i - + powers :: (Double,Double) -> [Rational] -> [Rational] powers (x,y) l = [ a*10^^p | p <- [(floor (log10 x))..(ceiling (log10 y))] :: [Integer] , a <- l ] midselection r l = filter (inRange r l) (powers r l) inRange (a,b) l x = (lower a l <= x) && (x <= upper b l) - + logRange = (log10 low, log10 high) - + roundPow x = 10^^(round x :: Integer) - + major | 17.5 < log10 ratio = map roundPow $ steps (min 5 (log10 ratio)) logRange | 12 < log10 ratio = map roundPow $ @@ -326,8 +326,8 @@ logTicks (low,high) = (major,minor,major) (dl',dh') = (fromRational l', fromRational h') ratio' :: Double ratio' = fromRational (h'/l') - filterX = filter (\x -> l'<=x && x <=h') . powers (dl',dh') - + filterX = filter (\x -> l'<=x && x <=h') . powers (dl',dh') + minor | 50 < log10 ratio' = map roundPow $ steps 50 (log10 dl', log10 dh') | 6 < log10 ratio' = filterX [1,10] From e350f6f210a932d1f756db6d6b6fc1c0d0998202 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Buckwalter?= Date: Tue, 23 May 2017 13:40:31 +0200 Subject: [PATCH 2/3] scaledAxis' accepting Maybe bounds. --- chart/Graphics/Rendering/Chart/Axis/Floating.hs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/chart/Graphics/Rendering/Chart/Axis/Floating.hs b/chart/Graphics/Rendering/Chart/Axis/Floating.hs index 3c12b261..a3f30440 100644 --- a/chart/Graphics/Rendering/Chart/Axis/Floating.hs +++ b/chart/Graphics/Rendering/Chart/Axis/Floating.hs @@ -19,6 +19,7 @@ module Graphics.Rendering.Chart.Axis.Floating( LogValue(..), LogAxisParams(..), scaledAxis, + scaledAxis', autoScaledAxis, autoScaledLogAxis, autoSteps, @@ -31,6 +32,7 @@ module Graphics.Rendering.Chart.Axis.Floating( ) where import Data.List(minimumBy) +import Data.Maybe (fromMaybe) import Data.Ord (comparing) import Data.Default.Class import Numeric (showEFloat, showFFloat) @@ -208,6 +210,14 @@ scaledAxis lap rs@(minV,maxV) ps0 = makeAxis' realToFrac realToFrac gridvs = labelvs r = range ps +-- | Generate a linear axis with the optionally specified bounds. +-- Unspecified bounds are computed automatically. +scaledAxis' :: RealFloat a => LinearAxisParams a -> (Maybe a, Maybe a) -> AxisFn a +scaledAxis' lap (minV,maxV) ps0 = scaledAxis lap rs ps + where + ps = filter isValidNumber ps0 + rs = (fromMaybe (minimum ps) minV, fromMaybe (maximum ps) maxV) + -- | Generate a linear axis automatically, scaled appropriately for the -- input data. autoScaledAxis :: RealFloat a => LinearAxisParams a -> AxisFn a From 24a00cf12f917bde829cf7f29d1f6dcdc80cbb82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Buckwalter?= Date: Tue, 23 May 2017 13:41:47 +0200 Subject: [PATCH 3/3] Define autoScaledAxis in terms of scaledAxis'. --- chart/Graphics/Rendering/Chart/Axis/Floating.hs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/chart/Graphics/Rendering/Chart/Axis/Floating.hs b/chart/Graphics/Rendering/Chart/Axis/Floating.hs index a3f30440..2b8dffd7 100644 --- a/chart/Graphics/Rendering/Chart/Axis/Floating.hs +++ b/chart/Graphics/Rendering/Chart/Axis/Floating.hs @@ -221,10 +221,7 @@ scaledAxis' lap (minV,maxV) ps0 = scaledAxis lap rs ps -- | Generate a linear axis automatically, scaled appropriately for the -- input data. autoScaledAxis :: RealFloat a => LinearAxisParams a -> AxisFn a -autoScaledAxis lap ps0 = scaledAxis lap rs ps - where - ps = filter isValidNumber ps0 - rs = (minimum ps,maximum ps) +autoScaledAxis lap = scaledAxis' lap (Nothing, Nothing) steps :: RealFloat a => a -> (a,a) -> [Rational] steps nSteps rs@(minV,maxV) = map ((s*) . fromIntegral) [min' .. max']