The conventions every layout shares (spec/08 §1): options checked once and every fault answered at once, vocabularies read by spelling, and output as columns.
A layout assigns positions to things that have none of their own: the nodes of a
hierarchy (Hierarchy, Tree, Cluster, Pack, Partition, Treemap), the nodes and
links of a network (Graph, Chord, Sankey, Force) and the cells of a hexagonal
binning (Hexbin). Every layout is a pure function of its options and its input.
- Options (§1.1). A layout with options is built by
new/1, which reads every option its table lists throughcheck/2: a key given as a string is read by its spelling, an unknown key is{[key], :unknown_key}, and a bad value is a fault with the option as its path, every fault at once, ordered byMacaw.Base.Fault.sort/1. - Vocabularies (§1.2). An enumerated option is one of the layout's own atoms, or the
string of its spelling, read by
spell/2; no atom is ever made from text. - Columns (§1.4). Each layout's
columnsfunction answers a map from column name, a string, to a list, every list of one length, with a"row"column naming the input row each output row came from and shapes asMacaw.Draw.IR.Pathvalues under"path".columns/2builds one from records.
Input drawn from data never raises: a missing parent, an unknown node, a cycle, a zero
or nil value each has a defined result or a fault in the answer.
Summary
Types
A refusal: faults with their paths.
A layout's option table: each option's key, default and type.
Functions
Reads opts, a keyword list or a map, against schema (§1.1): every option the schema
lists, its default where it is not given, each value checked against its type.
Output columns from records (§1.4): for each {name, key} of fields, the column
name, a string, holding Map.get(record, key) of every record, in record order. Every
column has one length, the records' count.
Reads value against a vocabulary (§1.2): a member atom as it is, or a string that spells
a member as that member. Answers {:ok, atom}, or :error for anything else, never
making an atom from text.
Types
@type error() :: {:error, [Macaw.Base.Fault.t()]}
A refusal: faults with their paths.
A layout's option table: each option's key, default and type.
@type type() :: :number | :non_negative_number | :positive_number | :non_negative_integer | :positive_integer | :boolean | :size | :positive_size | {:function, non_neg_integer()} | {:member, [atom()]} | {:nil_or, type()} | {:either, [type()], atom()} | {:check, (term() -> {:ok, term()} | {:error, term()})}
The type of one option, as check/2 reads it:
:number,:non_negative_number,:positive_number,:non_negative_integer,:positive_integer,:boolean: a value of that kind;:size: two non-negative numbers, a tuple or a list, read as a tuple;:positive_sizethe same of positive numbers;{:function, arity}: a function of that arity, its fault{:type, :function<arity>};{:member, members}: one ofmembers, an atom or the string of its spelling;{:nil_or, type}:nilor a value oftype;{:either, [type], name}: a value of any of the types, its fault{:type, name};{:check, fun}:fun.(value)answers{:ok, value},{:error, reason}(one fault at the option) or{:error, [{path, reason}]}(faults below the option).
Functions
Reads opts, a keyword list or a map, against schema (§1.1): every option the schema
lists, its default where it is not given, each value checked against its type.
Answers {:ok, values}, a map from every schema key to its value, or
{:error, faults}, every fault at once and sorted. A string key is read as the atom key
of the same spelling; a key the schema does not list is {[key], :unknown_key}, the key
as given. Options that are not a keyword list or a map are {[], {:type, :options}}.
iex> schema = [{:padding, 0, :non_negative_number}, {:round, false, :boolean}]
iex> Macaw.Draw.Layout.check(%{"padding" => 2}, schema)
{:ok, %{padding: 2, round: false}}
iex> Macaw.Draw.Layout.check([padding: -1, wat: 1], schema)
{:error, [{[:padding], {:type, :non_negative_number}}, {[:wat], :unknown_key}]}
Output columns from records (§1.4): for each {name, key} of fields, the column
name, a string, holding Map.get(record, key) of every record, in record order. Every
column has one length, the records' count.
iex> Macaw.Draw.Layout.columns([%{x: 1, y: 2}, %{x: 3, y: 4}], [{"x", :x}, {"y", :y}])
%{"x" => [1, 3], "y" => [2, 4]}
Reads value against a vocabulary (§1.2): a member atom as it is, or a string that spells
a member as that member. Answers {:ok, atom}, or :error for anything else, never
making an atom from text.
iex> Macaw.Draw.Layout.spell("slice_dice", [:squarify, :slice_dice])
{:ok, :slice_dice}
iex> Macaw.Draw.Layout.spell("spiral", [:squarify, :slice_dice])
:error