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

Copy Markdown View Source

A point symbol of a given area (spec/07 §9), copied from visualize's Visualize.Shape.Symbol.

type is a symbol type, read by spelling (an atom or its string), or a 1-arity function of the datum answering one; size is a number in square user units or a 1-arity function answering one. Every path is about the origin.

iex> alias Macaw.Draw.Shape.Symbol
iex> {:ok, square} = Symbol.type(Symbol.new(), "square")
iex> square |> Symbol.size(16) |> Symbol.generate()
"M-2,-2L2,-2L2,2L-2,2Z"

Only :circle and :square have area exactly size; the others are sized so their bounding area is about it. type/2 refuses a name none of types/0 spells as {[], {:unknown, :symbol, spelling}}; a function type answering an unknown name, and a size that is not a non-negative number, draw the empty path for that datum.

Summary

Types

A refusal: faults with their paths.

t()

Functions

The path data with nil as the datum.

The SVG path data of a datum's symbol.

The Macaw.Draw.IR.Path of a datum's symbol (§9).

A :circle of size 64.

Sets the size, an area in square user units, or a function of the datum.

Sets the type: a name read by spelling, or a function: {:ok, symbol} or {:error, faults}.

As type/2, the symbol itself, raising Macaw.Draw.Error with its faults.

The seven symbol types.

Types

error()

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

A refusal: faults with their paths.

symbol_type()

@type symbol_type() ::
  :circle | :cross | :diamond | :square | :star | :triangle | :wye

t()

@type t() :: %Macaw.Draw.Shape.Symbol{
  size: number() | (term() -> term()),
  type: symbol_type() | (term() -> term())
}

Functions

generate(symbol)

@spec generate(t()) :: String.t() | error()

The path data with nil as the datum.

generate(symbol, datum)

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

The SVG path data of a datum's symbol.

generate_path(symbol, datum)

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

The Macaw.Draw.IR.Path of a datum's symbol (§9).

new()

@spec new() :: t()

A :circle of size 64.

size(symbol, size)

@spec size(t(), number() | (term() -> term())) :: t() | error()

Sets the size, an area in square user units, or a function of the datum.

type(symbol, fun)

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

Sets the type: a name read by spelling, or a function: {:ok, symbol} or {:error, faults}.

type!(symbol, type)

@spec type!(t(), term()) :: t()

As type/2, the symbol itself, raising Macaw.Draw.Error with its faults.

types()

@spec types() :: [symbol_type()]

The seven symbol types.