plot-light 0.4.1 → 0.4.2
raw patch · 8 files changed
+73/−73 lines, 8 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Data.TimeSeries: Tick :: Day -> TimeOfDay -> Tick
- Data.TimeSeries: Tsp :: Tick -> a -> TsPoint a
- Data.TimeSeries: [_tick] :: TsPoint a -> Tick
- Data.TimeSeries: [_val] :: TsPoint a -> a
- Data.TimeSeries: data Tick
- Data.TimeSeries: data TsPoint a
- Data.TimeSeries: fromTick :: Tick -> Rational
- Data.TimeSeries: halfHourTick :: Rational
- Data.TimeSeries: hourTick :: Rational
- Data.TimeSeries: instance GHC.Classes.Eq Data.TimeSeries.Tick
- Data.TimeSeries: instance GHC.Classes.Eq a => GHC.Classes.Eq (Data.TimeSeries.TsPoint a)
- Data.TimeSeries: instance GHC.Classes.Ord Data.TimeSeries.Tick
- Data.TimeSeries: instance GHC.Show.Show Data.TimeSeries.Tick
- Data.TimeSeries: instance GHC.Show.Show a => GHC.Show.Show (Data.TimeSeries.TsPoint a)
- Data.TimeSeries: mkTick :: Integer -> Int -> Int -> Int -> Int -> Pico -> Maybe Tick
- Data.TimeSeries: quarterHourTick :: Rational
- Data.TimeSeries: tickToFractional :: Fractional b => TsPoint a -> b
- Data.TimeSeries: toTick :: Rational -> Tick
+ Graphics.Rendering.Plot.Light: fromTick :: Tick -> Rational
+ Graphics.Rendering.Plot.Light: toTick :: Rational -> Tick
Files
- plot-light.cabal +3/−3
- src/Data/TimeSeries.hs +0/−61
- src/Graphics/Rendering/Plot/Light.hs +3/−1
- src/Graphics/Rendering/Plot/Light/PlotTypes.hs +1/−1
- src/Graphics/Rendering/Plot/Light/PlotTypes/Heatmap.hs +1/−0
- src/Graphics/Rendering/Plot/Light/PlotTypes/Plot1D.hs +6/−0
- src/Graphics/Rendering/Plot/Light/PlotTypes/TimeSeries.hs +57/−5
- test/LibSpec.hs +2/−2
plot-light.cabal view
@@ -1,5 +1,5 @@ name: plot-light-version: 0.4.1+version: 0.4.2 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. @@ -24,11 +24,11 @@ ghc-options: -Wno-missing-signatures -Wno-type-defaults -Wno-name-shadowing -Wno-unused-local-binds -Wno-unused-top-binds -Wno-unused-imports hs-source-dirs: src exposed-modules: Graphics.Rendering.Plot.Light- Data.TimeSeries- Graphics.Rendering.Plot.Light.PlotTypes Graphics.Rendering.Plot.Light.Internal.Geometry other-modules: Graphics.Rendering.Plot.Light.Internal+ Graphics.Rendering.Plot.Light.PlotTypes Graphics.Rendering.Plot.Light.Internal.Layout+ Graphics.Rendering.Plot.Light.PlotTypes.Plot1D Graphics.Rendering.Plot.Light.PlotTypes.Heatmap Graphics.Rendering.Plot.Light.PlotTypes.Scatter Graphics.Rendering.Plot.Light.PlotTypes.Histogram
− src/Data/TimeSeries.hs
@@ -1,61 +0,0 @@-module Data.TimeSeries where--import Data.Time-import Data.Fixed (Pico)-import Graphics.Rendering.Plot.Light.Internal.Utils---- | An instant, defined by date (Day) and TimeOfDay-data Tick = Tick Day TimeOfDay- deriving (Eq, Show, Ord)---- | Create a Tick from valid (year, month, day, hour, minute, second)-mkTick :: Integer -> Int -> Int -> Int -> Int -> Pico -> Maybe Tick-mkTick yy mm dd hr mi se = do- tim <- makeTimeOfDayValid hr mi se- let d = fromGregorian yy mm dd- return $ Tick d tim---- | A point in a time series-data TsPoint a =- Tsp {- _tick :: Tick,- _val :: a- } deriving (Eq, Show)--tickToFractional :: Fractional b => TsPoint a -> b-tickToFractional = fromRational . fromTick . _tick---- | Map a Tick onto the rationals-fromTick :: Tick -> Rational-fromTick (Tick d t) = fromIntegral (toModifiedJulianDay d) + timeOfDayToDayFraction t- --- | Map a rational onto a Tick-toTick :: Rational -> Tick-toTick n = Tick d t- where- t = dayFractionToTimeOfDay dec- d = ModifiedJulianDay wh- (wh, dec) = wholeDecimal n---hourTick, halfHourTick, quarterHourTick :: Rational-hourTick = 1/24-halfHourTick = 1/2 * hourTick-quarterHourTick = 1/4 * hourTick----- locTime :: IO LocalTime--- locTime = do--- tz <- getCurrentTimeZone--- ct <- getCurrentTime--- return $ utcToLocalTime tz ct----- ---- tickRange :: Tick -> Tick -> Rational -> [Tick]--- tickRange t1 t2 dt = toTick <$> [td1, td1 + dt .. td2] where--- td1 = fromTick t1--- td2 = fromTick t2
src/Graphics/Rendering/Plot/Light.hs view
@@ -144,7 +144,9 @@ -- ** Colour utilities blendTwo, palette, pickColour, -- *** ShapeCol-related- ShapeCol(..), Col(..), + ShapeCol(..), Col(..),+ -- ** TimeSeries utilities+ fromTick, toTick, -- ** SVG utilities svgHeader, translateSvg, toSvgFrame, toSvgFrameLP, -- * Geometric types
src/Graphics/Rendering/Plot/Light/PlotTypes.hs view
@@ -1,13 +1,13 @@ module Graphics.Rendering.Plot.Light.PlotTypes (module X) where import Graphics.Rendering.Plot.Light.PlotTypes.TimeSeries as X+import Graphics.Rendering.Plot.Light.PlotTypes.Plot1D as X import Graphics.Rendering.Plot.Light.PlotTypes.Heatmap as X import Graphics.Rendering.Plot.Light.PlotTypes.Scatter as X import Graphics.Rendering.Plot.Light.PlotTypes.Histogram as X import Data.Parsers as X -import Data.TimeSeries as X
src/Graphics/Rendering/Plot/Light/PlotTypes/Heatmap.hs view
@@ -129,3 +129,4 @@ +
+ src/Graphics/Rendering/Plot/Light/PlotTypes/Plot1D.hs view
@@ -0,0 +1,6 @@+module Graphics.Rendering.Plot.Light.PlotTypes.Plot1D (plotFun) where++import Graphics.Rendering.Plot.Light.Internal++plotFun f = fmap f' where+ f' p@(Point x _) = LabeledPoint p (f x)
src/Graphics/Rendering/Plot/Light/PlotTypes/TimeSeries.hs view
@@ -5,15 +5,15 @@ import Control.Monad (forM_) -- import GHC.Real--- import Data.Fixed (Pico)--- import Data.Time+import Data.Fixed (Pico)+import Data.Time+ -- import Data.Scientific import qualified Data.Text as T import Graphics.Rendering.Plot.Light.Internal -- import Graphics.Rendering.Plot.Light.Internal.Utils-import Data.TimeSeries -- For debugging import Text.Blaze.Svg@@ -91,7 +91,61 @@ +-- | An instant, defined by date (Day) and TimeOfDay+data Tick = Tick Day TimeOfDay+ deriving (Eq, Show, Ord) +-- | Create a Tick from valid (year, month, day, hour, minute, second)+mkTick :: Integer -> Int -> Int -> Int -> Int -> Pico -> Maybe Tick+mkTick yy mm dd hr mi se = do+ tim <- makeTimeOfDayValid hr mi se+ let d = fromGregorian yy mm dd+ return $ Tick d tim++-- | A point in a time series+data TsPoint a =+ Tsp {+ _tick :: Tick,+ _val :: a+ } deriving (Eq, Show)++tickToFractional :: Fractional b => TsPoint a -> b+tickToFractional = fromRational . fromTick . _tick++-- | Map a Tick onto the rationals+fromTick :: Tick -> Rational+fromTick (Tick d t) = fromIntegral (toModifiedJulianDay d) + timeOfDayToDayFraction t+ +-- | Map a rational onto a Tick+toTick :: Rational -> Tick+toTick n = Tick d t+ where+ t = dayFractionToTimeOfDay dec+ d = ModifiedJulianDay wh+ (wh, dec) = wholeDecimal n+++hourTick, halfHourTick, quarterHourTick :: Rational+hourTick = 1/24+halfHourTick = 1/2 * hourTick+quarterHourTick = 1/4 * hourTick+++-- locTime :: IO LocalTime+-- locTime = do+-- tz <- getCurrentTimeZone+-- ct <- getCurrentTime+-- return $ utcToLocalTime tz ct+++-- tickRange :: Tick -> Tick -> Rational -> [Tick]+-- tickRange t1 t2 dt = toTick <$> [td1, td1 + dt .. td2] where+-- td1 = fromTick t1+-- td2 = fromTick t2++++ -- * Helpers -- | Create a `LabeledPoint` from a time series point (`TsPoint`). The `_tick` (time axis) field will be used for the x coordinate, whereas both fields of TsPoint may be used to create the label field.@@ -125,8 +179,6 @@ frameToFrameFxRow from to fxr = f <$> fxr where f = frameToFrameValue from to-- data FxRow a = FxRow {
test/LibSpec.hs view
@@ -7,14 +7,14 @@ import Graphics.Rendering.Plot.Light import Graphics.Rendering.Plot.Light.Internal.Geometry-import Data.TimeSeries+-- import Data.TimeSeries main :: IO () main = hspec spec spec :: Spec spec = do- describe "Data.Timeseries" $ + describe "TimeSeries" $ it "correctly converts between `Tick`s and `Fractional`s" $ do let t0 = 57957.475 fromTick (toTick t0) `shouldBe` t0