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

Function emit_html

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

Generate a self-contained HTML page with a D3.js force-directed graph.

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

Source from the content-addressed store, hash-verified

620
621/// Generate a self-contained HTML page with a D3.js force-directed graph.
622fn emit_html(query: &str, nodes: &[KgNode], edges: &[KgEdge]) -> String {
623 // Build JSON data for embedding
624 let graph_nodes: Vec<serde_json::Value> = nodes
625 .iter()
626 .map(|n| {
627 let content_matches = n
628 .metadata
629 .as_ref()
630 .and_then(|m| m.get("content_matches"))
631 .and_then(|v| v.as_u64())
632 .unwrap_or(0);
633 let entity_kind = n
634 .metadata
635 .as_ref()
636 .and_then(|m| m.get("kind"))
637 .and_then(|v| v.as_str())
638 .unwrap_or("");
639 let line = n
640 .metadata
641 .as_ref()
642 .and_then(|m| m.get("line"))
643 .and_then(|v| v.as_u64())
644 .unwrap_or(0);
645 let end_line = n
646 .metadata
647 .as_ref()
648 .and_then(|m| m.get("end_line"))
649 .and_then(|v| v.as_u64())
650 .unwrap_or(0);
651 serde_json::json!({
652 "id": n.id,
653 "kind": n.kind,
654 "label": n.label,
655 "summary": n.summary.as_deref().unwrap_or(""),
656 "content_matches": content_matches,
657 "entity_kind": entity_kind,
658 "line": line,
659 "end_line": end_line,
660 })
661 })
662 .collect();
663
664 let graph_edges: Vec<serde_json::Value> = edges
665 .iter()
666 .map(|e| {
667 serde_json::json!({
668 "source": e.from_id,
669 "target": e.to_id,
670 "kind": e.kind,
671 })
672 })
673 .collect();
674
675 let graph_data = serde_json::json!({
676 "nodes": graph_nodes,
677 "links": graph_edges,
678 });
679

Callers 1

runMethod · 0.85

Calls 7

as_refMethod · 0.80
as_u64Method · 0.80
getMethod · 0.65
iterMethod · 0.45
as_strMethod · 0.45
unwrapMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected