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

Copy Markdown View Source

Swimlanes (spec/08 §13): a layered graph (Macaw.Draw.Layout.Layered) banded into lanes, an activity diagram or a process map whose nodes each belong to one lane.

iex> alias Macaw.Draw.Layout.{Graph, Swimlanes}
iex> {:ok, graph} = Graph.new(["a"], ["b"], nil, nil, 1)
iex> {:ok, lanes} = Swimlanes.new()
iex> {:ok, result} =
...>   Swimlanes.generate(lanes, graph, [{40, 20}, {40, 20}],
...>     [%{id: "ops", label: {30, 10}}, %{id: "dev", label: {30, 10}}], lane_of: ["ops", "dev"])
iex> Enum.map(result.lanes, & &1.id)
["ops", "dev"]

The algorithm (§13.2, spec/08 decision 10):

  1. Ranks along the flow axis are the layered layout's over the whole graph, so a flow's order is the graph's whatever lanes its steps are in.
  2. Order within a rank is grouped by lane: each rank's nodes are ordered first by their lane, then by crossing reduction within one lane's group. A dummy of an edge from lane a to lane b is a's up to the middle of the edge's span and b's after it, so a cross-lane edge changes lanes once.
  3. Across the flow, each lane's nodes are placed by Brandes–Köpf over that lane alone, offset into the lane's band; a band is max(lane_min, extent + 2 · lane_pad) thick, the lanes stacked in order lane_sep apart, and the flow starts after header.
  4. Routing is the layered layout's, :orthogonal by default, so a route crosses a lane boundary perpendicularly.

Options (§13.1): every option of Layered with direction one of directions/0 (:lr, lanes stacked top to bottom and flow left to right, the default; or :tb) and routing defaulting to :orthogonal, plus lane_sep (0), lane_pad (16), lane_min (60) and header (30), each a non-negative number.

Summary

Functions

The columns of a swimlane drawing (§13.3): :nodes and :edges as Layered.columns/2's, and :lanes, one row per lane in order: "row" (nil), "id", "x0", "y0", "x1", "y1" (the band), "label_x", "label_y" (its label's center in the header).

The swimlanes' directions: [:lr, :tb].

The swimlane drawing of graph (§13.1): sizes as Layered.generate/4's, lanes the ordered %{id, label: {w, h}}, and opts Layered's labels: and min_lengths: with lane_of:, the lane id of each node in node order (required).

new/1 with every option at its default.

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

Types

t()

@type t() :: %Macaw.Draw.Layout.Swimlanes{
  align: :balanced | :ul | :ur | :dl | :dr,
  crossing_passes: pos_integer(),
  direction: :lr | :tb,
  edge_sep: number(),
  header: number(),
  lane_min: number(),
  lane_pad: number(),
  lane_sep: number(),
  margin: number(),
  node_sep: number(),
  rank_align: :center | :start | :end,
  rank_sep: number(),
  ranker: :network_simplex | :longest_path,
  routing: :orthogonal | :spline | :polyline,
  simplex_pivots: pos_integer() | nil
}

Functions

columns(result, output)

@spec columns(Macaw.Draw.Layout.Swimlanes.Result.t(), atom() | String.t()) ::
  %{required(String.t()) => [term()]} | Macaw.Draw.Layout.error()

The columns of a swimlane drawing (§13.3): :nodes and :edges as Layered.columns/2's, and :lanes, one row per lane in order: "row" (nil), "id", "x0", "y0", "x1", "y1" (the band), "label_x", "label_y" (its label's center in the header).

directions()

@spec directions() :: [atom()]

The swimlanes' directions: [:lr, :tb].

generate(swimlanes, graph, sizes, lanes, opts)

The swimlane drawing of graph (§13.1): sizes as Layered.generate/4's, lanes the ordered %{id, label: {w, h}}, and opts Layered's labels: and min_lengths: with lane_of:, the lane id of each node in node order (required).

A node of no listed lane is {[:lane_of, i], {:unknown_lane, id}}, a lane that is no %{id, label} {[:lanes, i], {:type, :lane}}, a lane id given twice {[:lanes, i], {:duplicate, id}}; the sizes and edge options fault as the layered layout's.

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 (§13.1): {:ok, swimlanes} or {:error, faults}.