import type { DataOptions } from '../algorithm/types'; import { GraphLib } from '../model/data'; import type { EdgeData, Graph, GraphData, GraphEdge, GraphNode, NodeData, } from '../types'; export class RuntimeContext< N extends NodeData = NodeData, E extends EdgeData = EdgeData, > { public readonly graph: GraphLib; constructor(data: GraphData, options: DataOptions = {}) { this.graph = new GraphLib(data, options); } public export(): Graph { return this.graph.data(); } public replace(result: Graph): void { this.graph.replace(result); } public forEachNode( callback: (node: GraphNode, index: number) => void, ): void { this.graph.forEachNode(callback); } public forEachEdge( callback: (edge: GraphEdge, index: number) => void, ): void { this.graph.forEachEdge((edge, i) => { edge.sourceNode = this.graph.node(edge.source); edge.targetNode = this.graph.node(edge.target); callback(edge, i); }); } public destroy(): void { this.graph.destroy(); } }