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

Function emit_html

atomic-cli/src/commands/query/mod.rs:683–1148  ·  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

681
682/// Generate a self-contained HTML page with a D3.js force-directed graph.
683pub(crate) fn emit_html(query: &str, nodes: &[KgNode], edges: &[KgEdge]) -> String {
684 // Build JSON data for embedding
685 let graph_nodes: Vec<serde_json::Value> = nodes
686 .iter()
687 .map(|n| {
688 let content_matches = n
689 .metadata
690 .as_ref()
691 .and_then(|m| m.get("content_matches"))
692 .and_then(|v| v.as_u64())
693 .unwrap_or(0);
694 let entity_kind = n
695 .metadata
696 .as_ref()
697 .and_then(|m| m.get("kind"))
698 .and_then(|v| v.as_str())
699 .unwrap_or("");
700 let line = n
701 .metadata
702 .as_ref()
703 .and_then(|m| m.get("line"))
704 .and_then(|v| v.as_u64())
705 .unwrap_or(0);
706 let end_line = n
707 .metadata
708 .as_ref()
709 .and_then(|m| m.get("end_line"))
710 .and_then(|v| v.as_u64())
711 .unwrap_or(0);
712 serde_json::json!({
713 "id": n.id,
714 "kind": n.primary_type(),
715 "color": html_node_color(n.primary_type()),
716 "types": n.types,
717 "label": n.label,
718 "summary": n.summary.as_deref().unwrap_or(""),
719 "source": n.source,
720 "metadata": n.metadata,
721 "content_matches": content_matches,
722 "entity_kind": entity_kind,
723 "line": line,
724 "end_line": end_line,
725 })
726 })
727 .collect();
728
729 let graph_edges: Vec<serde_json::Value> = edges
730 .iter()
731 .map(|e| {
732 serde_json::json!({
733 "source": e.from_id,
734 "target": e.to_id,
735 "kind": e.kind,
736 "metadata": e.metadata,
737 })
738 })
739 .collect();
740

Callers 4

query_graphFunction · 0.85
runMethod · 0.85
runMethod · 0.85

Calls 8

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