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 (:parentor bounds map):style- Custom inline styles map:class- Custom CSS classes:z_index- Stacking order:handles- List ofLiveFlow.Handlestructs: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
@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
@spec add_handle(t(), LiveFlow.Handle.t()) :: t()
Adds a handle to the node.
Gets the bounding box of the node.
Returns nil if the node hasn't been measured yet.
Gets the center point of the node.
Returns nil if the node hasn't been measured yet.
Checks if a point is inside the node's bounds.
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}}
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}}
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}
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.
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}}