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

Function emit_html

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

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

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