LiveFlow.Node (LiveFlow v0.2.3)

Copy Markdown View Source

Node data structure for LiveFlow.

A node represents a visual element in the flow diagram that can be positioned, connected via handles, and interacted with.

Fields

  • :id - Unique identifier for the node (required)
  • :type - Node type atom, used for custom rendering (default: :default)
  • :position - Position in flow coordinates %{x: number, y: number}
  • :data - Custom data map passed to the node renderer
  • :width - Measured width (set by JS after render)
  • :height - Measured height (set by JS after render)
  • :selected - Whether the node is currently selected
  • :draggable - Whether the node can be dragged
  • :connectable - Whether handles can create connections
  • :selectable - Whether the node can be selected
  • :deletable - Whether the node can be deleted
  • :hidden - Whether the node is visible
  • :dragging - Whether the node is currently being dragged
  • :resizing - Whether the node is currently being resized
  • :parent_id - ID of parent node for grouping
  • :extent - Movement constraint (:parent or bounds map)
  • :style - Custom inline styles map
  • :class - Custom CSS classes
  • :z_index - Stacking order
  • :handles - List of LiveFlow.Handle structs
  • :measured - Whether dimensions have been measured

Examples

iex> LiveFlow.Node.new("node-1", %{x: 100, y: 100}, %{label: "Start"})
%LiveFlow.Node{id: "node-1", position: %{x: 100, y: 100}, data: %{label: "Start"}}

iex> LiveFlow.Node.new("node-2", %{x: 200, y: 150}, %{}, type: :input)
%LiveFlow.Node{id: "node-2", type: :input, position: %{x: 200, y: 150}}

Summary

Functions

Adds a handle to the node.

Gets the bounding box of the node.

Gets the center point of the node.

Checks if a point is inside the node's bounds.

Moves a node to a new position.

Moves a node by a delta offset.

Creates a new node with the given id, position, and data.

Sets the node's selected state.

Sets the node's dimensions after measurement.

Sets the node's dragging state.

Updates a node with the given attributes.

Types

t()

@type t() :: %LiveFlow.Node{
  class: String.t() | nil,
  connectable: boolean(),
  data: map(),
  deletable: boolean(),
  draggable: boolean(),
  dragging: boolean(),
  extent: :parent | map() | nil,
  handles: [LiveFlow.Handle.t()],
  height: number() | nil,
  hidden: boolean(),
  id: String.t(),
  measured: boolean(),
  parent_id: String.t() | nil,
  position: %{x: number(), y: number()},
  resizing: boolean(),
  selectable: boolean(),
  selected: boolean(),
  style: map(),
  type: atom(),
  width: number() | nil,
  z_index: integer()
}

Functions

add_handle(node, handle)

@spec add_handle(t(), LiveFlow.Handle.t()) :: t()

Adds a handle to the node.

bounds(node)

@spec bounds(t()) :: map() | nil

Gets the bounding box of the node.

Returns nil if the node hasn't been measured yet.

center(node)

@spec center(t()) :: map() | nil

Gets the center point of the node.

Returns nil if the node hasn't been measured yet.

contains_point?(node, x, y)

@spec contains_point?(t(), number(), number()) :: boolean()

Checks if a point is inside the node's bounds.

move(node, position)

@spec move(t(), map()) :: t()

Moves a node to a new position.

Examples

iex> node = LiveFlow.Node.new("1", %{x: 0, y: 0}, %{})
iex> LiveFlow.Node.move(node, %{x: 50, y: 50})
%LiveFlow.Node{id: "1", position: %{x: 50.0, y: 50.0}}

move_by(node, dx, dy)

@spec move_by(t(), number(), number()) :: t()

Moves a node by a delta offset.

Examples

iex> node = LiveFlow.Node.new("1", %{x: 100, y: 100}, %{})
iex> LiveFlow.Node.move_by(node, 10, -20)
%LiveFlow.Node{id: "1", position: %{x: 110.0, y: 80.0}}

new(id, position, data \\ %{}, opts \\ [])

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

Creates a new node with the given id, position, and data.

Options

  • :type - Node type (default: :default)
  • :draggable - Whether draggable (default: true)
  • :connectable - Whether connectable (default: true)
  • :selectable - Whether selectable (default: true)
  • :deletable - Whether deletable (default: true)
  • :parent_id - Parent node ID for grouping
  • :extent - Movement constraint
  • :style - Custom inline styles
  • :class - Custom CSS classes
  • :z_index - Stacking order (default: 0)
  • :handles - List of handles (default: [])

Examples

iex> LiveFlow.Node.new("1", %{x: 0, y: 0}, %{label: "Hello"})
%LiveFlow.Node{id: "1", position: %{x: 0, y: 0}, data: %{label: "Hello"}}

iex> LiveFlow.Node.new("2", %{x: 100, y: 100}, %{}, type: :input, draggable: false)
%LiveFlow.Node{id: "2", type: :input, position: %{x: 100, y: 100}, draggable: false}

select(node, selected \\ true)

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

Sets the node's selected state.

set_dimensions(node, width, height)

@spec set_dimensions(t(), number(), number()) :: t()

Sets the node's dimensions after measurement.

set_dragging(node, dragging)

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

Sets the node's dragging state.

update(node, attrs)

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

Updates a node with the given attributes.

Examples

iex> node = LiveFlow.Node.new("1", %{x: 0, y: 0}, %{})
iex> LiveFlow.Node.update(node, position: %{x: 100, y: 100})
%LiveFlow.Node{id: "1", position: %{x: 100.0, y: 100.0}}