Visualize.Layout.Chord (Visualize v0.2.25)

Copy Markdown View Source

Chord diagram layout for visualizing relationships between groups.

Chord diagrams display flows or connections between entities arranged in a circle. The outer arcs represent groups, and the chords connecting them represent relationships.

Examples

# Matrix where matrix[i][j] is the flow from group i to group j
matrix = [
  [11975,  5871, 8916, 2868],
  [ 1951, 10048, 2060, 6171],
  [ 8010, 16145, 8090, 8045],
  [ 1013,   990,  940, 6907]
]

chord = Visualize.Layout.Chord.new()
  |> Visualize.Layout.Chord.pad_angle(0.05)

result = Visualize.Layout.Chord.generate(chord, matrix)

# result.groups - list of group arcs with start_angle, end_angle, value, index
# result.chords - list of chords with source/target containing start_angle, end_angle, index

Summary

Functions

Generates an SVG path for a group arc.

Generates the chord layout from a matrix.

Creates a new chord layout

Sets the padding angle between groups in radians

Generates an SVG path for a chord ribbon.

Sets the comparator for sorting chords

Sets the comparator for sorting groups

Sets the comparator for sorting subgroups within each group

Types

chord()

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

chord_end()

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

group()

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

result()

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

t()

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

Functions

arc_path(group, inner_radius, outer_radius)

@spec arc_path(group(), number(), number()) :: String.t()

Generates an SVG path for a group arc.

generate(chord, matrix)

@spec generate(t(), [[number()]]) :: result()

Generates the chord layout from a matrix.

The matrix should be a list of lists where matrix[i][j] represents the flow from group i to group j.

Returns a map with :groups and :chords.

new()

@spec new() :: t()

Creates a new chord layout

pad_angle(chord, angle)

@spec pad_angle(t(), number()) :: t()

Sets the padding angle between groups in radians

ribbon_path(chord, radius)

@spec ribbon_path(chord(), number()) :: String.t()

Generates an SVG path for a chord ribbon.

The ribbon connects the source and target arcs with bezier curves.

sort_chords(chord, func)

@spec sort_chords(t(), (chord(), chord() -> boolean()) | nil) :: t()

Sets the comparator for sorting chords

sort_groups(chord, func)

@spec sort_groups(t(), (group(), group() -> boolean()) | nil) :: t()

Sets the comparator for sorting groups

sort_subgroups(chord, func)

@spec sort_subgroups(t(), (number(), number() -> boolean()) | nil) :: t()

Sets the comparator for sorting subgroups within each group