Visualize.Shape.Band (Visualize v0.2.25)

Copy Markdown View Source

Band generator: a state timeline of one rectangle per datum (spec/04 §11, D-26).

Each datum spans x0 to x1 at y, height tall, filled per datum. The coordinates are pixel accessors, so the caller applies the x scale inside x0/x1 exactly as for Visualize.Shape.Line and Visualize.Shape.Area.

Examples

states = [
  %{from: ~U[2024-01-01 00:00:00Z], to: ~U[2024-01-01 06:00:00Z], state: :ok},
  %{from: ~U[2024-01-01 06:00:00Z], to: ~U[2024-01-01 09:00:00Z], state: :down}
]

band =
  Visualize.Shape.Band.new()
  |> Visualize.Shape.Band.x0(fn d -> Visualize.Scale.apply(x_scale, d.from) end)
  |> Visualize.Shape.Band.x1(fn d -> Visualize.Scale.apply(x_scale, d.to) end)
  |> Visualize.Shape.Band.y(20)
  |> Visualize.Shape.Band.height(12)
  |> Visualize.Shape.Band.fill(fn d -> colour(d.state) end)

rects = Visualize.Shape.Band.generate(band, states)

Summary

Types

t()

An accessor whose value is text: a 1-arity function, an atom field, or a string.

Functions

Sets the fill accessor: a 1-arity function, an atom field, or a string constant

Returns one :rect element per datum, in data order.

Returns one IR.Path of closed rectangles, in data order, for a uniformly filled band.

Sets the height accessor, in pixels

Creates a band generator reading tuple elements 0 and 1 as x0/x1

Sets the start-edge accessor, in pixels

Sets the end-edge accessor, in pixels

Sets the top accessor, in pixels

Types

accessor()

@type accessor() :: (any() -> number()) | atom() | number()

t()

@type t() :: %Visualize.Shape.Band{
  fill: text_accessor() | nil,
  height: accessor(),
  x0: accessor() | nil,
  x1: accessor() | nil,
  y: accessor()
}

text_accessor()

@type text_accessor() :: (any() -> String.t() | nil) | atom() | String.t()

An accessor whose value is text: a 1-arity function, an atom field, or a string.

Functions

fill(band, accessor)

@spec fill(t(), text_accessor() | nil) :: t()

Sets the fill accessor: a 1-arity function, an atom field, or a string constant

generate(band, data)

Returns one :rect element per datum, in data order.

The rectangle is normalised so x is the lesser edge and width is non-negative; the style is %{class: "band"} plus fill: when the fill accessor yields a value.

generate_path(band, data)

@spec generate_path(t(), Visualize.Data.Table.source()) :: Visualize.IR.Path.t()

Returns one IR.Path of closed rectangles, in data order, for a uniformly filled band.

height(band, accessor)

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

Sets the height accessor, in pixels

new()

@spec new() :: t()

Creates a band generator reading tuple elements 0 and 1 as x0/x1

x0(band, accessor)

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

Sets the start-edge accessor, in pixels

x1(band, accessor)

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

Sets the end-edge accessor, in pixels

y(band, accessor)

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

Sets the top accessor, in pixels