MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / emit_dot

Function emit_dot

atomic-cli/src/commands/query/mod.rs:511–548  ·  view source on GitHub ↗

Generate a DOT (Graphviz) representation of a subgraph.

(nodes: &[KgNode], edges: &[KgEdge])

Source from the content-addressed store, hash-verified

509
510/// Generate a DOT (Graphviz) representation of a subgraph.
511pub(crate) fn emit_dot(nodes: &[KgNode], edges: &[KgEdge]) -> String {
512 let mut out = String::new();
513 out.push_str("digraph query {\n");
514 out.push_str(" rankdir=LR;\n");
515 out.push_str(
516 " node [shape=box, style=\"filled,rounded\", fontname=\"Helvetica\", fontsize=10];\n",
517 );
518 out.push_str(" edge [fontname=\"Helvetica\", fontsize=8, color=\"#888888\"];\n");
519 out.push('\n');
520
521 // Nodes
522 for node in nodes {
523 let (fillcolor, shape) = node_style(node.primary_type());
524 let label = node_label(node);
525 out.push_str(&format!(
526 " \"{}\" [label=\"{}\", fillcolor=\"{}\", shape={}];\n",
527 dot_escape_id(&node.id),
528 dot_escape_label(&label),
529 fillcolor,
530 shape,
531 ));
532 }
533
534 out.push('\n');
535
536 // Edges
537 for edge in edges {
538 out.push_str(&format!(
539 " \"{}\" -> \"{}\" [label=\"{}\"];\n",
540 dot_escape_id(&edge.from_id),
541 dot_escape_id(&edge.to_id),
542 dot_escape_label(&compact(edge.kind.iri())),
543 ));
544 }
545
546 out.push_str("}\n");
547 out
548}
549
550/// Returns `(fillcolor, shape)` for a given node kind.
551fn node_style(kind: &str) -> (&'static str, &'static str) {

Callers 3

query_graphFunction · 0.85
runMethod · 0.85
runMethod · 0.85

Calls 4

node_styleFunction · 0.85
node_labelFunction · 0.85
primary_typeMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected