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

Copy Markdown View Source

A line through points (spec/07 §3), copied from visualize's Visualize.Shape.Line.

new/0 reads tuple elements 0 and 1 as x and y, so {x, y} tuples need no configuration:

iex> alias Macaw.Draw.Shape.Line
iex> Line.new() |> Line.generate([{0, 0}, {10, 5}, {20, 2}])
"M0,0L10,5L20,2"

generate_path/2 splits the data into defined runs (§1.2: a falsy defined and a coordinate that is no number each break the line), draws each run through the curve as its own subpath, and concatenates them in data order; no run of two points is the empty path. A layer whose pixels are columns hands runs_path/2 its runs of {x, y} points instead, and reads no accessor (§1.4).

An accessor is a 1-arity function, a field name read from a map datum by spelling (:v finds "v" and the other way round, as Macaw.Data.Table.get/2 reads it), or a numeric constant (§1.1). A generator takes a list of data; any other term is {:error, [{[], {:type, :list}}]}.

Summary

Types

An accessor: a 1-arity function, a field name, or a numeric constant (§1.1).

A refusal: faults with their paths.

t()

Functions

curve(line, type, []).

Sets the curve type (§5) and its options: {:ok, line}, or {:error, faults} for an unknown type ({[], {:unknown, :curve, spelling}}) or an option of the wrong type.

As curve/3, the line itself, raising Macaw.Draw.Error with its faults.

Sets the defined predicate (§1.2), a 1-arity function; nil clears it.

The SVG path data of generate_path/2.

The line's Macaw.Draw.IR.Path: one subpath per defined run of two or more points, each through the curve, in data order (§3).

A line reading tuple elements 0 and 1.

The path of runs already read (§1.4): each run a list of {x, y} points drawn through the curve as its own subpath, in order, as generate_path/2 draws a run of defined data. A point that is no pair of numbers is {[1, run, i], {:type, :point}}.

Sets the x accessor: a function, a field, or a number.

Sets the y accessor: a function, a field, or a number.

Types

accessor()

@type accessor() :: (term() -> term()) | atom() | String.t() | number()

An accessor: a 1-arity function, a field name, or a numeric constant (§1.1).

error()

@type error() :: {:error, [Macaw.Base.Fault.t()]}

A refusal: faults with their paths.

t()

@type t() :: %Macaw.Draw.Shape.Line{
  curve: Macaw.Draw.Shape.Curve.curve_type(),
  curve_opts: keyword(),
  defined: (term() -> term()) | nil,
  x: (term() -> term()) | nil,
  y: (term() -> term()) | nil
}

Functions

curve(line, type)

@spec curve(t(), term()) :: {:ok, t()} | error()

curve(line, type, []).

curve(line, type, opts)

@spec curve(t(), term(), keyword()) :: {:ok, t()} | error()

Sets the curve type (§5) and its options: {:ok, line}, or {:error, faults} for an unknown type ({[], {:unknown, :curve, spelling}}) or an option of the wrong type.

curve!(line, type, opts \\ [])

@spec curve!(t(), term(), keyword()) :: t()

As curve/3, the line itself, raising Macaw.Draw.Error with its faults.

defined(line, predicate)

@spec defined(t(), (term() -> term()) | nil) :: t() | error()

Sets the defined predicate (§1.2), a 1-arity function; nil clears it.

generate(line, data)

@spec generate(t(), [term()]) :: String.t() | error()

The SVG path data of generate_path/2.

generate_path(line, data)

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

The line's Macaw.Draw.IR.Path: one subpath per defined run of two or more points, each through the curve, in data order (§3).

new()

@spec new() :: t()

A line reading tuple elements 0 and 1.

runs_path(line, runs)

@spec runs_path(t(), [[{number(), number()}]]) :: Macaw.Draw.IR.Path.t() | error()

The path of runs already read (§1.4): each run a list of {x, y} points drawn through the curve as its own subpath, in order, as generate_path/2 draws a run of defined data. A point that is no pair of numbers is {[1, run, i], {:type, :point}}.

x(line, accessor)

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

Sets the x accessor: a function, a field, or a number.

y(line, accessor)

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

Sets the y accessor: a function, a field, or a number.