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

Copy Markdown View Source

A state timeline: one rectangle per datum (spec/07 §11), copied from visualize's Visualize.Shape.Band.

Each datum spans x0 to x1 at y, height tall, filled per datum. The four coordinates are pixel accessors: the caller (a layer) applies the x scale. new/0 reads tuple elements 0 and 1 as the edges, with y = 0 and height = 10:

iex> alias Macaw.Draw.Shape.Band
iex> [rect] = Band.generate(Band.new(), [{50, 10}])
iex> {rect.type, rect.attrs, rect.style}
{:rect, %{x: 10, y: 0, width: 40, height: 10}, %{class: "band"}}

generate/2 answers one :rect element per datum in data order, x the lesser edge and width non-negative, its style %{class: "band"} plus fill: when the fill accessor answers a value. Coinciding edges give a zero-width rectangle; a datum with an undefined coordinate is not emitted (§1.1). generate_path/2 folds the rectangles into one path, the fill playing no part. The fill is a function, an atom field, or a color value of macaw_layers.

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 :rect element per drawn datum, in data order.

One Macaw.Draw.IR.Path of closed rectangles, in data order.

Sets the height accessor, in pixels: a function, a field, or a number.

A band reading tuple elements 0 and 1 as its edges, y = 0 and height = 10.

Sets the start edge accessor, in pixels: a function, a field, or a number.

Sets the end edge accessor, in pixels: a function, a field, or a number.

Sets the top accessor, in pixels: 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.Band{
  fill: (term() -> term()) | nil,
  height: (term() -> term()) | number(),
  x0: (term() -> term()) | nil,
  x1: (term() -> term()) | nil,
  y: (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 :rect element per drawn datum, in data order.

generate_path(band, data)

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

One Macaw.Draw.IR.Path of closed rectangles, in data order.

height(band, accessor)

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

Sets the height accessor, in pixels: a function, a field, or a number.

new()

@spec new() :: t()

A band reading tuple elements 0 and 1 as its edges, y = 0 and height = 10.

x0(band, accessor)

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

Sets the start edge accessor, in pixels: a function, a field, or a number.

x1(band, accessor)

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

Sets the end edge accessor, in pixels: a function, a field, or a number.

y(band, accessor)

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

Sets the top accessor, in pixels: a function, a field, or a number.