# `Macaw.Draw.Scale.Power`
[🔗](https://github.com/dcoai/macaw_draw/blob/v0.1.0/lib/macaw/draw/scale/power.ex#L1)

A continuous power scale: d3's signed power, `sqrt` its exponent 0.5 (spec/06 §6).

The transform is `T(x) = sign(x) · |x|^e`, applied to the domain's bounds and the value
alike, so a domain that includes negatives maps symmetrically and `invert/2` answers
negative domain values. `ticks/2` and `nice/1` are `Macaw.Draw.Scale.Linear`'s over the
domain: linear in the domain, not in the transformed space. When it clamps, the scale
clamps its output to the range's bounds.

    scale = Macaw.Draw.Scale.Power.sqrt() |> Macaw.Draw.Scale.Power.domain!([0, 100])
    Macaw.Draw.Scale.Power.apply(Macaw.Draw.Scale.Power.range!(scale, [0, 10]), 25)
    #=> 5.0

# `error`

```elixir
@type error() :: {:error, [Macaw.Base.Fault.t()]}
```

A refusal: faults with their paths.

# `t`

```elixir
@type t() :: %Macaw.Draw.Scale.Power{
  clamp?: boolean(),
  domain: [number()],
  exponent: number(),
  range: [number()]
}
```

# `apply`

```elixir
@spec apply(t(), term()) :: float() | nil | error()
```

The range value of `value` by the signed power, `0.5` of the range in a collapsed
transformed domain, clamped to the range's bounds when the scale clamps; `nil` for a
value that is not a number.

# `bandwidth`

```elixir
@spec bandwidth(t()) :: 0 | error()
```

`0`: a power scale has no bandwidth.

# `clamp`

```elixir
@spec clamp(t(), boolean()) :: t() | error()
```

Sets clamping of the output to the range; answers the struct.

# `domain`

```elixir
@spec domain(t(), term()) :: {:ok, t()} | error()
```

Sets the domain, a two-element list or tuple of numbers, stored as a list.

# `domain!`

```elixir
@spec domain!(t(), term()) :: t()
```

`domain/2`, answering the scale or raising `Macaw.Draw.Error`.

# `exponent`

```elixir
@spec exponent(t(), number()) :: t() | error()
```

Sets the exponent, a number; answers the struct.

# `invert`

```elixir
@spec invert(t(), term()) :: float() | nil | error()
```

The domain value of a range value, `T⁻¹(T(d0) + t · (T(d1) − T(d0)))`; never clamps.

# `new`

```elixir
@spec new() :: t()
```

A power scale of exponent 1.

# `nice`

```elixir
@spec nice(t()) :: t() | error()
```

`Macaw.Draw.Scale.Linear.nice/1`'s domain.

# `padding`

```elixir
@spec padding(t(), number()) :: t() | error()
```

Identity: a power scale has no padding.

# `range`

```elixir
@spec range(t(), term()) :: {:ok, t()} | error()
```

Sets the range, a two-element list or tuple of numbers, stored as a list.

# `range!`

```elixir
@spec range!(t(), term()) :: t()
```

`range/2`, answering the scale or raising `Macaw.Draw.Error`.

# `sqrt`

```elixir
@spec sqrt() :: t()
```

A square-root scale: exponent 0.5, kind `:sqrt`.

# `ticks`

```elixir
@spec ticks(t(), number()) :: [number()] | error()
```

`Macaw.Draw.Scale.Linear.ticks/2` over the domain.

---

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