The angles of a pie, as data (spec/07 §7), copied from visualize's
Visualize.Shape.Pie. It draws nothing: generate/2 answers one arc datum per datum,
in data order, that Macaw.Draw.Shape.Arc consumes directly.
iex> alias Macaw.Draw.Shape.Pie
iex> [a, b] = Pie.generate(Pie.new(), [1, 3])
iex> {a.end_angle, b.start_angle, b.value}
{1.5707963267948966, 1.5707963267948966, 3}An arc datum is %{data: d, value: v, index: i, start_angle: a, end_angle: b, pad_angle: p}: v = max(0, value.(d)) (a value that is not a number read as 0), the
span da = clamp(end − start, −2π, 2π) shared out as k = (da − n·pad) / Σv per unit
(0 when the total is not positive), the pad after each positive value only. Sorting
(sort/2 on the data, sort_values/2 on the values) changes the angles, never the
order of the answer.
start_angle, end_angle and pad_angle are numbers or 1-arity functions of the whole
data list, evaluated once per generate/2; one answering no number is
{[key], {:type, :number}}.
Summary
Functions
Sets end_angle: radians, or a 1-arity function of the whole data list.
The arc data (§7): [] for empty data, else one map per datum in data order.
A pie whose value is the datum itself when a number, its :value field (by spelling)
when a map, 0 when that is absent or nil, and 0 otherwise.
Sets pad_angle: radians, or a 1-arity function of the whole data list.
Sets the comparator on data, a 2-arity function, and clears sort_values; nil unsets.
Sets the comparator on values, a 2-arity function, and clears sort; nil unsets.
Sets start_angle: radians, or a 1-arity function of the whole data list.
Sets the value accessor: a function, a field (0 when absent), or a number.
Types
@type error() :: {:error, [Macaw.Base.Fault.t()]}
A refusal: faults with their paths.
@type t() :: %Macaw.Draw.Shape.Pie{ end_angle: angle(), pad_angle: angle(), sort: comparator() | nil, sort_values: comparator() | nil, start_angle: angle(), value: (term() -> term()) | nil }
Functions
Sets end_angle: radians, or a 1-arity function of the whole data list.
The arc data (§7): [] for empty data, else one map per datum in data order.
@spec new() :: t()
A pie whose value is the datum itself when a number, its :value field (by spelling)
when a map, 0 when that is absent or nil, and 0 otherwise.
Sets pad_angle: radians, or a 1-arity function of the whole data list.
@spec sort(t(), comparator() | nil) :: t() | error()
Sets the comparator on data, a 2-arity function, and clears sort_values; nil unsets.
@spec sort_values(t(), comparator() | nil) :: t() | error()
Sets the comparator on values, a 2-arity function, and clears sort; nil unsets.
Sets start_angle: radians, or a 1-arity function of the whole data list.
Sets the value accessor: a function, a field (0 when absent), or a number.