Macaw.Draw.Layout.Chord (macaw_draw v0.1.0)

Copy Markdown View Source

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:

OptionTypeDefault
pad_anglenon-negative number, radians0
sort_groupsfunction of two %{value: v} maps answering a boolean, or nilnil
sort_subgroupsfunction of two numbers, or nilnil
sort_chordsfunction of two chords, or nilnil
ringnumber 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.

t()

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.

new/1 with every option at its default.

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

chord()

@type chord() :: %{source: chord_end(), target: chord_end()}

A chord between two groups, a self-loop when both ends are one group.

chord_end()

@type chord_end() :: %{
  index: non_neg_integer(),
  start_angle: number(),
  end_angle: number(),
  value: number()
}

One end of a chord: a subgroup arc.

group()

@type group() :: %{
  index: non_neg_integer(),
  start_angle: number(),
  end_angle: number(),
  value: number()
}

A group: its arc on the circle.

result()

@type result() :: %{groups: [group()], chords: [chord()]}

A laid-out matrix.

t()

@type t() :: %Macaw.Draw.Layout.Chord{
  pad_angle: number(),
  ring: number(),
  sort_chords: (chord(), chord() -> boolean()) | nil,
  sort_groups: (map(), map() -> boolean()) | nil,
  sort_subgroups: (number(), number() -> boolean()) | nil
}

Functions

arc_path(group, inner, outer)

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 π.

columns(result, output, opts)

@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, or nil), "index", "id", "start_angle", "end_angle", "value", "path" (the sector between ring · radius and radius, 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 at ring · radius, about the center).

Without a graph, a group's id is its index.

generate(chord, matrix)

@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}}.

matrix(graph)

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.

new()

@spec new() :: {:ok, t()}

new/1 with every option at its default.

new(opts)

@spec new(keyword() | map()) :: {:ok, t()} | Macaw.Draw.Layout.error()

The layout of opts (§7.1): {:ok, chord} or {:error, faults}.

ribbon_path(chord, radius)

@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.