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, connections, and annotations
  3. Sets the viewport to match the saved state
  4. Sets up visual positioning and hit-testing infrastructure

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, annotations, and viewport state

Example:

final graph = NodeGraph<MyData>(
  nodes: savedNodes,
  connections: savedConnections,
  annotations: savedAnnotations,
  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);
    for (final annotation in graph.annotations) {
      annotations.annotations[annotation.id] = annotation;
    }

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

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