Bland.Ticks (Elixir Technical Drawing v0.6.0)

Copy Markdown View Source

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

format(v)

@spec format(number()) :: String.t()

Default tick formatter: trims trailing zeros from floats and renders integers without a decimal point.

format(v, arg2)

@spec format(number(), atom()) :: String.t()

Formats v according to a named tick format.

Formats:

  • :default — integers plain, very large or very small values in e notation (the behaviour of format/1)

  • :si — SI prefixes: 1.2k, , 4M

  • :scientific — always e notation: 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_minor(domain, base \\ 10)

@spec log_minor(
  {number(), number()},
  number()
) :: [float()]

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_nice(domain, base \\ 10)

@spec log_nice(
  {number(), number()},
  number()
) :: [float()]

Log-axis ticks at integer powers of base that fall within the domain.

nice(domain, target \\ 6)

@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.

nice_minor(arg1, majors)

@spec nice_minor(
  {number(), number()},
  [number()]
) :: [float()]

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}