Visualize.Shape.Rule (Visualize v0.2.35)

Copy Markdown View Source

Rule generator: a vertical line at a domain x value, with an optional label (spec/04 §12, D-27).

The x accessor yields a domain value that scale/2 maps, so the rule stays aligned with the axis whatever the margins. Without a scale the value is a pixel coordinate. Each datum is one annotation; by default the datum is the value itself.

Examples

rule =
  Visualize.Shape.Rule.new()
  |> Visualize.Shape.Rule.scale(x_scale)
  |> Visualize.Shape.Rule.y1(height)
  |> Visualize.Shape.Rule.label("deploy")

[group] = Visualize.Shape.Rule.generate(rule, [~U[2024-01-01 12:00:00Z]])

Summary

Types

t()

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

Functions

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

Sets the label accessor: function, atom field, or string constant; nil clears it

Creates a rule generator reading each datum as its 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

Sets the first vertical-extent accessor, in pixels

Sets the second vertical-extent accessor, in pixels

Types

t()

@type t() :: %Visualize.Shape.Rule{
  label: (any() -> String.t() | nil) | nil,
  scale: struct() | nil,
  x: Visualize.Shape.Line.accessor() | nil,
  y0: Visualize.Shape.Line.accessor(),
  y1: Visualize.Shape.Line.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

generate(rule, data)

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

label(rule, accessor)

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

Sets the label accessor: function, atom field, or string constant; nil clears it

new()

@spec new() :: t()

Creates a rule generator reading each datum as its x value, with extent 0 to 100

scale(rule, scale)

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

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

x(rule, accessor)

@spec x(t(), Visualize.Shape.Line.accessor()) :: t()

Sets the domain-value accessor

y0(rule, accessor)

@spec y0(t(), Visualize.Shape.Line.accessor()) :: t()

Sets the first vertical-extent accessor, in pixels

y1(rule, accessor)

@spec y1(t(), Visualize.Shape.Line.accessor()) :: t()

Sets the second vertical-extent accessor, in pixels