# `Fude.Rules`
[🔗](https://github.com/hattoriai/fude/blob/v0.1.0/lib/fude/rules.ex#L1)

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.

# `bin`

```elixir
@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`

```elixir
@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`

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

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

# `increment`

```elixir
@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`

```elixir
@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`

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

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

# `ticks`

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

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

# `time_ticks`

```elixir
@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").

---

*Consult [api-reference.md](api-reference.md) for complete listing*
