Nice-rounded tick generation.
Picks evenly-spaced tick values within a domain using the classic 1-2-2.5-5-10 decade decomposition so that axes break on numbers a human would pick by hand — the kind of axis you'd draw on engineering graph paper.
iex> Bland.Ticks.nice({0.0, 9.7}, 5) |> Enum.take(3)
[0.0, 2.0, 4.0]
Summary
Functions
Default tick formatter: trims trailing zeros from floats and renders integers without a decimal point.
Formats v according to a named tick format.
Log-axis minor ticks at 2x and 5x each decade — the 2-5-10 convention of engineering graph paper. Decade powers themselves are majors and are omitted.
Log-axis ticks at integer powers of base that fall within the domain.
Produces a list of tick values for a linear axis. target is the
approximate number of ticks desired; the returned list will be close to
that count but pinned to nice, round step sizes.
Linear minor ticks between majors, using a 1-2-5 subdivision of the
major step. Values coinciding with a major are omitted, so the result
can be drawn without doubling up on the major grid.
Functions
Default tick formatter: trims trailing zeros from floats and renders integers without a decimal point.
Formats v according to a named tick format.
Formats:
:default— integers plain, very large or very small values inenotation (the behaviour offormat/1):si— SI prefixes:1.2k,3µ,4M:scientific— alwaysenotation:1.20e+03:degrees— appends a degree sign:45°iex> Bland.Ticks.format(1200.0, :si) "1.2k"
iex> Bland.Ticks.format(45.0, :degrees) "45°"
Log-axis minor ticks at 2x and 5x each decade — the 2-5-10 convention of engineering graph paper. Decade powers themselves are majors and are omitted.
iex> Bland.Ticks.log_minor({1.0, 100.0}, 10)
[2.0, 5.0, 20.0, 50.0]
Log-axis ticks at integer powers of base that fall within the domain.
@spec nice( {number(), number()}, pos_integer() ) :: [float()]
Produces a list of tick values for a linear axis. target is the
approximate number of ticks desired; the returned list will be close to
that count but pinned to nice, round step sizes.
Linear minor ticks between majors, using a 1-2-5 subdivision of the
major step. Values coinciding with a major are omitted, so the result
can be drawn without doubling up on the major grid.
iex> majors = Bland.Ticks.nice({0.0, 8.0}, 5)
iex> minors = Bland.Ticks.nice_minor({0.0, 8.0}, majors)
iex> {1.0 in minors, 2.0 in minors}
{true, false}