Fude.Rules (Fude v0.1.0)

Copy Markdown View Source

The rules of a chart's scales that the server and the browser both apply: nice domains, the ticks of a number axis and of a time axis, the bins of a histogram and the units of a time.

They are written twice, here and in assets/src/rules.ts, word for word: a change here is a change there. One fixture, test/fixtures/rules.json, holds the cases that both test suites run.

Times are milliseconds since 1970 in UTC.

Summary

Functions

The bin of a value among the bins {start, step, n}: from 0 to n - 1.

The bins of the numbers from min to max, about count of them, at round numbers: {start, step, n}, the first bin [start, start + step) and the last one closed, so that max is in it.

The start of a time's unit: :minute, :hour, :day, :week (from Monday), :month, :quarter or :year.

The step between ticks of about count ticks from start to stop: a positive number, or, for a step under 1, minus its inverse (-10 is a step of 0.1), which keeps it exact.

The domain from start to stop widened to round numbers, so that its ends are ticks of about count ticks. A domain of one value widens around it.

The time step units after a time at the start of its unit.

About count ticks between start and stop, at round numbers, in order.

About count ticks of a time axis from start to stop, at the starts of round units: {unit, step, ticks}, where the unit says how to write them (:month: "Mar").

Functions

bin(arg, value)

@spec bin({number(), number(), pos_integer()}, number()) :: non_neg_integer()

The bin of a value among the bins {start, step, n}: from 0 to n - 1.

bins(min, max, count)

@spec bins(number(), number(), pos_integer()) :: {number(), number(), pos_integer()}

The bins of the numbers from min to max, about count of them, at round numbers: {start, step, n}, the first bin [start, start + step) and the last one closed, so that max is in it.

floor(time, atom)

@spec floor(integer(), atom()) :: integer()

The start of a time's unit: :minute, :hour, :day, :week (from Monday), :month, :quarter or :year.

increment(start, stop, count)

@spec increment(number(), number(), number()) :: number()

The step between ticks of about count ticks from start to stop: a positive number, or, for a step under 1, minus its inverse (-10 is a step of 0.1), which keeps it exact.

nice(start, stop, count \\ 10)

@spec nice(number(), number(), number()) :: {number(), number()}

The domain from start to stop widened to round numbers, so that its ends are ticks of about count ticks. A domain of one value widens around it.

offset(time, atom, step)

@spec offset(integer(), atom(), integer()) :: integer()

The time step units after a time at the start of its unit.

ticks(start, stop, count)

@spec ticks(number(), number(), number()) :: [float()]

About count ticks between start and stop, at round numbers, in order.

time_ticks(start, stop, count)

@spec time_ticks(integer(), integer(), number()) ::
  {atom(), pos_integer(), [integer()]}

About count ticks of a time axis from start to stop, at the starts of round units: {unit, step, ticks}, where the unit says how to write them (:month: "Mar").