Boxart.Graph (Boxart v0.3.2)

Copy Markdown View Source

Internal graph representation for the rendering pipeline.

Users should build graphs with Graph from libgraph and pass them to Boxart.render/2. This module handles the conversion via from_libgraph/2.

Summary

Functions

Appends an edge to the graph.

Adds a node to the graph.

Finds a subgraph by its id, searching recursively through nested children.

Finds the innermost subgraph containing node_id.

Converts a libgraph Graph.t() into the internal representation.

Returns ids of nodes reachable via outgoing edges from node_id, in edge order.

Returns root node ids — nodes with no incoming edges, in definition order.

Returns true if the direction flows horizontally.

Normalizes a direction to its canonical form (:bt:tb, :rl:lr, :td:tb).

Returns true if the direction is reversed (bottom-to-top or right-to-left).

Returns true if the direction flows vertically.

Returns a copy of the graph with the given direction.

Types

arrow_type()

@type arrow_type() :: :arrow | :circle | :cross

direction()

@type direction() :: :tb | :td | :lr | :bt | :rl

edge_style()

@type edge_style() :: :solid | :dotted | :thick | :invisible

node_shape()

@type node_shape() ::
  :rectangle
  | :rounded
  | :stadium
  | :subroutine
  | :diamond
  | :hexagon
  | :circle
  | :double_circle
  | :asymmetric
  | :cylinder
  | :parallelogram
  | :parallelogram_alt
  | :trapezoid
  | :trapezoid_alt
  | :start_state
  | :end_state
  | :fork_join
  | :junction

t()

@type t() :: %Boxart.Graph{
  direction: direction(),
  edges: [Boxart.Graph.Edge.t()],
  node_order: [String.t()],
  nodes: %{required(String.t()) => Boxart.Graph.Node.t()},
  subgraphs: [Boxart.Graph.Subgraph.t()]
}

Functions

add_edge(graph, edge)

@spec add_edge(t(), Boxart.Graph.Edge.t()) :: t()

Appends an edge to the graph.

add_node(graph, node)

@spec add_node(t(), Boxart.Graph.Node.t()) :: t()

Adds a node to the graph.

If a node with the same id already exists, merges non-default fields from the new node into the existing one.

find_subgraph_by_id(graph, sg_id)

@spec find_subgraph_by_id(t(), String.t()) :: Boxart.Graph.Subgraph.t() | nil

Finds a subgraph by its id, searching recursively through nested children.

find_subgraph_for_node(graph, node_id)

@spec find_subgraph_for_node(t(), String.t()) :: Boxart.Graph.Subgraph.t() | nil

Finds the innermost subgraph containing node_id.

from_libgraph(libgraph, opts \\ [])

@spec from_libgraph(
  Graph.t(),
  keyword()
) :: t()

Converts a libgraph Graph.t() into the internal representation.

Vertex labels are keyword lists. Recognized keys:

  • :label — display text (defaults to inspect(vertex))
  • :shape — node shape atom (default: :rectangle)
  • :source — raw source code string (renders as a code block instead of label)
  • :start_line — starting line number for code display (default: 1)
  • :language — language atom for syntax highlighting (e.g. :elixir)

Edge labels become the display text on the edge.

Options

  • :direction — layout direction (default: :td)

get_children(graph, node_id)

@spec get_children(t(), String.t()) :: [String.t()]

Returns ids of nodes reachable via outgoing edges from node_id, in edge order.

get_roots(graph)

@spec get_roots(t()) :: [String.t()]

Returns root node ids — nodes with no incoming edges, in definition order.

Falls back to the first defined node when every node has incoming edges.

horizontal?(dir)

@spec horizontal?(direction()) :: boolean()

Returns true if the direction flows horizontally.

is_arrow_type(t)

(macro)

is_direction(d)

(macro)

is_edge_style(s)

(macro)

is_node_shape(s)

(macro)

normalized(dir)

@spec normalized(direction()) :: :tb | :lr

Normalizes a direction to its canonical form (:bt:tb, :rl:lr, :td:tb).

reversed?(dir)

@spec reversed?(direction()) :: boolean()

Returns true if the direction is reversed (bottom-to-top or right-to-left).

vertical?(dir)

@spec vertical?(direction()) :: boolean()

Returns true if the direction flows vertically.

with_direction(graph, direction)

@spec with_direction(t(), direction()) :: t()

Returns a copy of the graph with the given direction.