LiveFlow.Edge (LiveFlow v0.2.3)

Copy Markdown View Source

Edge data structure for LiveFlow.

An edge represents a connection between two nodes, from a source node's handle to a target node's handle.

Fields

  • :id - Unique identifier for the edge (required)
  • :source - Source node ID (required)
  • :target - Target node ID (required)
  • :source_handle - Source handle ID (optional)
  • :target_handle - Target handle ID (optional)
  • :type - Edge type: :bezier, :straight, :step, :smoothstep
  • :animated - Whether to show animation on the edge
  • :selected - Whether the edge is currently selected
  • :selectable - Whether the edge can be selected
  • :deletable - Whether the edge can be deleted
  • :hidden - Whether the edge is visible
  • :data - Custom data map
  • :label - Edge label text
  • :label_position - Position of label along edge (0.0 to 1.0)
  • :label_style - Custom styles for label
  • :marker_start - Marker at start of edge
  • :marker_end - Marker at end of edge
  • :style - Custom inline styles
  • :class - Custom CSS classes
  • :z_index - Stacking order
  • :interaction_width - Clickable width for selection
  • :path_options - Additional options for path calculation

Examples

iex> LiveFlow.Edge.new("e1", "node-1", "node-2")
%LiveFlow.Edge{id: "e1", source: "node-1", target: "node-2"}

iex> LiveFlow.Edge.new("e2", "a", "b", type: :straight, animated: true)
%LiveFlow.Edge{id: "e2", source: "a", target: "b", type: :straight, animated: true}

Summary

Functions

Sets the edge's animated state.

Checks if two edges connect the same nodes (ignoring direction).

Checks if an edge connects to a specific node (either as source or target).

Gets the effective source handle ID.

Gets the effective target handle ID.

Creates a new edge between source and target nodes.

Sets the edge's selected state.

Sets the edge label.

Updates an edge with the given attributes.

Types

t()

@type t() :: %LiveFlow.Edge{
  animated: boolean(),
  class: String.t() | nil,
  data: map(),
  deletable: boolean(),
  hidden: boolean(),
  id: String.t(),
  interaction_width: integer(),
  label: String.t() | nil,
  label_position: float(),
  label_style: map(),
  marker_end: map() | nil,
  marker_start: map() | nil,
  path_options: map(),
  selectable: boolean(),
  selected: boolean(),
  source: String.t(),
  source_handle: String.t() | nil,
  style: map(),
  target: String.t(),
  target_handle: String.t() | nil,
  type: atom(),
  z_index: integer()
}

Functions

animate(edge, animated \\ true)

@spec animate(t(), boolean()) :: t()

Sets the edge's animated state.

connects_same_nodes?(e1, e2)

@spec connects_same_nodes?(t(), t()) :: boolean()

Checks if two edges connect the same nodes (ignoring direction).

connects_to?(edge, node_id)

@spec connects_to?(t(), String.t()) :: boolean()

Checks if an edge connects to a specific node (either as source or target).

effective_source_handle(edge)

@spec effective_source_handle(t()) :: String.t()

Gets the effective source handle ID.

effective_target_handle(edge)

@spec effective_target_handle(t()) :: String.t()

Gets the effective target handle ID.

new(id, source, target, opts \\ [])

@spec new(String.t(), String.t(), String.t(), keyword()) :: t()

Creates a new edge between source and target nodes.

Options

  • :source_handle - Source handle ID
  • :target_handle - Target handle ID
  • :type - Edge type (default: :bezier)
  • :animated - Whether animated (default: false)
  • :selectable - Whether selectable (default: true)
  • :deletable - Whether deletable (default: true)
  • :label - Edge label text
  • :marker_end - End marker config (default: %{type: :arrow})
  • :marker_start - Start marker config
  • :style - Custom inline styles
  • :class - Custom CSS classes
  • :z_index - Stacking order
  • :data - Custom data map

Examples

iex> LiveFlow.Edge.new("1", "a", "b")
%LiveFlow.Edge{id: "1", source: "a", target: "b"}

iex> LiveFlow.Edge.new("2", "a", "b", source_handle: "out", target_handle: "in")
%LiveFlow.Edge{id: "2", source: "a", target: "b", source_handle: "out", target_handle: "in"}

select(edge, selected \\ true)

@spec select(t(), boolean()) :: t()

Sets the edge's selected state.

set_label(edge, label)

@spec set_label(t(), String.t() | nil) :: t()

Sets the edge label.

update(edge, attrs)

@spec update(
  t(),
  keyword()
) :: t()

Updates an edge with the given attributes.