Version: dev

to_dot

Stable function · Graphs

Tier: stable · Kind: function · Topic: Graphs

JuliaTypeScriptPythonRustGo
to_dottoDotto_dotto_dotToDOT

Julia

to_dot(graph::Graph{ComponentNode, CouplingEdge})
to_dot(graph::Graph{VariableNode, DependencyEdge})

Export graph to DOT format for Graphviz rendering.

Source

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")

From docs/api/examples/julia/coupling.jl

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.

Source

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"/)

From docs/api/examples/typescript/component_graph.ts

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).

Source

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.

Source · Rust docs

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"));

From docs/api/examples/rust/graphs.rs

Go

func ToDOT(g Graph) (string, error)

ToDOT renders a graph in DOT (Graphviz) format.

Canonical to_dot (API_SPEC.md §8 item 8). It accepts a *ComponentGraph or an *ExpressionGraph; the emitted text is pinned across bindings by tests/conformance/graph/cases.json.

Source · Go docs