A reference axis as scene elements: its domain line, tick marks and labels (spec/06
§17), d3-axis's geometry (visualize Visualize.Axis, D-23, D-55, D-56).
{:ok, scale} = Macaw.Draw.Scale.new(:linear, domain: [0, 100], range: [0, 200])
{:ok, axis} = Macaw.Draw.Axis.bottom(scale)
{:ok, svg} = axis |> Macaw.Draw.Axis.ticks(5) |> Macaw.Draw.Axis.render()An axis takes only a position scale: a continuous one, a Band, or an Ordinal whose
range is all numbers; any other is {:not_positional, kind}. Its colors and font are the
theme's slots "axis", "text", "font_size" and "font_family", written as CSS
references (var(--mw-axis, #666666)) or, with resolve: :literal, as plain values;
nothing is currentColor, and the group is aria-hidden. An axis built by hand is d3's:
ten ticks and the default label. Every setter answers the struct, and an argument of the
wrong type its fault.
Summary
Functions
An axis below the plot: new(scale, :bottom).
bottom/1, answering the axis or raising Macaw.Draw.Error.
The default label (spec/06 §17.5): a float rounded to six decimals in plain notation,
trailing zeros and point removed, never an exponent and never -0; any other value
to_string/1, or inspected where it has none.
generate(axis, resolve: :css).
The axis as a scene group (spec/06 §17.4): {:ok, group}, or the faults of resolving its
theme's slots at [:theme, slot]. :resolve is :css (the default) or :literal.
generate/2, answering the group or raising Macaw.Draw.Error.
An axis left of the plot: new(scale, :left).
left/1, answering the axis or raising Macaw.Draw.Error.
An axis of a position scale on a side, the orientation an atom or its string:
{:ok, axis}, or {:error, [{[], {:not_positional, kind}}]} for a scale that maps to
range elements rather than positions.
new/2, answering the axis or raising Macaw.Draw.Error.
An offset added to every tick position (crisp half-pixel alignment).
render(axis, []).
The axis written by a target (spec/06 §17.6): generate/2 then
Macaw.Draw.Render.to_string/2 with the same options, :resolve defaulting to the
target's theme mode. {:ok, string} or the faults of either.
render/2, answering the string or raising Macaw.Draw.Error.
An axis right of the plot: new(scale, :right).
right/1, answering the axis or raising Macaw.Draw.Error.
The theme the colors, font and size resolve from, or nil for the default theme.
How a tick value becomes its label: a Macaw.Draw.Format, a Macaw.Format, a
Macaw.Format.Time, a Macaw.Format.Measure, a 1-arity function, or nil
for the default label.
The gap between a tick line's end and its label.
The position of a tick value (spec/06 §17.3): Scale.apply/2 plus the offset and d3's
band centering, max(0, bandwidth − 2·offset) / 2, rounded when the band scale rounds;
nil for a value the scale places nowhere. A frame's grid lines are drawn here too.
The inner and outer tick sizes together.
The length of each tick line.
The length of the domain line's end caps.
Explicit tick values, bypassing the scale's ticks, or nil.
The tick count hint given to the scale's ticks/2; ignored when tick_values is set.
An axis above the plot: new(scale, :top).
top/1, answering the axis or raising Macaw.Draw.Error.
Types
@type error() :: {:error, [Macaw.Base.Fault.t()]}
A refusal: faults with their paths.
@type orient() :: :top | :right | :bottom | :left
An axis's side.
@type t() :: %Macaw.Draw.Axis{ offset: number(), orient: orient(), scale: struct() | nil, theme: Macaw.Layers.Theme.t() | nil, tick_format: tick_format(), tick_padding: number(), tick_size_inner: number(), tick_size_outer: number(), tick_values: [term()] | nil, ticks: number() | nil }
@type tick_format() :: Macaw.Draw.Format.t() | Macaw.Format.t() | Macaw.Format.Time.t() | Macaw.Format.Measure.t() | (term() -> String.t()) | nil
How a tick value becomes its label.
Functions
An axis below the plot: new(scale, :bottom).
bottom/1, answering the axis or raising Macaw.Draw.Error.
The default label (spec/06 §17.5): a float rounded to six decimals in plain notation,
trailing zeros and point removed, never an exponent and never -0; any other value
to_string/1, or inspected where it has none.
iex> Enum.map([2.0, 0.1 + 0.2, 1000.0, 0.00001, -0.0], &Macaw.Draw.Axis.default_label/1)
["2", "0.3", "1000", "0.00001", "0"]
@spec generate(t()) :: {:ok, Macaw.Draw.IR.Element.t()} | error()
generate(axis, resolve: :css).
@spec generate(t(), keyword()) :: {:ok, Macaw.Draw.IR.Element.t()} | error()
The axis as a scene group (spec/06 §17.4): {:ok, group}, or the faults of resolving its
theme's slots at [:theme, slot]. :resolve is :css (the default) or :literal.
@spec generate!(t(), keyword()) :: Macaw.Draw.IR.Element.t()
generate/2, answering the group or raising Macaw.Draw.Error.
An axis left of the plot: new(scale, :left).
left/1, answering the axis or raising Macaw.Draw.Error.
An axis of a position scale on a side, the orientation an atom or its string:
{:ok, axis}, or {:error, [{[], {:not_positional, kind}}]} for a scale that maps to
range elements rather than positions.
new/2, answering the axis or raising Macaw.Draw.Error.
An offset added to every tick position (crisp half-pixel alignment).
render(axis, []).
The axis written by a target (spec/06 §17.6): generate/2 then
Macaw.Draw.Render.to_string/2 with the same options, :resolve defaulting to the
target's theme mode. {:ok, string} or the faults of either.
render/2, answering the string or raising Macaw.Draw.Error.
An axis right of the plot: new(scale, :right).
right/1, answering the axis or raising Macaw.Draw.Error.
@spec theme(t(), Macaw.Layers.Theme.t() | nil) :: t() | error()
The theme the colors, font and size resolve from, or nil for the default theme.
@spec tick_format(t(), tick_format()) :: t() | error()
How a tick value becomes its label: a Macaw.Draw.Format, a Macaw.Format, a
Macaw.Format.Time, a Macaw.Format.Measure, a 1-arity function, or nil
for the default label.
The gap between a tick line's end and its label.
The position of a tick value (spec/06 §17.3): Scale.apply/2 plus the offset and d3's
band centering, max(0, bandwidth − 2·offset) / 2, rounded when the band scale rounds;
nil for a value the scale places nowhere. A frame's grid lines are drawn here too.
The inner and outer tick sizes together.
The length of each tick line.
The length of the domain line's end caps.
Explicit tick values, bypassing the scale's ticks, or nil.
The tick count hint given to the scale's ticks/2; ignored when tick_values is set.
An axis above the plot: new(scale, :top).
top/1, answering the axis or raising Macaw.Draw.Error.