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

Copy Markdown View Source

A shaded interval between two domain values, with an optional label (spec/07 §13), copied from visualize's Visualize.Shape.XBand: an incident, a maintenance window, under the rule's model.

x0/x1 are domain accessors mapped by scale/2 (no scale: pixels), y0/y1 the pixel extent. new/0 reads tuple elements 0 and 1 as the edges and fills the region as a brush selection is filled, Macaw.Layers.Color.rgb(119, 119, 119, 0.2):

iex> alias Macaw.Draw.Shape.XBand
iex> [group] = XBand.generate(XBand.new(), [{30, 10}])
iex> [rect] = group.children
iex> rect.attrs
%{x: 10, y: 0, width: 20, height: 100}

generate/2 answers one :group per datum, style: %{class: "x-band"}: a :rect between the mapped edges and, with a label, a :text at its top left. An edge the scale places nowhere draws nothing for its datum. The fill is a function, an atom field, or a color value; the label a function, an atom field, or a string.

Summary

Types

A refusal: faults with their paths.

t()

Functions

Sets the fill: a function, an atom field, or a color value; nil unsets it.

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

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

An x-band reading tuple elements 0 and 1 as its edges, extent 0 to 100, the brush's fill.

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

Sets the first edge's domain value accessor: a function, a field, or a number.

Sets the second edge's 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.XBand{
  fill: (term() -> term()) | nil,
  label: (term() -> term()) | nil,
  scale: struct() | nil,
  x0: (term() -> term()) | nil,
  x1: (term() -> term()) | nil,
  y0: (term() -> term()) | number(),
  y1: (term() -> term()) | number()
}

Functions

fill(band, fill)

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

Sets the fill: a function, an atom field, or a color value; nil unsets it.

generate(band, data)

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

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

label(band, 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()

An x-band reading tuple elements 0 and 1 as its edges, extent 0 to 100, the brush's fill.

scale(band, scale)

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

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

x0(band, accessor)

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

Sets the first edge's domain value accessor: a function, a field, or a number.

x1(band, accessor)

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

Sets the second edge's domain value accessor: a function, a field, or a number.

y0(band, accessor)

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

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

y1(band, accessor)

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

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