loadGraph method

void loadGraph(
  1. NodeGraph<T> graph
)

Loads a complete graph into the controller.

This method:

  1. Clears the existing graph state
  2. Bulk loads all nodes and connections
  3. Sets the viewport to match the saved state
  4. Sets up visual positioning and hit-testing infrastructure
  5. Sets up node monitoring for GroupNode and CommentNode

This is the preferred method for loading saved graphs as it performs efficient bulk loading rather than individual additions.

Parameters:

  • graph: The graph to load containing nodes, connections, and viewport state

Example:

final graph = NodeGraph<MyData>(
  nodes: savedNodes,
  connections: savedConnections,
  viewport: savedViewport,
);
controller.loadGraph(graph);

Implementation

void loadGraph(NodeGraph<T> graph) {
  runInAction(() {
    // Clear existing state
    clearGraph();

    // Bulk load all data structures without infrastructure setup
    for (final node in graph.nodes) {
      _nodes[node.id] = node;
    }
    _connections.addAll(graph.connections);

    // Set viewport
    _viewport.value = graph.viewport;

    // Single infrastructure setup call after bulk loading
    _setupLoadedGraphInfrastructure();
  });
}