to_html()
Render a knowledge graph as an interactive HTML page.
Usage
to_html(
kg,
*,
max_nodes=200,
node_type=None,
color_by="type",
title="Knowledge Graph"
)Generates a self-contained HTML file with an SVG-based force-directed graph layout. No external JavaScript dependencies are required.
Parameters
kg: KnowledgeGraph-
The knowledge graph to render.
max_nodes: int = 200-
Maximum nodes to include.
node_type: NodeType | None = None-
If provided, only include nodes of this type.
color_by: str = "type"-
Color scheme:
"type"or"freshness". title: str = "Knowledge Graph"- Page title.
Returns
str- Complete HTML document as a string.
Examples
import talk_box as tb
kg = tb.KnowledgeGraph(":memory:")
# ... add nodes ...
html_str = tb.to_html(kg, color_by="freshness")