{-# LANGUAGE CPP #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Graphics.Rendering.Chart.Axis.Time(
TimeSeq,
TimeLabelFn,
TimeLabelAlignment(..),
TimeValue (..),
timeValueAxis,
autoTimeValueAxis,
days, months, years,
) where
import Data.Default.Class
#if MIN_VERSION_time(1,5,0)
import Data.Time hiding (months)
#else
import Data.Time
import System.Locale (defaultTimeLocale)
#endif
import Data.Fixed
import Control.Lens
import Graphics.Rendering.Chart.Axis.Types
import Graphics.Rendering.Chart.Geometry (Range)
class TimeValue t where
utctimeFromTV :: t -> UTCTime
tvFromUTCTime :: UTCTime -> t
{-# MINIMAL utctimeFromTV, tvFromUTCTime #-}
doubleFromTimeValue :: t -> Double
doubleFromTimeValue = forall t. TimeValue t => t -> Double
doubleFromTimeValue forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. TimeValue t => t -> UTCTime
utctimeFromTV
timeValueFromDouble :: Double -> t
timeValueFromDouble = forall t. TimeValue t => UTCTime -> t
tvFromUTCTime forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. TimeValue t => Double -> t
timeValueFromDouble
instance TimeValue UTCTime where
utctimeFromTV :: UTCTime -> UTCTime
utctimeFromTV = forall a. a -> a
id
tvFromUTCTime :: UTCTime -> UTCTime
tvFromUTCTime = forall a. a -> a
id
doubleFromTimeValue :: UTCTime -> Double
doubleFromTimeValue = UTCTime -> Double
doubleFromUTCTime
timeValueFromDouble :: Double -> UTCTime
timeValueFromDouble = Double -> UTCTime
utcTimeFromDouble
instance TimeValue Day where
utctimeFromTV :: Day -> UTCTime
utctimeFromTV Day
d = Day -> DiffTime -> UTCTime
UTCTime Day
d DiffTime
0
tvFromUTCTime :: UTCTime -> Day
tvFromUTCTime = UTCTime -> Day
utctDay
doubleFromTimeValue :: Day -> Double
doubleFromTimeValue = Day -> Double
doubleFromDay
timeValueFromDouble :: Double -> Day
timeValueFromDouble = Double -> Day
dayFromDouble
instance TimeValue LocalTime where
utctimeFromTV :: LocalTime -> UTCTime
utctimeFromTV (LocalTime Day
d TimeOfDay
tod) = Day -> DiffTime -> UTCTime
UTCTime Day
d (TimeOfDay -> DiffTime
timeOfDayToTime TimeOfDay
tod)
tvFromUTCTime :: UTCTime -> LocalTime
tvFromUTCTime (UTCTime Day
d DiffTime
dt) = Day -> TimeOfDay -> LocalTime
LocalTime Day
d (DiffTime -> TimeOfDay
timeToTimeOfDay DiffTime
dt)
instance PlotValue LocalTime where
toValue :: LocalTime -> Double
toValue = forall t. TimeValue t => t -> Double
doubleFromTimeValue
fromValue :: Double -> LocalTime
fromValue = forall t. TimeValue t => Double -> t
timeValueFromDouble
autoAxis :: AxisFn LocalTime
autoAxis = forall t. TimeValue t => AxisFn t
autoTimeValueAxis
instance PlotValue UTCTime where
toValue :: UTCTime -> Double
toValue = forall t. TimeValue t => t -> Double
doubleFromTimeValue
fromValue :: Double -> UTCTime
fromValue = forall t. TimeValue t => Double -> t
timeValueFromDouble
autoAxis :: AxisFn UTCTime
autoAxis = forall t. TimeValue t => AxisFn t
autoTimeValueAxis
instance PlotValue Day where
toValue :: Day -> Double
toValue = forall t. TimeValue t => t -> Double
doubleFromTimeValue
fromValue :: Double -> Day
fromValue = forall t. TimeValue t => Double -> t
timeValueFromDouble
autoAxis :: AxisFn Day
autoAxis = forall t. TimeValue t => AxisFn t
autoTimeValueAxis
doubleFromUTCTime :: UTCTime -> Double
doubleFromUTCTime :: UTCTime -> Double
doubleFromUTCTime UTCTime
ut = forall a b. (Integral a, Num b) => a -> b
fromIntegral (Day -> Integer
toModifiedJulianDay (UTCTime -> Day
utctDay UTCTime
ut))
forall a. Num a => a -> a -> a
+ forall a. Fractional a => Rational -> a
fromRational (TimeOfDay -> Rational
timeOfDayToDayFraction (DiffTime -> TimeOfDay
timeToTimeOfDay (UTCTime -> DiffTime
utctDayTime UTCTime
ut)))
utcTimeFromDouble :: Double -> UTCTime
utcTimeFromDouble :: Double -> UTCTime
utcTimeFromDouble Double
v =
Day -> DiffTime -> UTCTime
UTCTime (Integer -> Day
ModifiedJulianDay Integer
i) (TimeOfDay -> DiffTime
timeOfDayToTime (Rational -> TimeOfDay
dayFractionToTimeOfDay (forall a. Real a => a -> Rational
toRational Double
d)))
where
(Integer
i,Double
d) = forall a b. (RealFrac a, Integral b) => a -> (b, a)
properFraction Double
v
doubleFromDay :: Day -> Double
doubleFromDay :: Day -> Double
doubleFromDay Day
d = forall a b. (Integral a, Num b) => a -> b
fromIntegral (Day -> Integer
toModifiedJulianDay Day
d)
dayFromDouble :: Double -> Day
dayFromDouble :: Double -> Day
dayFromDouble Double
v = Integer -> Day
ModifiedJulianDay (forall a b. (RealFrac a, Integral b) => a -> b
truncate Double
v)
type TimeSeq = UTCTime -> ([UTCTime],[UTCTime])
coverTS :: TimeSeq -> UTCTime -> UTCTime -> [UTCTime]
coverTS :: TimeSeq -> UTCTime -> UTCTime -> [UTCTime]
coverTS TimeSeq
tseq UTCTime
minT UTCTime
maxT = [UTCTime]
min' forall a. [a] -> [a] -> [a]
++ TimeSeq -> UTCTime -> UTCTime -> [UTCTime]
enumerateTS TimeSeq
tseq UTCTime
minT UTCTime
maxT forall a. [a] -> [a] -> [a]
++ [UTCTime]
max'
where
min' :: [UTCTime]
min' = if UTCTime -> TimeSeq -> Bool
elemTS UTCTime
minT TimeSeq
tseq then [] else forall a. Int -> [a] -> [a]
take Int
1 (forall a b. (a, b) -> a
fst (TimeSeq
tseq UTCTime
minT))
max' :: [UTCTime]
max' = if UTCTime -> TimeSeq -> Bool
elemTS UTCTime
maxT TimeSeq
tseq then [] else forall a. Int -> [a] -> [a]
take Int
1 (forall a b. (a, b) -> b
snd (TimeSeq
tseq UTCTime
maxT))
enumerateTS :: TimeSeq -> UTCTime -> UTCTime -> [UTCTime]
enumerateTS :: TimeSeq -> UTCTime -> UTCTime -> [UTCTime]
enumerateTS TimeSeq
tseq UTCTime
minT UTCTime
maxT =
forall a. [a] -> [a]
reverse (forall a. (a -> Bool) -> [a] -> [a]
takeWhile (forall a. Ord a => a -> a -> Bool
>=UTCTime
minT) [UTCTime]
ts1) forall a. [a] -> [a] -> [a]
++ forall a. (a -> Bool) -> [a] -> [a]
takeWhile (forall a. Ord a => a -> a -> Bool
<=UTCTime
maxT) [UTCTime]
ts2
where
([UTCTime]
ts1,[UTCTime]
ts2) = TimeSeq
tseq UTCTime
minT
elemTS :: UTCTime -> TimeSeq -> Bool
elemTS :: UTCTime -> TimeSeq -> Bool
elemTS UTCTime
t TimeSeq
tseq = case TimeSeq
tseq UTCTime
t of
([UTCTime]
_,UTCTime
t0:[UTCTime]
_) | UTCTime
t forall a. Eq a => a -> a -> Bool
== UTCTime
t0 -> Bool
True
([UTCTime], [UTCTime])
_ -> Bool
False
type TimeLabelFn = UTCTime -> String
data TimeLabelAlignment = UnderTicks
| BetweenTicks
deriving (Int -> TimeLabelAlignment -> ShowS
[TimeLabelAlignment] -> ShowS
TimeLabelAlignment -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TimeLabelAlignment] -> ShowS
$cshowList :: [TimeLabelAlignment] -> ShowS
show :: TimeLabelAlignment -> String
$cshow :: TimeLabelAlignment -> String
showsPrec :: Int -> TimeLabelAlignment -> ShowS
$cshowsPrec :: Int -> TimeLabelAlignment -> ShowS
Show)
timeValueAxis ::
TimeValue t
=> TimeSeq
-> TimeSeq
-> TimeLabelFn
-> TimeLabelAlignment
-> TimeSeq
-> TimeLabelFn
-> TimeLabelAlignment
-> AxisFn t
timeValueAxis :: forall t.
TimeValue t =>
TimeSeq
-> TimeSeq
-> TimeLabelFn
-> TimeLabelAlignment
-> TimeSeq
-> TimeLabelFn
-> TimeLabelAlignment
-> AxisFn t
timeValueAxis TimeSeq
tseq TimeSeq
lseq TimeLabelFn
labelf TimeLabelAlignment
lal TimeSeq
cseq TimeLabelFn
contextf TimeLabelAlignment
clal [t]
pts = AxisData {
_axis_visibility :: AxisVisibility
_axis_visibility = forall a. Default a => a
def,
_axis_viewport :: Range -> t -> Double
_axis_viewport = forall x. TimeValue x => (x, x) -> Range -> x -> Double
vmap' (forall t. TimeValue t => UTCTime -> t
tvFromUTCTime UTCTime
min', forall t. TimeValue t => UTCTime -> t
tvFromUTCTime UTCTime
max'),
_axis_tropweiv :: Range -> Double -> t
_axis_tropweiv = forall x. TimeValue x => (x, x) -> Range -> Double -> x
invmap' (forall t. TimeValue t => UTCTime -> t
tvFromUTCTime UTCTime
min', forall t. TimeValue t => UTCTime -> t
tvFromUTCTime UTCTime
max'),
_axis_ticks :: [(t, Double)]
_axis_ticks = [ (forall t. TimeValue t => UTCTime -> t
tvFromUTCTime UTCTime
t,Double
2) | UTCTime
t <- [UTCTime]
times] forall a. [a] -> [a] -> [a]
++ [ (forall t. TimeValue t => UTCTime -> t
tvFromUTCTime UTCTime
t,Double
5) | UTCTime
t <- [UTCTime]
ltimes, UTCTime -> Bool
visible UTCTime
t],
_axis_labels :: [[(t, String)]]
_axis_labels = [ [ (forall t. TimeValue t => UTCTime -> t
tvFromUTCTime UTCTime
t,String
l) | (UTCTime
t,String
l) <- forall {b}.
(UTCTime -> b) -> [UTCTime] -> TimeLabelAlignment -> [(UTCTime, b)]
labels TimeLabelFn
labelf [UTCTime]
ltimes TimeLabelAlignment
lal, UTCTime -> Bool
visible UTCTime
t]
, [ (forall t. TimeValue t => UTCTime -> t
tvFromUTCTime UTCTime
t,String
l) | (UTCTime
t,String
l) <- forall {b}.
(UTCTime -> b) -> [UTCTime] -> TimeLabelAlignment -> [(UTCTime, b)]
labels TimeLabelFn
contextf [UTCTime]
ctimes TimeLabelAlignment
clal, UTCTime -> Bool
visible UTCTime
t]
],
_axis_grid :: [t]
_axis_grid = [ forall t. TimeValue t => UTCTime -> t
tvFromUTCTime UTCTime
t | UTCTime
t <- [UTCTime]
ltimes, UTCTime -> Bool
visible UTCTime
t]
}
where
(UTCTime
minT,UTCTime
maxT) = case [t]
pts of
[] -> (UTCTime
refTimeValue,UTCTime
refTimeValue)
[t]
ps -> (forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
minimum (forall a b. (a -> b) -> [a] -> [b]
map forall t. TimeValue t => t -> UTCTime
utctimeFromTV [t]
ps), forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
maximum (forall a b. (a -> b) -> [a] -> [b]
map forall t. TimeValue t => t -> UTCTime
utctimeFromTV [t]
ps))
refTimeValue :: UTCTime
refTimeValue = forall t. TimeValue t => Double -> t
timeValueFromDouble Double
0
times, ltimes, ctimes :: [UTCTime]
times :: [UTCTime]
times = TimeSeq -> UTCTime -> UTCTime -> [UTCTime]
coverTS TimeSeq
tseq UTCTime
minT UTCTime
maxT
ltimes :: [UTCTime]
ltimes = TimeSeq -> UTCTime -> UTCTime -> [UTCTime]
coverTS TimeSeq
lseq UTCTime
minT UTCTime
maxT
ctimes :: [UTCTime]
ctimes = TimeSeq -> UTCTime -> UTCTime -> [UTCTime]
coverTS TimeSeq
cseq UTCTime
minT UTCTime
maxT
min' :: UTCTime
min' = forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
minimum [UTCTime]
times
max' :: UTCTime
max' = forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
maximum [UTCTime]
times
visible :: UTCTime -> Bool
visible UTCTime
t = UTCTime
min' forall a. Ord a => a -> a -> Bool
<= UTCTime
t Bool -> Bool -> Bool
&& UTCTime
t forall a. Ord a => a -> a -> Bool
<= UTCTime
max'
labels :: (UTCTime -> b) -> [UTCTime] -> TimeLabelAlignment -> [(UTCTime, b)]
labels UTCTime -> b
f [UTCTime]
ts TimeLabelAlignment
lal' =
[ (forall {t} {p}.
(TimeValue t, TimeValue p) =>
TimeLabelAlignment -> t -> p -> t
align TimeLabelAlignment
lal' UTCTime
m1' UTCTime
m2', UTCTime -> b
f UTCTime
m1)
| (UTCTime
m1,UTCTime
m2) <- forall a b. [a] -> [b] -> [(a, b)]
zip [UTCTime]
ts (forall a. [a] -> [a]
tail [UTCTime]
ts)
, let m1' :: UTCTime
m1' = if UTCTime
m1forall a. Ord a => a -> a -> Bool
<UTCTime
min' then UTCTime
min' else UTCTime
m1
, let m2' :: UTCTime
m2' = if UTCTime
m2forall a. Ord a => a -> a -> Bool
>UTCTime
max' then UTCTime
max' else UTCTime
m2 ]
align :: TimeLabelAlignment -> t -> p -> t
align TimeLabelAlignment
BetweenTicks t
m1 p
m2 = forall {t} {p} {p}.
(TimeValue t, TimeValue p, TimeValue p) =>
p -> p -> t
avg t
m1 p
m2
align TimeLabelAlignment
UnderTicks t
m1 p
_ = t
m1
avg :: p -> p -> t
avg p
m1 p
m2 = forall t. TimeValue t => Double -> t
timeValueFromDouble forall a b. (a -> b) -> a -> b
$ Double
m1' forall a. Num a => a -> a -> a
+ (Double
m2' forall a. Num a => a -> a -> a
- Double
m1')forall a. Fractional a => a -> a -> a
/Double
2
where
m1' :: Double
m1' = forall t. TimeValue t => t -> Double
doubleFromTimeValue p
m1
m2' :: Double
m2' = forall t. TimeValue t => t -> Double
doubleFromTimeValue p
m2
vmap' :: TimeValue x => (x,x) -> Range -> x -> Double
vmap' :: forall x. TimeValue x => (x, x) -> Range -> x -> Double
vmap' (x
v1,x
v2) (Double
v3,Double
v4) x
v = Double
v3 forall a. Num a => a -> a -> a
+ (forall t. TimeValue t => t -> Double
doubleFromTimeValue x
v forall a. Num a => a -> a -> a
- forall t. TimeValue t => t -> Double
doubleFromTimeValue x
v1) forall a. Num a => a -> a -> a
* (Double
v4forall a. Num a => a -> a -> a
-Double
v3)
forall a. Fractional a => a -> a -> a
/ (forall t. TimeValue t => t -> Double
doubleFromTimeValue x
v2 forall a. Num a => a -> a -> a
- forall t. TimeValue t => t -> Double
doubleFromTimeValue x
v1)
invmap' :: TimeValue x => (x,x) -> Range -> Double -> x
invmap' :: forall x. TimeValue x => (x, x) -> Range -> Double -> x
invmap' (x
v3,x
v4) (Double
d1,Double
d2) Double
d = forall t. TimeValue t => Double -> t
timeValueFromDouble (forall t. TimeValue t => t -> Double
doubleFromTimeValue x
v3 forall a. Num a => a -> a -> a
+ ( (Double
dforall a. Num a => a -> a -> a
-Double
d1) forall a. Num a => a -> a -> a
* Double
doubleRange
forall a. Fractional a => a -> a -> a
/ (Double
d2forall a. Num a => a -> a -> a
-Double
d1) ))
where doubleRange :: Double
doubleRange = forall t. TimeValue t => t -> Double
doubleFromTimeValue x
v4 forall a. Num a => a -> a -> a
- forall t. TimeValue t => t -> Double
doubleFromTimeValue x
v3
truncateTo :: Real a => a -> a -> a
truncateTo :: forall a. Real a => a -> a -> a
truncateTo a
t a
step = a
t forall a. Num a => a -> a -> a
- a
t forall a. Real a => a -> a -> a
`mod'` a
step
secondSeq :: NominalDiffTime -> TimeSeq
secondSeq :: NominalDiffTime -> TimeSeq
secondSeq NominalDiffTime
step t :: UTCTime
t@(UTCTime Day
day DiffTime
dt) = (forall a. (a -> a) -> a -> [a]
iterate UTCTime -> UTCTime
rev UTCTime
t1, forall a. [a] -> [a]
tail (forall a. (a -> a) -> a -> [a]
iterate UTCTime -> UTCTime
fwd UTCTime
t1))
where t0 :: UTCTime
t0 = Day -> DiffTime -> UTCTime
UTCTime Day
day (forall a. Real a => a -> a -> a
truncateTo DiffTime
dt DiffTime
step')
t1 :: UTCTime
t1 = if UTCTime
t0 forall a. Ord a => a -> a -> Bool
< UTCTime
t then UTCTime
t0 else UTCTime -> UTCTime
rev UTCTime
t0
rev :: UTCTime -> UTCTime
rev = NominalDiffTime -> UTCTime -> UTCTime
addUTCTime (forall a. Num a => a -> a
negate NominalDiffTime
step)
fwd :: UTCTime -> UTCTime
fwd = NominalDiffTime -> UTCTime -> UTCTime
addUTCTime NominalDiffTime
step
step' :: DiffTime
step' = forall a b. (Real a, Fractional b) => a -> b
realToFrac NominalDiffTime
step
millis1, millis10, millis100, seconds, fiveSeconds :: TimeSeq
millis1 :: TimeSeq
millis1 = NominalDiffTime -> TimeSeq
secondSeq (NominalDiffTime
1 forall a. Fractional a => a -> a -> a
/ NominalDiffTime
1000)
millis10 :: TimeSeq
millis10 = NominalDiffTime -> TimeSeq
secondSeq (NominalDiffTime
1 forall a. Fractional a => a -> a -> a
/ NominalDiffTime
100)
millis100 :: TimeSeq
millis100 = NominalDiffTime -> TimeSeq
secondSeq (NominalDiffTime
1 forall a. Fractional a => a -> a -> a
/ NominalDiffTime
10)
seconds :: TimeSeq
seconds = NominalDiffTime -> TimeSeq
secondSeq NominalDiffTime
1
fiveSeconds :: TimeSeq
fiveSeconds = NominalDiffTime -> TimeSeq
secondSeq NominalDiffTime
5
minutes, fiveMinutes :: TimeSeq
minutes :: TimeSeq
minutes = NominalDiffTime -> TimeSeq
secondSeq NominalDiffTime
60
fiveMinutes :: TimeSeq
fiveMinutes = NominalDiffTime -> TimeSeq
secondSeq (NominalDiffTime
5 forall a. Num a => a -> a -> a
* NominalDiffTime
60)
hours :: TimeSeq
hours :: TimeSeq
hours = NominalDiffTime -> TimeSeq
secondSeq (NominalDiffTime
60 forall a. Num a => a -> a -> a
* NominalDiffTime
60)
days :: TimeSeq
days :: TimeSeq
days UTCTime
t = (forall a b. (a -> b) -> [a] -> [b]
map Day -> UTCTime
toTime forall a b. (a -> b) -> a -> b
$ forall a. (a -> a) -> a -> [a]
iterate Day -> Day
rev Day
t1, forall a b. (a -> b) -> [a] -> [b]
map Day -> UTCTime
toTime forall a b. (a -> b) -> a -> b
$ forall a. [a] -> [a]
tail (forall a. (a -> a) -> a -> [a]
iterate Day -> Day
fwd Day
t1))
where t0 :: Day
t0 = UTCTime -> Day
utctDay UTCTime
t
t1 :: Day
t1 = if Day -> UTCTime
toTime Day
t0 forall a. Ord a => a -> a -> Bool
< UTCTime
t then Day
t0 else Day -> Day
rev Day
t0
rev :: Day -> Day
rev = forall a. Enum a => a -> a
pred
fwd :: Day -> Day
fwd = forall a. Enum a => a -> a
succ
toTime :: Day -> UTCTime
toTime Day
d = Day -> DiffTime -> UTCTime
UTCTime Day
d DiffTime
0
months :: TimeSeq
months :: TimeSeq
months UTCTime
t = (forall a b. (a -> b) -> [a] -> [b]
map Day -> UTCTime
toTime forall a b. (a -> b) -> a -> b
$ forall a. (a -> a) -> a -> [a]
iterate Day -> Day
rev Day
t1, forall a b. (a -> b) -> [a] -> [b]
map Day -> UTCTime
toTime forall a b. (a -> b) -> a -> b
$ forall a. [a] -> [a]
tail (forall a. (a -> a) -> a -> [a]
iterate Day -> Day
fwd Day
t1))
where t0 :: Day
t0 = let (Integer
y,Int
m,Int
_) = Day -> (Integer, Int, Int)
toGregorian forall a b. (a -> b) -> a -> b
$ UTCTime -> Day
utctDay UTCTime
t in Integer -> Int -> Int -> Day
fromGregorian Integer
y Int
m Int
1
t1 :: Day
t1 = if Day -> UTCTime
toTime Day
t0 forall a. Ord a => a -> a -> Bool
< UTCTime
t then Day
t0 else Day -> Day
rev Day
t0
rev :: Day -> Day
rev = Integer -> Day -> Day
addGregorianMonthsClip (-Integer
1)
fwd :: Day -> Day
fwd = Integer -> Day -> Day
addGregorianMonthsClip Integer
1
toTime :: Day -> UTCTime
toTime Day
d = Day -> DiffTime -> UTCTime
UTCTime Day
d DiffTime
0
years :: TimeSeq
years :: TimeSeq
years UTCTime
t = (forall a b. (a -> b) -> [a] -> [b]
map Integer -> UTCTime
toTime forall a b. (a -> b) -> a -> b
$ forall a. (a -> a) -> a -> [a]
iterate Integer -> Integer
rev Integer
t1, forall a b. (a -> b) -> [a] -> [b]
map Integer -> UTCTime
toTime forall a b. (a -> b) -> a -> b
$ forall a. [a] -> [a]
tail (forall a. (a -> a) -> a -> [a]
iterate Integer -> Integer
fwd Integer
t1))
where t0 :: Integer
t0 = Day -> (Integer, Int, Int)
toGregorian (UTCTime -> Day
utctDay UTCTime
t) forall s a. s -> Getting a s a -> a
^. forall s t a b. Field1 s t a b => Lens s t a b
_1
t1 :: Integer
t1 = if Integer -> UTCTime
toTime Integer
t0 forall a. Ord a => a -> a -> Bool
< UTCTime
t then Integer
t0 else Integer -> Integer
rev Integer
t0
rev :: Integer -> Integer
rev = forall a. Enum a => a -> a
pred
fwd :: Integer -> Integer
fwd = forall a. Enum a => a -> a
succ
toTime :: Integer -> UTCTime
toTime Integer
y = Day -> DiffTime -> UTCTime
UTCTime (Integer -> Int -> Int -> Day
fromGregorian Integer
y Int
1 Int
1) DiffTime
0
noTime :: TimeSeq
noTime :: TimeSeq
noTime UTCTime
_ = ([],[])
autoTimeValueAxis :: TimeValue t => AxisFn t
autoTimeValueAxis :: forall t. TimeValue t => AxisFn t
autoTimeValueAxis [t]
pts
| forall (t :: * -> *) a. Foldable t => t a -> Bool
null [t]
pts = forall t.
TimeValue t =>
TimeSeq
-> TimeSeq
-> TimeLabelFn
-> TimeLabelAlignment
-> TimeSeq
-> TimeLabelFn
-> TimeLabelAlignment
-> AxisFn t
timeValueAxis TimeSeq
days TimeSeq
days (String -> TimeLabelFn
ft String
"%d-%b-%y") TimeLabelAlignment
UnderTicks
TimeSeq
noTime (String -> TimeLabelFn
ft String
"") TimeLabelAlignment
UnderTicks []
| NominalDiffTime
100forall a. Num a => a -> a -> a
*NominalDiffTime
dsecforall a. Ord a => a -> a -> Bool
<NominalDiffTime
1 = forall t.
TimeValue t =>
TimeSeq
-> TimeSeq
-> TimeLabelFn
-> TimeLabelAlignment
-> TimeSeq
-> TimeLabelFn
-> TimeLabelAlignment
-> AxisFn t
timeValueAxis TimeSeq
millis1 TimeSeq
millis1 (String -> TimeLabelFn
ft String
"%S%Q") TimeLabelAlignment
UnderTicks
TimeSeq
noTime (String -> TimeLabelFn
ft String
"%S%Q") TimeLabelAlignment
UnderTicks [t]
pts
| NominalDiffTime
10forall a. Num a => a -> a -> a
*NominalDiffTime
dsecforall a. Ord a => a -> a -> Bool
<NominalDiffTime
1 = forall t.
TimeValue t =>
TimeSeq
-> TimeSeq
-> TimeLabelFn
-> TimeLabelAlignment
-> TimeSeq
-> TimeLabelFn
-> TimeLabelAlignment
-> AxisFn t
timeValueAxis TimeSeq
millis10 TimeSeq
millis10 (String -> TimeLabelFn
ft String
"%S%Q") TimeLabelAlignment
UnderTicks
TimeSeq
noTime (String -> TimeLabelFn
ft String
"%S%Q") TimeLabelAlignment
UnderTicks [t]
pts
| NominalDiffTime
dsecforall a. Ord a => a -> a -> Bool
<NominalDiffTime
1 = forall t.
TimeValue t =>
TimeSeq
-> TimeSeq
-> TimeLabelFn
-> TimeLabelAlignment
-> TimeSeq
-> TimeLabelFn
-> TimeLabelAlignment
-> AxisFn t
timeValueAxis TimeSeq
millis10 TimeSeq
millis100 (String -> TimeLabelFn
ft String
"%S%Q") TimeLabelAlignment
UnderTicks
TimeSeq
seconds (String -> TimeLabelFn
ft String
"%M:%S") TimeLabelAlignment
BetweenTicks [t]
pts
| NominalDiffTime
dsecforall a. Ord a => a -> a -> Bool
<NominalDiffTime
5 = forall t.
TimeValue t =>
TimeSeq
-> TimeSeq
-> TimeLabelFn
-> TimeLabelAlignment
-> TimeSeq
-> TimeLabelFn
-> TimeLabelAlignment
-> AxisFn t
timeValueAxis TimeSeq
millis100 TimeSeq
seconds (String -> TimeLabelFn
ft String
"%M:%S%Q") TimeLabelAlignment
UnderTicks
TimeSeq
seconds (String -> TimeLabelFn
ft String
"%M:%S") TimeLabelAlignment
BetweenTicks [t]
pts
| NominalDiffTime
dsecforall a. Ord a => a -> a -> Bool
<NominalDiffTime
32 = forall t.
TimeValue t =>
TimeSeq
-> TimeSeq
-> TimeLabelFn
-> TimeLabelAlignment
-> TimeSeq
-> TimeLabelFn
-> TimeLabelAlignment
-> AxisFn t
timeValueAxis TimeSeq
seconds TimeSeq
seconds (String -> TimeLabelFn
ft String
"%Ss") TimeLabelAlignment
UnderTicks
TimeSeq
minutes (String -> TimeLabelFn
ft String
"%d-%b-%y %H:%M") TimeLabelAlignment
BetweenTicks [t]
pts
| NominalDiffTime
dsecforall a. Ord a => a -> a -> Bool
<NominalDiffTime
120 = forall t.
TimeValue t =>
TimeSeq
-> TimeSeq
-> TimeLabelFn
-> TimeLabelAlignment
-> TimeSeq
-> TimeLabelFn
-> TimeLabelAlignment
-> AxisFn t
timeValueAxis TimeSeq
seconds TimeSeq
fiveSeconds (String -> TimeLabelFn
ft String
"%Ss") TimeLabelAlignment
UnderTicks
TimeSeq
minutes (String -> TimeLabelFn
ft String
"%d-%b-%y %H:%M") TimeLabelAlignment
BetweenTicks [t]
pts
| NominalDiffTime
dsecforall a. Ord a => a -> a -> Bool
<NominalDiffTime
7forall a. Num a => a -> a -> a
*NominalDiffTime
60 = forall t.
TimeValue t =>
TimeSeq
-> TimeSeq
-> TimeLabelFn
-> TimeLabelAlignment
-> TimeSeq
-> TimeLabelFn
-> TimeLabelAlignment
-> AxisFn t
timeValueAxis TimeSeq
fiveSeconds TimeSeq
minutes (String -> TimeLabelFn
ft String
"%Mm") TimeLabelAlignment
UnderTicks
TimeSeq
hours (String -> TimeLabelFn
ft String
"%d-%b-%y %H:00") TimeLabelAlignment
BetweenTicks [t]
pts
| NominalDiffTime
dsecforall a. Ord a => a -> a -> Bool
<NominalDiffTime
32forall a. Num a => a -> a -> a
*NominalDiffTime
60 = forall t.
TimeValue t =>
TimeSeq
-> TimeSeq
-> TimeLabelFn
-> TimeLabelAlignment
-> TimeSeq
-> TimeLabelFn
-> TimeLabelAlignment
-> AxisFn t
timeValueAxis TimeSeq
minutes TimeSeq
minutes (String -> TimeLabelFn
ft String
"%Mm") TimeLabelAlignment
UnderTicks
TimeSeq
hours (String -> TimeLabelFn
ft String
"%d-%b-%y %H:00") TimeLabelAlignment
BetweenTicks [t]
pts
| NominalDiffTime
dsecforall a. Ord a => a -> a -> Bool
<NominalDiffTime
90forall a. Num a => a -> a -> a
*NominalDiffTime
60 = forall t.
TimeValue t =>
TimeSeq
-> TimeSeq
-> TimeLabelFn
-> TimeLabelAlignment
-> TimeSeq
-> TimeLabelFn
-> TimeLabelAlignment
-> AxisFn t
timeValueAxis TimeSeq
minutes TimeSeq
fiveMinutes (String -> TimeLabelFn
ft String
"%Mm") TimeLabelAlignment
UnderTicks
TimeSeq
hours (String -> TimeLabelFn
ft String
"%d-%b-%y %H:00") TimeLabelAlignment
BetweenTicks [t]
pts
| NominalDiffTime
dsecforall a. Ord a => a -> a -> Bool
<NominalDiffTime
4forall a. Num a => a -> a -> a
*NominalDiffTime
3600 = forall t.
TimeValue t =>
TimeSeq
-> TimeSeq
-> TimeLabelFn
-> TimeLabelAlignment
-> TimeSeq
-> TimeLabelFn
-> TimeLabelAlignment
-> AxisFn t
timeValueAxis TimeSeq
fiveMinutes TimeSeq
hours (String -> TimeLabelFn
ft String
"%H:%M") TimeLabelAlignment
UnderTicks
TimeSeq
days (String -> TimeLabelFn
ft String
"%d-%b-%y") TimeLabelAlignment
BetweenTicks [t]
pts
| NominalDiffTime
dsecforall a. Ord a => a -> a -> Bool
<NominalDiffTime
32forall a. Num a => a -> a -> a
*NominalDiffTime
3600 = forall t.
TimeValue t =>
TimeSeq
-> TimeSeq
-> TimeLabelFn
-> TimeLabelAlignment
-> TimeSeq
-> TimeLabelFn
-> TimeLabelAlignment
-> AxisFn t
timeValueAxis TimeSeq
hours TimeSeq
hours (String -> TimeLabelFn
ft String
"%H:%M") TimeLabelAlignment
UnderTicks
TimeSeq
days (String -> TimeLabelFn
ft String
"%d-%b-%y") TimeLabelAlignment
BetweenTicks [t]
pts
| NominalDiffTime
ddayforall a. Ord a => a -> a -> Bool
<NominalDiffTime
4 = forall t.
TimeValue t =>
TimeSeq
-> TimeSeq
-> TimeLabelFn
-> TimeLabelAlignment
-> TimeSeq
-> TimeLabelFn
-> TimeLabelAlignment
-> AxisFn t
timeValueAxis TimeSeq
hours TimeSeq
days (String -> TimeLabelFn
ft String
"%d-%b-%y") TimeLabelAlignment
BetweenTicks
TimeSeq
noTime (String -> TimeLabelFn
ft String
"") TimeLabelAlignment
BetweenTicks [t]
pts
| NominalDiffTime
ddayforall a. Ord a => a -> a -> Bool
<NominalDiffTime
12 = forall t.
TimeValue t =>
TimeSeq
-> TimeSeq
-> TimeLabelFn
-> TimeLabelAlignment
-> TimeSeq
-> TimeLabelFn
-> TimeLabelAlignment
-> AxisFn t
timeValueAxis TimeSeq
days TimeSeq
days (String -> TimeLabelFn
ft String
"%d-%b") TimeLabelAlignment
BetweenTicks
TimeSeq
years (String -> TimeLabelFn
ft String
"%Y") TimeLabelAlignment
BetweenTicks [t]
pts
| NominalDiffTime
ddayforall a. Ord a => a -> a -> Bool
<NominalDiffTime
45 = forall t.
TimeValue t =>
TimeSeq
-> TimeSeq
-> TimeLabelFn
-> TimeLabelAlignment
-> TimeSeq
-> TimeLabelFn
-> TimeLabelAlignment
-> AxisFn t
timeValueAxis TimeSeq
days TimeSeq
days (String -> TimeLabelFn
ft String
"%d") TimeLabelAlignment
BetweenTicks
TimeSeq
months (String -> TimeLabelFn
ft String
"%b-%y") TimeLabelAlignment
BetweenTicks [t]
pts
| NominalDiffTime
ddayforall a. Ord a => a -> a -> Bool
<NominalDiffTime
95 = forall t.
TimeValue t =>
TimeSeq
-> TimeSeq
-> TimeLabelFn
-> TimeLabelAlignment
-> TimeSeq
-> TimeLabelFn
-> TimeLabelAlignment
-> AxisFn t
timeValueAxis TimeSeq
days TimeSeq
months (String -> TimeLabelFn
ft String
"%b-%y") TimeLabelAlignment
BetweenTicks
TimeSeq
noTime (String -> TimeLabelFn
ft String
"") TimeLabelAlignment
BetweenTicks [t]
pts
| NominalDiffTime
ddayforall a. Ord a => a -> a -> Bool
<NominalDiffTime
450 = forall t.
TimeValue t =>
TimeSeq
-> TimeSeq
-> TimeLabelFn
-> TimeLabelAlignment
-> TimeSeq
-> TimeLabelFn
-> TimeLabelAlignment
-> AxisFn t
timeValueAxis TimeSeq
months TimeSeq
months (String -> TimeLabelFn
ft String
"%b-%y") TimeLabelAlignment
BetweenTicks
TimeSeq
noTime (String -> TimeLabelFn
ft String
"") TimeLabelAlignment
BetweenTicks [t]
pts
| NominalDiffTime
ddayforall a. Ord a => a -> a -> Bool
<NominalDiffTime
735 = forall t.
TimeValue t =>
TimeSeq
-> TimeSeq
-> TimeLabelFn
-> TimeLabelAlignment
-> TimeSeq
-> TimeLabelFn
-> TimeLabelAlignment
-> AxisFn t
timeValueAxis TimeSeq
months TimeSeq
months (String -> TimeLabelFn
ft String
"%b") TimeLabelAlignment
BetweenTicks
TimeSeq
years (String -> TimeLabelFn
ft String
"%Y") TimeLabelAlignment
BetweenTicks [t]
pts
| NominalDiffTime
ddayforall a. Ord a => a -> a -> Bool
<NominalDiffTime
1800 = forall t.
TimeValue t =>
TimeSeq
-> TimeSeq
-> TimeLabelFn
-> TimeLabelAlignment
-> TimeSeq
-> TimeLabelFn
-> TimeLabelAlignment
-> AxisFn t
timeValueAxis TimeSeq
months TimeSeq
years (String -> TimeLabelFn
ft String
"%Y") TimeLabelAlignment
BetweenTicks
TimeSeq
noTime (String -> TimeLabelFn
ft String
"") TimeLabelAlignment
BetweenTicks [t]
pts
| Bool
otherwise = forall t.
TimeValue t =>
TimeSeq
-> TimeSeq
-> TimeLabelFn
-> TimeLabelAlignment
-> TimeSeq
-> TimeLabelFn
-> TimeLabelAlignment
-> AxisFn t
timeValueAxis TimeSeq
years TimeSeq
years (String -> TimeLabelFn
ft String
"%Y") TimeLabelAlignment
BetweenTicks
TimeSeq
noTime (String -> TimeLabelFn
ft String
"") TimeLabelAlignment
BetweenTicks [t]
pts
where
upts :: [UTCTime]
upts = forall a b. (a -> b) -> [a] -> [b]
map forall t. TimeValue t => t -> UTCTime
utctimeFromTV [t]
pts
dsec :: NominalDiffTime
dsec = UTCTime -> UTCTime -> NominalDiffTime
diffUTCTime UTCTime
t1 UTCTime
t0
dday :: NominalDiffTime
dday = NominalDiffTime
dsec forall a. Fractional a => a -> a -> a
/ NominalDiffTime
86400
t1 :: UTCTime
t1 = forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
maximum [UTCTime]
upts
t0 :: UTCTime
t0 = forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
minimum [UTCTime]
upts
ft :: String -> TimeLabelFn
ft = forall t. FormatTime t => TimeLocale -> String -> t -> String
formatTime TimeLocale
defaultTimeLocale