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

Copy Markdown View Source

A network from a links slot and an optional nodes slot (spec/08 §1.3): the one graph every network layout reads (chord, sankey and force; the layered layouts of the second cut).

A graph is tables bound to slots, never a new data type. The Frame reads the links slot's source, target and value role columns, and the nodes slot's id column when there is one, and passes them as lists:

iex> {:ok, graph} = Macaw.Draw.Layout.Graph.new(["a", "a"], ["b", "c"], [3, nil], nil, 1)
iex> {graph.ids, graph.links}
{["a", "b", "c"], [{0, 1, 3}, {0, 2, 1}]}
  • Nodes. Without node_ids, the distinct ids over every source and then every target, in order of first appearance. With them, those ids in the nodes slot's order, each node's row the nodes slot's row it came from; a node no link mentions is isolated. An id given twice is {[:nodes, i], {:duplicate, id}}.
  • Links. Link i is {source_position, target_position, value}, the value the column's reading, or default_value with no value column or a nil reading. An endpoint the nodes slot lacks is {[:links, i, :source], {:unknown_node, id}} (or :target), a value that is no number {[:links, i, :value], {:type, :number}}.
  • Rows. node_rows is the nodes slot's row of each node, or nil without a nodes slot; link_rows the links slot's row of each link. Every output column a network layout answers carries them, so the Frame joins a node's own columns back by row.

This is visualize's Visualize.Chart.Transform.Layout flows/3, nodes/3 and with_node/2, over columns rather than rows, with faults where it raised.

Summary

Types

A refusal: faults with their paths.

t()

Functions

The graph of sources, targets and values (lists of one length; values may be nil), with the nodes slot's node_ids or nil, reading a missing value as default_value (§1.3). Answers {:ok, graph} or {:error, faults}, every fault at once.

Types

error()

@type error() :: {:error, [Macaw.Base.Fault.t()]}

A refusal: faults with their paths.

t()

@type t() :: %Macaw.Draw.Layout.Graph{
  ids: [term()],
  index: %{required(term()) => non_neg_integer()},
  link_rows: [non_neg_integer()],
  links: [{non_neg_integer(), non_neg_integer(), number()}],
  node_rows: [non_neg_integer()] | nil
}

Functions

new(sources, targets, values, node_ids, default_value)

@spec new([term()], [term()], [number() | nil] | nil, [term()] | nil, number()) ::
  {:ok, t()} | error()

The graph of sources, targets and values (lists of one length; values may be nil), with the nodes slot's node_ids or nil, reading a missing value as default_value (§1.3). Answers {:ok, graph} or {:error, faults}, every fault at once.