Macaw.Draw.Shape.Rule (macaw_draw v0.1.0)

Copy Markdown View Source

A vertical rule at a domain value, with an optional label (spec/07 §12), copied from visualize's Visualize.Shape.Rule: an instant (a deploy, an incident) inside the same scale and plot as the data.

x/2 yields a domain value that scale/2 maps, any scale Macaw.Draw.Scale.apply/2 takes; with no scale the value is a pixel. new/0 reads each datum as its own value, so a list of bare values is valid data:

iex> alias Macaw.Draw.Shape.Rule
iex> [group] = Rule.generate(Rule.new(), [33])
iex> [line] = group.children
iex> {group.style, line.attrs}
{%{class: "rule"}, %{x1: 33, y1: 0, x2: 33, y2: 100}}

generate/2 answers one :group per datum, style: %{class: "rule"}: a :line from (px, y0) to (px, y1) and, with a label, a :text right of the rule's upper end. A value the scale places nowhere draws nothing for its datum. The label is a function, an atom field, or a string; nil clears it.

Summary

Types

A refusal: faults with their paths.

t()

Functions

One :group element per drawn datum: the line, then the label when there is one.

Sets the label: a function, an atom field, or a string; nil clears it.

A rule reading each datum as its own x value, with extent 0 to 100.

Sets the x scale the values map through; nil means the values are pixels.

Sets the domain value accessor: a function, a field, or a number.

Sets the first vertical extent accessor: a function, a field, or a number.

Sets the second vertical extent accessor: a function, a field, or a number.

Types

accessor()

@type accessor() :: (term() -> term()) | atom() | String.t() | number()

error()

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

A refusal: faults with their paths.

t()

@type t() :: %Macaw.Draw.Shape.Rule{
  label: (term() -> term()) | nil,
  scale: struct() | nil,
  x: (term() -> term()) | nil,
  y0: (term() -> term()) | number(),
  y1: (term() -> term()) | number()
}

Functions

generate(rule, data)

@spec generate(t(), [term()]) :: [Macaw.Draw.IR.Element.t()] | error()

One :group element per drawn datum: the line, then the label when there is one.

label(rule, label)

@spec label(t(), term()) :: t() | error()

Sets the label: a function, an atom field, or a string; nil clears it.

new()

@spec new() :: t()

A rule reading each datum as its own x value, with extent 0 to 100.

scale(rule, scale)

@spec scale(t(), struct() | nil) :: t() | error()

Sets the x scale the values map through; nil means the values are pixels.

x(rule, accessor)

@spec x(t(), accessor()) :: t() | error()

Sets the domain value accessor: a function, a field, or a number.

y0(rule, accessor)

@spec y0(t(), accessor()) :: t() | error()

Sets the first vertical extent accessor: a function, a field, or a number.

y1(rule, accessor)

@spec y1(t(), accessor()) :: t() | error()

Sets the second vertical extent accessor: a function, a field, or a number.