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

Function emit_dot

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

Generate a DOT (Graphviz) representation of a subgraph.

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

Source from the content-addressed store, hash-verified

494
495/// Generate a DOT (Graphviz) representation of a subgraph.
496fn emit_dot(nodes: &[KgNode], edges: &[KgEdge]) -> String {
497 let mut out = String::new();
498 out.push_str("digraph query {\n");
499 out.push_str(" rankdir=LR;\n");
500 out.push_str(
501 " node [shape=box, style=\"filled,rounded\", fontname=\"Helvetica\", fontsize=10];\n",
502 );
503 out.push_str(" edge [fontname=\"Helvetica\", fontsize=8, color=\"#888888\"];\n");
504 out.push('\n');
505
506 // Nodes
507 for node in nodes {
508 let (fillcolor, shape) = node_style(&node.kind);
509 let label = node_label(node);
510 out.push_str(&format!(
511 " \"{}\" [label=\"{}\", fillcolor=\"{}\", shape={}];\n",
512 dot_escape_id(&node.id),
513 dot_escape_label(&label),
514 fillcolor,
515 shape,
516 ));
517 }
518
519 out.push('\n');
520
521 // Edges
522 for edge in edges {
523 out.push_str(&format!(
524 " \"{}\" -> \"{}\" [label=\"{}\"];\n",
525 dot_escape_id(&edge.from_id),
526 dot_escape_id(&edge.to_id),
527 dot_escape_label(&edge.kind),
528 ));
529 }
530
531 out.push_str("}\n");
532 out
533}
534
535/// Returns `(fillcolor, shape)` for a given node kind.
536fn node_style(kind: &str) -> (&'static str, &'static str) {

Callers 1

runMethod · 0.85

Calls 3

node_styleFunction · 0.85
node_labelFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected