cognis_graph/viz/mod.rs
1//! Render compiled graphs as Mermaid, GraphViz DOT, or ASCII diagrams
2//! for docs / debugging.
3
4pub mod ascii;
5pub mod dot;
6pub mod mermaid;
7
8use std::collections::BTreeSet;
9
10use crate::compiled::CompiledGraph;
11use crate::state::GraphState;
12
13/// A static-route edge `(from, to)`. Dynamic routing via `Goto::Send` /
14/// `Goto::Multiple` only surfaces what the node *can* go to if the graph
15/// builder declared it via [`crate::builder::Graph::edge`].
16#[derive(Debug, Clone, PartialEq, Eq, Ord, PartialOrd)]
17pub struct Edge {
18 /// Source node name.
19 pub from: String,
20 /// Destination node name (or `__END__`).
21 pub to: String,
22}
23
24/// Extract the static edges declared on the graph (via `edge(from, to)`).
25/// Used by both renderers.
26pub(crate) fn extract_edges<S: GraphState>(g: &CompiledGraph<S>) -> Vec<Edge> {
27 let mut set: BTreeSet<Edge> = BTreeSet::new();
28 for (from, to) in &g.graph.edges {
29 set.insert(Edge {
30 from: from.clone(),
31 to: to.clone(),
32 });
33 }
34 set.into_iter().collect()
35}