Choreo.Lab.View (Choreo v0.12.0)

Copy Markdown View Source

Pipe-friendly view helpers for exploring Choreo models in Livebook.

This module is ordinary Elixir, not a macro DSL. It is a thin convenience layer over Choreo.View that keeps the stable view API intact while making common zoom, focus, filter, path, and collapse operations easier to compose in pipelines.

Choreo.View remains the primitive graph-lens API. Choreo.Lab.View is the ergonomic exploration API: a place to try friendlier names, positional forms, and common predicates before deciding whether any of them should graduate into core Choreo.View.

Prefer alias-qualified usage for better editor autocomplete:

alias Choreo.Lab.View

system
|> View.zoom(1)
|> View.only_type([:service, :database, :cache])
|> View.focus(:api, depth: 2)

The functions return ordinary Choreo structs rebuilt through the Choreo.Viewable protocol.

Summary

Functions

Keeps the shortest path between two nodes, optionally with surrounding radius.

Collapses the listed node IDs into new_id.

Collapses all nodes of the given type(s) into new_id.

Keeps node and its surrounding neighbourhood.

Alias for focus/3 that reads naturally in exploratory pipelines.

Generic keep filter for small Livebook experiments.

Keeps only the listed node IDs.

Keeps only nodes whose :node_type or :type matches the given type(s).

Renders the diagram as a tabbed layout in Livebook featuring Siren, Graphviz, and Sketch.

Returns the view helper vocabulary for Livebook discovery.

Converts the diagram to a Graphviz DOT string.

Converts the diagram to a Mermaid string.

Renders the diagram using the Siren Kino widget in Livebook.

Renders the diagram using the Sketch Kino widget in Livebook.

Keeps a trace path between two nodes using Choreo.View.focus_trace/4.

Compatibility alias for taxonomy/0.

Generic remove filter for small Livebook experiments.

Removes the listed node IDs.

Removes nodes whose :node_type or :type matches the given type(s).

Applies Choreo.View.zoom/2 with a positional level.

Types

node_id()

@type node_id() :: Yog.node_id()

node_type()

@type node_type() :: atom()

viewable()

@type viewable() :: struct()

Functions

between(diagram, from, to, opts \\ [])

@spec between(viewable(), node_id(), node_id(), keyword()) :: viewable()

Keeps the shortest path between two nodes, optionally with surrounding radius.

collapse_nodes(diagram, ids, new_id, opts \\ [])

@spec collapse_nodes(viewable(), node_id() | [node_id()], node_id(), keyword()) ::
  viewable()

Collapses the listed node IDs into new_id.

collapse_type(diagram, types, new_id, opts \\ [])

@spec collapse_type(viewable(), node_type() | [node_type()], node_id(), keyword()) ::
  viewable()

Collapses all nodes of the given type(s) into new_id.

focus(diagram, node, opts \\ [])

@spec focus(viewable(), node_id(), keyword()) :: viewable()

Keeps node and its surrounding neighbourhood.

Accepts either :depth or :radius; both map to Choreo.View.focus/3's :radius option. :mode may be :neighbors, :successors, or :predecessors.

neighborhood(diagram, node, opts \\ [])

@spec neighborhood(viewable(), node_id(), keyword()) :: viewable()

Alias for focus/3 that reads naturally in exploratory pipelines.

only(diagram, opts)

@spec only(
  viewable(),
  keyword()
) :: viewable()

Generic keep filter for small Livebook experiments.

Supported options:

  • :nodes — node ID or IDs to keep
  • :type / :types — semantic node type or types to keep

When both are supplied, a node may match either condition.

only_nodes(diagram, ids, opts \\ [])

@spec only_nodes(viewable(), node_id() | [node_id()], keyword()) :: viewable()

Keeps only the listed node IDs.

only_type(diagram, types, opts \\ [])

@spec only_type(viewable(), node_type() | [node_type()], keyword()) :: viewable()

Keeps only nodes whose :node_type or :type matches the given type(s).

path(diagram, from, to, opts \\ [])

@spec path(viewable(), node_id(), node_id(), keyword()) :: viewable()

Alias for between/4.

tabs(diagram, opts \\ [])

@spec tabs(
  viewable(),
  keyword()
) :: any()

Renders the diagram as a tabbed layout in Livebook featuring Siren, Graphviz, and Sketch.

Only active when Kino is loaded. Returns the Kino widget tab layout. If Kino is not loaded, returns the diagram unmodified.

taxonomy()

@spec taxonomy() :: %{
  transforms: [atom()],
  filters: [atom()],
  collapse: [atom()],
  options: [atom()],
  renders: [atom()]
}

Returns the view helper vocabulary for Livebook discovery.

iex> taxonomy = Choreo.Lab.View.taxonomy()
iex> :zoom in taxonomy.transforms
true
iex> :only_type in taxonomy.filters
true
iex> :collapse_type in taxonomy.collapse
true

to_dot(diagram, opts \\ [])

@spec to_dot(
  viewable(),
  keyword()
) :: String.t()

Converts the diagram to a Graphviz DOT string.

to_mermaid(diagram, opts \\ [])

@spec to_mermaid(
  viewable(),
  keyword()
) :: String.t()

Converts the diagram to a Mermaid string.

to_siren(diagram, opts \\ [])

@spec to_siren(
  viewable(),
  keyword()
) :: any()

Renders the diagram using the Siren Kino widget in Livebook.

Only active when Kino is loaded. Returns the Kino widget. If Kino is not loaded, returns the diagram unmodified.

to_sketch(diagram, opts \\ [])

@spec to_sketch(
  viewable(),
  keyword()
) :: any()

Renders the diagram using the Sketch Kino widget in Livebook.

Only active when Kino is loaded. Returns the Kino widget. If Kino is not loaded, returns the diagram unmodified.

trace(diagram, from, to, opts \\ [])

@spec trace(viewable(), node_id(), node_id(), keyword()) :: viewable()

Keeps a trace path between two nodes using Choreo.View.focus_trace/4.

verbs()

@spec verbs() :: %{
  transforms: [atom()],
  filters: [atom()],
  collapse: [atom()],
  options: [atom()],
  renders: [atom()]
}

Compatibility alias for taxonomy/0.

without(diagram, opts)

@spec without(
  viewable(),
  keyword()
) :: viewable()

Generic remove filter for small Livebook experiments.

Supported options mirror only/2.

without_nodes(diagram, ids, opts \\ [])

@spec without_nodes(viewable(), node_id() | [node_id()], keyword()) :: viewable()

Removes the listed node IDs.

without_type(diagram, types, opts \\ [])

@spec without_type(viewable(), node_type() | [node_type()], keyword()) :: viewable()

Removes nodes whose :node_type or :type matches the given type(s).

zoom(diagram, level, opts \\ [])

@spec zoom(viewable(), non_neg_integer(), keyword()) :: viewable()

Applies Choreo.View.zoom/2 with a positional level.

iex> system = Choreo.new() |> Choreo.add_service(:api) |> Choreo.add_database(:db)
iex> system |> Choreo.Lab.View.zoom(0) |> Choreo.nodes()
%{api: %{label: "api", node_type: :service}}