pub struct Graph<N = (), E = ()> { /* private fields */ }Expand description
Graph container for nodes and edges
Implementations§
Source§impl<N, E> Graph<N, E>
impl<N, E> Graph<N, E>
Sourcepub fn apply_node_drag(
&mut self,
selected_nodes: &HashSet<NodeId>,
delta: Position,
) -> Result<()>
pub fn apply_node_drag( &mut self, selected_nodes: &HashSet<NodeId>, delta: Position, ) -> Result<()>
Apply drag operation to selected nodes
Sourcepub fn apply_node_drag_with_bounds(
&mut self,
selected_nodes: &HashSet<NodeId>,
delta: Position,
bounds: Option<Rect>,
) -> Result<()>
pub fn apply_node_drag_with_bounds( &mut self, selected_nodes: &HashSet<NodeId>, delta: Position, bounds: Option<Rect>, ) -> Result<()>
Apply drag operation with bounds constraint
Sourcepub fn apply_node_drag_with_snap(
&mut self,
selected_nodes: &HashSet<NodeId>,
delta: Position,
grid_size: f64,
) -> Result<()>
pub fn apply_node_drag_with_snap( &mut self, selected_nodes: &HashSet<NodeId>, delta: Position, grid_size: f64, ) -> Result<()>
Apply drag operation with grid snapping
Sourcepub fn apply_node_drag_with_constraint<F>(
&mut self,
selected_nodes: &HashSet<NodeId>,
delta: Position,
constraint: F,
) -> Result<()>
pub fn apply_node_drag_with_constraint<F>( &mut self, selected_nodes: &HashSet<NodeId>, delta: Position, constraint: F, ) -> Result<()>
Apply drag operation with custom constraint function
Sourcepub fn create_drag_operation(
&self,
selected_nodes: &HashSet<NodeId>,
delta: Position,
) -> Result<DragOperation>
pub fn create_drag_operation( &self, selected_nodes: &HashSet<NodeId>, delta: Position, ) -> Result<DragOperation>
Create a drag operation for undo/redo support
Source§impl<N, E> Graph<N, E>
impl<N, E> Graph<N, E>
Sourcepub fn has_cycle(&self) -> bool
pub fn has_cycle(&self) -> bool
Check if the graph contains any cycles using DFS-based cycle detection
Uses Depth-First Search with recursion stack tracking to detect back edges. Time complexity: O(V + E), Space complexity: O(V)
Sourcepub fn creates_cycle(&self, source: &NodeId, target: &NodeId) -> bool
pub fn creates_cycle(&self, source: &NodeId, target: &NodeId) -> bool
Check if adding an edge from source to target would create a cycle
This is useful for preventing cycles during interactive edge creation. Time complexity: O(V + E), Space complexity: O(V)
Sourcepub fn find_cycle(&self) -> Option<Vec<NodeId>>
pub fn find_cycle(&self) -> Option<Vec<NodeId>>
Find a cycle in the graph, returning the cycle path if found
Returns the first cycle found, or None if the graph is acyclic. The returned path represents the nodes in the cycle. Time complexity: O(V + E), Space complexity: O(V)
Sourcepub fn topological_sort(&self) -> Result<Vec<NodeId>>
pub fn topological_sort(&self) -> Result<Vec<NodeId>>
Perform topological sort on the graph using Kahn’s algorithm
Returns a valid topological ordering of nodes, or Err if the graph contains cycles. A topological sort is a linear ordering where for every directed edge (u, v), vertex u comes before v in the ordering. Time complexity: O(V + E), Space complexity: O(V)
Source§impl<N, E> Graph<N, E>
impl<N, E> Graph<N, E>
Sourcepub fn add_handle_edge(&mut self, edge: Edge<E>) -> Result<()>
pub fn add_handle_edge(&mut self, edge: Edge<E>) -> Result<()>
Add an edge with handle validation
Sourcepub fn get_handle_connections(
&self,
node_id: &NodeId,
handle_id: &HandleId,
) -> Vec<&Edge<E>>
pub fn get_handle_connections( &self, node_id: &NodeId, handle_id: &HandleId, ) -> Vec<&Edge<E>>
Get all edges connected to a specific handle
This method provides accurate connection counting by examining all edges in the graph that reference the specified handle.
Sourcepub fn can_handle_accept_connection(
&self,
node_id: &NodeId,
handle_id: &HandleId,
) -> bool
pub fn can_handle_accept_connection( &self, node_id: &NodeId, handle_id: &HandleId, ) -> bool
Check if a handle can accept new connections (respects connection limits)
This method provides accurate connection limit validation by counting current connections and comparing against the handle’s limit.
Source§impl<N, E> Graph<N, E>
impl<N, E> Graph<N, E>
Sourcepub fn remove_node(&mut self, node_id: &NodeId) -> Result<Node<N>>
pub fn remove_node(&mut self, node_id: &NodeId) -> Result<Node<N>>
Remove a node and all connected edges
Sourcepub fn get_node_mut(&mut self, node_id: &NodeId) -> Option<&mut Node<N>>
pub fn get_node_mut(&mut self, node_id: &NodeId) -> Option<&mut Node<N>>
Get a mutable reference to a node
Sourcepub fn remove_edge(&mut self, edge_id: &EdgeId) -> Result<Edge<E>>
pub fn remove_edge(&mut self, edge_id: &EdgeId) -> Result<Edge<E>>
Remove an edge
Sourcepub fn get_edge_mut(&mut self, edge_id: &EdgeId) -> Option<&mut Edge<E>>
pub fn get_edge_mut(&mut self, edge_id: &EdgeId) -> Option<&mut Edge<E>>
Get a mutable reference to an edge
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Get node count
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
Get edge count
Sourcepub fn get_connected_edges(&self, node_id: &NodeId) -> Vec<&Edge<E>>
pub fn get_connected_edges(&self, node_id: &NodeId) -> Vec<&Edge<E>>
Get edges connected to a node
Sourcepub fn get_incoming_edges(&self, node_id: &NodeId) -> Vec<&Edge<E>>
pub fn get_incoming_edges(&self, node_id: &NodeId) -> Vec<&Edge<E>>
Get incoming edges for a node
Sourcepub fn get_outgoing_edges(&self, node_id: &NodeId) -> Vec<&Edge<E>>
pub fn get_outgoing_edges(&self, node_id: &NodeId) -> Vec<&Edge<E>>
Get outgoing edges for a node
Sourcepub fn are_connected(&self, source: &NodeId, target: &NodeId) -> bool
pub fn are_connected(&self, source: &NodeId, target: &NodeId) -> bool
Check if two nodes are connected
Sourcepub fn handle_at_position(
&self,
point: Position,
handle_size: f64,
) -> Option<(&NodeId, &Handle)>
pub fn handle_at_position( &self, point: Position, handle_size: f64, ) -> Option<(&NodeId, &Handle)>
Find handle at position in the graph
Sourcepub fn get_handles_by_type(
&self,
handle_type: HandleType,
) -> Vec<(&NodeId, &Handle)>
pub fn get_handles_by_type( &self, handle_type: HandleType, ) -> Vec<(&NodeId, &Handle)>
Get all handles of a specific type in the graph
Sourcepub fn create_edge_creator(&self) -> EdgeCreator
pub fn create_edge_creator(&self) -> EdgeCreator
Create a new edge creator for this graph