loadGraph method
Loads a complete graph into the controller.
This method:
- Clears the existing graph state
- Bulk loads all nodes, connections, and annotations
- Sets the viewport to match the saved state
- 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();
});
}