to_dot
Stable function · Graphs
Tier: stable · Kind: function · Topic: Graphs
| Julia | TypeScript | Python | Rust | Go |
|---|---|---|---|---|
to_dot | toDot | to_dot | to_dot | ToDOT |
Julia
to_dot(graph::Graph{ComponentNode, CouplingEdge})
to_dot(graph::Graph{VariableNode, DependencyEdge})
Export graph to DOT format for Graphviz rendering.
Example (component_graph)
graph = component_graph(doc)
@assert [n.name for n in graph.nodes] == ["Heater", "Box"]
mermaid = to_mermaid(graph)
println(mermaid)
@assert occursin("Heater -.->|\"T\"| Box", mermaid)
@assert startswith(to_dot(graph), "digraph")
TypeScript
function toDot<N extends object, E>(graph: Graph<N, E>): string
Export graph as Graphviz DOT format. Node shapes: box for models and reaction systems, diamond for operators. Edge styles: solid for compose, dashed for variable_map.
The header NAMES the graph — digraph ComponentGraph / digraph ExpressionGraph. §4.8.3 requires a DOT export and specifies no syntax for it,
so the cross-binding tie-break is the majority: Python, Go, Rust and Julia all
emitted the named form and this binding alone emitted a bare digraph {.
tests/conformance/graph/cases.json pins it.
Example (component_graph)
const doc = loadPath(fixture('coupled.esm'))
const graph = componentGraph(doc)
assert.deepEqual(graph.nodes.map((n) => n.id), ['Heater', 'Box'])
assert.deepEqual(graph.successors('Heater'), ['Box'])
const [edge] = graph.edges
assert.equal(edge.data.type, 'variable_map')
// Render for a Markdown page or for Graphviz.
const mermaid = toMermaid(graph)
assert.match(mermaid, /Heater -\.->\|T\| Box/)
assert.match(toDot(graph), /"Heater" -> "Box"/)
Python
to_dot(graph: Graph[Any, Any]) -> str
Render graph as Graphviz DOT.
Component nodes are coloured by type and coupling edges by kind; variable
nodes are shaped by their derived kind and dependency edges styled by
relationship. The digraph ComponentGraph / digraph ExpressionGraph
headers are what Julia, Rust and Go all emit (TypeScript writes a bare
digraph).
Rust
pub fn to_dot<G: Graph>(graph: &G) -> String
Render graph as Graphviz DOT (esm-libraries-spec §4.8.3).
The canonical free-function spelling (API_SPEC.md §8 item 8). Equivalent to
the graph’s own to_dot method; the byte-level output is pinned by
tests/conformance/graph/cases.json.
Example (component_graph)
let doc = load_path(fixture("coupled.esm"))?;
let graph = component_graph(&doc);
let ids: Vec<&str> = graph.nodes.iter().map(|n| n.id.as_str()).collect();
assert_eq!(ids, ["Box", "Heater"]);
assert_eq!(graph.edges.len(), 1);
assert_eq!((graph.edges[0].from.as_str(), graph.edges[0].to.as_str()), ("Heater", "Box"));
let dot = to_dot(&graph);
assert!(dot.starts_with("digraph"));
assert!(to_mermaid(&graph).contains("Heater"));