( graph: Graph<N, E, "undirected"> | MutableGraph<N, E, "undirected"> )
| 2922 | ): string => { |
| 2923 | const impl = graphImpl(graph) |
| 2924 | const { |
| 2925 | edgeLabel = (data: E) => String(data), |
| 2926 | graphName = "G", |
| 2927 | nodeLabel = (data: N) => String(data) |
| 2928 | } = options ?? {} |
| 2929 | |
| 2930 | const isDirected = graph.type === "directed" |
| 2931 | const graphType = isDirected ? "digraph" : "graph" |
| 2932 | const edgeOperator = isDirected ? "->" : "--" |
| 2933 | const graphId = `"${escapeGraphVizString(graphName)}"` |
| 2934 | |
| 2935 | const lines: Array<string> = [] |
| 2936 | lines.push(`${graphType} ${graphId} {`) |
| 2937 | |
| 2938 | // Add nodes |
| 2939 | for (const [nodeIndex, nodeData] of impl.nodes) { |
| 2940 | const label = escapeGraphVizString(nodeLabel(nodeData)) |
| 2941 | lines.push(` "${nodeIndex}" [label="${label}"];`) |
| 2942 | } |
| 2943 | |
| 2944 | // Add edges |
| 2945 | for (const [, edgeData] of impl.edges) { |
| 2946 | const label = escapeGraphVizString(edgeLabel(edgeData.data)) |
| 2947 | lines.push(` "${edgeData.source}" ${edgeOperator} "${edgeData.target}" [label="${label}"];`) |
| 2948 | } |
| 2949 | |
| 2950 | lines.push("}") |
| 2951 | return lines.join("\n") |
| 2952 | }) |
| 2953 | |
| 2954 | // ============================================================================= |
| 2955 | // Mermaid Export |
| 2956 | // ============================================================================= |
| 2957 | |
| 2958 | /** |
| 2959 | * Mermaid node shape types for diagram visualization. |
nothing calls this directly
no test coverage detected
searching dependent graphs…