Main state container for LiveFlow.
The state holds all nodes, edges, viewport information, and selection state. It provides CRUD operations for nodes and edges, as well as selection management.
Fields
:nodes- Map of node ID toLiveFlow.Nodestructs:edges- Map of edge ID toLiveFlow.Edgestructs:viewport- CurrentLiveFlow.Viewportstate:selected_nodes- Set of selected node IDs:selected_edges- Set of selected edge IDs
Examples
iex> state = LiveFlow.State.new()
iex> node = LiveFlow.Node.new("1", %{x: 0, y: 0}, %{label: "Start"})
iex> state = LiveFlow.State.add_node(state, node)
iex> Map.keys(state.nodes)
["1"]
Summary
Functions
Adds an edge to the state.
Adds multiple edges to the state.
Adds a node to the state.
Adds multiple nodes to the state.
Calculates bounds of all nodes.
Clears all selection (nodes and edges).
Deletes all selected nodes and edges.
Deselects a node by ID.
Checks if an edge already exists between two nodes.
Gets all edges connected to a node.
Gets all edges as a list.
Gets an edge by ID.
Gets a node by ID.
Creates a new empty state.
Gets all nodes as a list.
Removes an edge by ID.
Removes multiple edges by ID.
Removes a node by ID. Also removes all edges connected to this node.
Removes multiple nodes by ID.
Selects all nodes and edges.
Selects an edge by ID.
Selects a node by ID.
Selects multiple nodes by ID.
Gets all selected edges.
Gets all selected nodes.
Sets the viewport.
Updates an edge by ID with the given attributes.
Updates a node by ID with the given attributes or function.
Updates the viewport with the given values.
Types
@type t() :: %LiveFlow.State{ edges: %{required(String.t()) => LiveFlow.Edge.t()}, nodes: %{required(String.t()) => LiveFlow.Node.t()}, selected_edges: MapSet.t(String.t()), selected_nodes: MapSet.t(String.t()), viewport: LiveFlow.Viewport.t() }
Functions
@spec add_edge(t(), LiveFlow.Edge.t()) :: t()
Adds an edge to the state.
@spec add_edges(t(), [LiveFlow.Edge.t()]) :: t()
Adds multiple edges to the state.
@spec add_node(t(), LiveFlow.Node.t()) :: t()
Adds a node to the state.
@spec add_nodes(t(), [LiveFlow.Node.t()]) :: t()
Adds multiple nodes to the state.
Calculates bounds of all nodes.
Clears all selection (nodes and edges).
Deletes all selected nodes and edges.
Deselects a node by ID.
Checks if an edge already exists between two nodes.
@spec edges_for_node(t(), String.t()) :: [LiveFlow.Edge.t()]
Gets all edges connected to a node.
@spec edges_list(t()) :: [LiveFlow.Edge.t()]
Gets all edges as a list.
@spec get_edge(t(), String.t()) :: LiveFlow.Edge.t() | nil
Gets an edge by ID.
@spec get_node(t(), String.t()) :: LiveFlow.Node.t() | nil
Gets a node by ID.
Creates a new empty state.
Options
:nodes- Initial nodes (list or map):edges- Initial edges (list or map):viewport- Initial viewport
Examples
iex> LiveFlow.State.new()
%LiveFlow.State{nodes: %{}, edges: %{}}
iex> nodes = [LiveFlow.Node.new("1", %{x: 0, y: 0}, %{})]
iex> state = LiveFlow.State.new(nodes: nodes)
iex> Map.keys(state.nodes)
["1"]
@spec nodes_list(t()) :: [LiveFlow.Node.t()]
Gets all nodes as a list.
Removes an edge by ID.
Removes multiple edges by ID.
Removes a node by ID. Also removes all edges connected to this node.
Removes multiple nodes by ID.
Selects all nodes and edges.
Selects an edge by ID.
Selects a node by ID.
Options
:multi- If true, adds to selection. If false, replaces selection (default:false)
Selects multiple nodes by ID.
@spec selected_edges_list(t()) :: [LiveFlow.Edge.t()]
Gets all selected edges.
@spec selected_nodes_list(t()) :: [LiveFlow.Node.t()]
Gets all selected nodes.
@spec set_viewport(t(), LiveFlow.Viewport.t()) :: t()
Sets the viewport.
Updates an edge by ID with the given attributes.
@spec update_node( t(), String.t(), keyword() | (LiveFlow.Node.t() -> LiveFlow.Node.t()) ) :: t()
Updates a node by ID with the given attributes or function.
When passed a keyword list, updates the node with those attributes. When passed a function, applies the function to the node.
Updates the viewport with the given values.