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

Copy Markdown View Source

One sector per datum about its angle (spec/07 §15), copied from visualize's Visualize.Shape.Rose: a wind rose, a compass rose, an hour-of-day clock.

angle/2 and width/2 are in the domain units of the radial scale given to scale/2 (radians without one): the sector runs from apply(scale, angle − width/2) to apply(scale, angle + width/2). Over a Macaw.Draw.Scale.Band the angle is a category and the sector its band, from the band's start through bandwidth/1, and width is not read. The radii are pixel accessors; pad_angle/2 is Macaw.Draw.Shape.Arc's.

iex> alias Macaw.Draw.Shape.Rose
iex> Rose.span(nil, 1.0, 0.5)
{0.75, 1.25}

generate_path/2 answers one path per datum in data order, Macaw.Draw.Shape.Arc's path for that datum's radii, span and pad; a datum with no span draws the empty path, so the list stays one path a datum.

Summary

Types

A refusal: faults with their paths.

t()

Functions

Sets the sector center, in the scale's domain units, accessor: a function, a field, or a number.

One SVG path data string per datum.

One Macaw.Draw.IR.Path per datum, the empty path for a datum with no span.

Sets the inner radius, in pixels, accessor: a function, a field, or a number.

A rose reading tuple elements 0 and 1 as angle and outer radius, width 1.

Sets the outer radius, in pixels, accessor: a function, a field, or a number.

Sets the pad angle, in radians, accessor: a function, a field, or a number.

Sets the radial scale the angles map through; nil means radians.

A sector's sweep, {start, end} in radians, or nil when the datum does not place: a category off a band scale's domain, an angle or width that is not a number over any other scale, or a scale that answers something other than a number.

Sets the sector width, in the scale's domain units, accessor: a function, a field, or a number.

Types

accessor()

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

error()

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

A refusal: faults with their paths.

t()

@type t() :: %Macaw.Draw.Shape.Rose{
  angle: (term() -> term()) | nil,
  inner_radius: (term() -> term()) | number(),
  outer_radius: (term() -> term()) | nil,
  pad_angle: (term() -> term()) | number(),
  scale: struct() | nil,
  width: (term() -> term()) | number()
}

Functions

angle(rose, accessor)

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

Sets the sector center, in the scale's domain units, accessor: a function, a field, or a number.

generate(rose, data)

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

One SVG path data string per datum.

generate_path(rose, data)

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

One Macaw.Draw.IR.Path per datum, the empty path for a datum with no span.

inner_radius(rose, accessor)

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

Sets the inner radius, in pixels, accessor: a function, a field, or a number.

new()

@spec new() :: t()

A rose reading tuple elements 0 and 1 as angle and outer radius, width 1.

outer_radius(rose, accessor)

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

Sets the outer radius, in pixels, accessor: a function, a field, or a number.

pad_angle(rose, accessor)

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

Sets the pad angle, in radians, accessor: a function, a field, or a number.

scale(rose, scale)

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

Sets the radial scale the angles map through; nil means radians.

span(scale, center, width)

@spec span(struct() | nil, term(), term()) :: {number(), number()} | nil

A sector's sweep, {start, end} in radians, or nil when the datum does not place: a category off a band scale's domain, an angle or width that is not a number over any other scale, or a scale that answers something other than a number.

width(rose, accessor)

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

Sets the sector width, in the scale's domain units, accessor: a function, a field, or a number.