Produce "nice" intervals for e.g. axis labels.
What are "nice" numbers/integers/datetimes?
When I say "nice", I just mean that I try to calculate intervals which begin with 10, 5, 3, 2, 1 (adjusted to magnitude, of course!). For dates, I try to hit whole days, weeks, months or hours, minutes, and seconds.
ints : Amount -> Range -> List Basics.Int
Produce a list of "nice" integers.
floats : Amount -> Range -> List Basics.Float
Produce a list of "nice" floats.
around : Basics.Int -> Amount
Will get you around the amount of numbers you pass it, although it will prioritize getting "nice" numbers.
exactly : Basics.Int -> Amount
Will get you closer to the amount of numbers you pass it, although not actually exactly, since you still want decently "nice" numbers.
P.S. If you have a better name for this function, please contact me.
{ min : Basics.Float
, max : Basics.Float
}
The upper and lower bound of your numbers/timestamps.
custom : Basics.Float -> Basics.Float -> Range -> List Basics.Float
Makes evenly spaced floats.
Arguments: 1. A number which must be in your resulting numbers (commonly 0). 2. The interval between your numbers. 3. The range which your numbers must be between.
Intervals.custom 45 10 (Range 25 100)
-- ^ Makes [ 25, 35, 45, 55, 65, 75, 85, 95 ]
Intervals.custom 30 20 (Range 25 100)
-- ^ Makes [ 30, 50, 70, 90 ]
times : Time.Zone -> Basics.Int -> Range -> List Time
Produce a list of "nice" dates.
Arguments:
{ timestamp : Time.Posix
, zone : Time.Zone
, isFirst : Basics.Bool
, unit : Unit
, multiple : Basics.Int
, change : Maybe Unit
}
A timestamp with extra info helpful for formatting. Explanation:
Just
when the tick is changing to a larger unit
than used in the interval. E.g. if the interval is 2 hours, then
this will be a Just Day
when the day changes. Useful if you
want a different formatting for those ticks!You can format your tick label differently based on it's unit.