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
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
@type t() :: %Visualize.Shape.Band{ fill: text_accessor() | nil, height: accessor(), x0: accessor() | nil, x1: accessor() | nil, y: accessor() }
An accessor whose value is text: a 1-arity function, an atom field, or a string.
Functions
@spec fill(t(), text_accessor() | nil) :: t()
Sets the fill accessor: a 1-arity function, an atom field, or a string constant
@spec generate(t(), Visualize.Data.Table.source()) :: [Visualize.IR.Element.t()]
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.
@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.
Sets the height accessor, in pixels
@spec new() :: t()
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