Chord diagrams: a square flow matrix laid out as arcs on a circle with ribbons between them (spec/08 §7).
iex> alias Macaw.Draw.Layout.Chord
iex> {:ok, chord} = Chord.new()
iex> {:ok, %{groups: groups, chords: chords}} = Chord.generate(chord, [[0, 1], [1, 0]])
iex> {Enum.map(groups, & &1.value), length(chords)}
{[1, 1], 1}Options (§7.1), checked by new/1:
| Option | Type | Default |
|---|---|---|
pad_angle | non-negative number, radians | 0 |
sort_groups | function of two %{value: v} maps answering a boolean, or nil | nil |
sort_subgroups | function of two numbers, or nil | nil |
sort_chords | function of two chords, or nil | nil |
ring | number in (0, 1] | 0.9 |
With total the sum of every entry, each unit spans k = (2π − n · pad_angle) / total
radians; groups are laid out consecutively, each spanning its row sum, and within group
i entry j spans matrix[i][j] · k. One chord for every pair i ≤ j with any flow, in
row-major order. Angles run clockwise from 12 o'clock. The shapes, arc_path/3 and
ribbon_path/2, are about the origin; columns/3 places them about a center, the radius
setting only the size (visualize #488). This is visualize's Visualize.Layout.Chord with
Visualize.Chart.Transform.Layout chord/3 and ribbon_path/2, answering IR paths.
Summary
Types
A chord between two groups, a self-loop when both ends are one group.
One end of a chord: a subgroup arc.
A group: its arc on the circle.
A laid-out matrix.
Functions
The annulus sector of group between inner_radius and outer_radius, about the
origin (§7.3): an inner arc from the start to the end angle (sweep 1), a line to the
outer end, the outer arc back (sweep 0), closed; large-arc set when the span exceeds π.
The columns of a laid-out matrix (§7.3), with options radius: (the outer radius, 1 by
default), center: ({0, 0} by default) and graph: (the Graph the matrix came from,
for ids and rows). The radius sets the size, never the center.
The groups and chords of matrix, n rows of n non-negative numbers (§7.2):
{:ok, %{groups: groups, chords: chords}}; an empty matrix answers empty lists. A ragged
row is {[:matrix, i], {:length, n}}, a negative or non-numeric entry
{[:matrix, i, j], {:type, :non_negative_number}}.
The square flow matrix of a graph (§7.2): matrix[i][j] the sum of the values of the
links from node i to node j, in node order.
The layout of opts (§7.1): {:ok, chord} or {:error, faults}.
The ribbon of chord at radius, about the origin (§7.3): the source arc, a quadratic
curve through the origin to the target arc's start, the target arc, a quadratic curve
back to the source's start, closed. A self-loop is the source arc and one quadratic
return.
Types
A chord between two groups, a self-loop when both ends are one group.
@type chord_end() :: %{ index: non_neg_integer(), start_angle: number(), end_angle: number(), value: number() }
One end of a chord: a subgroup arc.
@type group() :: %{ index: non_neg_integer(), start_angle: number(), end_angle: number(), value: number() }
A group: its arc on the circle.
A laid-out matrix.
Functions
@spec arc_path(group(), number(), number()) :: Macaw.Draw.IR.Path.t() | Macaw.Draw.Layout.error()
The annulus sector of group between inner_radius and outer_radius, about the
origin (§7.3): an inner arc from the start to the end angle (sweep 1), a line to the
outer end, the outer arc back (sweep 0), closed; large-arc set when the span exceeds π.
@spec columns(result(), atom() | String.t(), keyword()) :: %{required(String.t()) => [term()]} | Macaw.Draw.Layout.error()
The columns of a laid-out matrix (§7.3), with options radius: (the outer radius, 1 by
default), center: ({0, 0} by default) and graph: (the Graph the matrix came from,
for ids and rows). The radius sets the size, never the center.
:groups(the default): one row per group in index order,"row"(the group node's nodes-slot row, ornil),"index","id","start_angle","end_angle","value","path"(the sector betweenring · radiusandradius, about the center).:chords: one row per chord,"row"(nil: a chord is a pair of groups, not an input row),"source","target"(the ids),"source_value","target_value","path"(the ribbon atring · radius, about the center).
Without a graph, a group's id is its index.
@spec generate(t(), [[number()]]) :: {:ok, result()} | Macaw.Draw.Layout.error()
The groups and chords of matrix, n rows of n non-negative numbers (§7.2):
{:ok, %{groups: groups, chords: chords}}; an empty matrix answers empty lists. A ragged
row is {[:matrix, i], {:length, n}}, a negative or non-numeric entry
{[:matrix, i, j], {:type, :non_negative_number}}.
@spec matrix(Macaw.Draw.Layout.Graph.t()) :: [[number()]] | Macaw.Draw.Layout.error()
The square flow matrix of a graph (§7.2): matrix[i][j] the sum of the values of the
links from node i to node j, in node order.
@spec new() :: {:ok, t()}
new/1 with every option at its default.
@spec new(keyword() | map()) :: {:ok, t()} | Macaw.Draw.Layout.error()
The layout of opts (§7.1): {:ok, chord} or {:error, faults}.
@spec ribbon_path(chord(), number()) :: Macaw.Draw.IR.Path.t() | Macaw.Draw.Layout.error()
The ribbon of chord at radius, about the origin (§7.3): the source arc, a quadratic
curve through the origin to the target arc's start, the target arc, a quadratic curve
back to the source's start, closed. A self-loop is the source arc and one quadratic
return.