component_graph (type)
Stable type · Graphs
Tier: stable · Kind: type · Topic: Graphs
| Julia | TypeScript | Python | Rust | Go |
|---|---|---|---|---|
| not exported | ComponentGraph | not exported | ComponentGraph | ComponentGraph |
Julia
Julia does not export this type.
TypeScript
interface ComponentGraph {
nodes: ComponentNode[];
edges: CouplingEdge[];
}
System graph representation with components and couplings
Properties
nodes— All components in the systemedges— All coupling relationships
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
Python does not export this type.
Rust
pub struct ComponentGraph {
pub nodes: Vec<ComponentNode>,
pub edges: Vec<CouplingEdge>,
}
impl ComponentGraph { pub fn adjacency(&self, id: &str) -> Vec<String> }
impl ComponentGraph { pub fn predecessors(&self, id: &str) -> Vec<String> }
impl ComponentGraph { pub fn successors(&self, id: &str) -> Vec<String> }
impl ComponentGraph { pub fn to_dot(&self) -> String }
impl ComponentGraph { pub fn to_mermaid(&self) -> String }
impl ComponentGraph { pub fn to_json_graph(&self) -> String }
Component graph representing model structure
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"));
Go
type ComponentGraph struct {
Nodes []ComponentNode `json:"nodes"`
Edges []GraphEdge[ComponentNode, CouplingEdge] `json:"edges"`
}
func (g *ComponentGraph) Adjacency(node ComponentNode) []ComponentAdjacency
func (g *ComponentGraph) Predecessors(node ComponentNode) []ComponentNode
func (g *ComponentGraph) Successors(node ComponentNode) []ComponentNode
ComponentGraph is a specialized graph for system components
Methods
func (g *ComponentGraph) Adjacency(node ComponentNode) []ComponentAdjacency
Adjacency returns the neighbours of a node in the component graph, together with the coupling edge that reaches each (esm-libraries-spec §4.8.3). Adjacency is UNDIRECTED: an edge in either direction makes its other endpoint a neighbour, regardless of whether the coupling is bidirectional. One entry is returned per incident edge.
func (g *ComponentGraph) Predecessors(node ComponentNode) []ComponentNode
Predecessors returns the distinct nodes with an edge pointing TO the given node, in sorted-ID order. A bidirectional coupling is still one DIRECTED edge: its Bidirectional flag styles the export, it does not add a reverse dependency.
func (g *ComponentGraph) Successors(node ComponentNode) []ComponentNode
Successors returns the distinct nodes the given node has an edge pointing TO, in sorted-ID order.