srdatalog.viz.html¶
Render a Program as a self-contained HTML iframe for notebook cells.
The renderer (TS / React, built from harp-lab/srdatalog-viz) lives as
a static asset under srdatalog/viz/static/. We embed it inline in
an <iframe srcdoc=...> so each cell gets DOM isolation: no
document.getElementById('root') collision between cells, no shared
React tree, no leaking state.
Inside the iframe we:
Stub
window.vscodeso the renderer’s postMessage calls no-op (the renderer was built for VS Code webviews; we don’t have a bidirectional channel from a Jupyter cell)Load the bundle JS + CSS (inlined as data; no external fetch)
After the React app mounts, dispatch a
messageevent carrying asetRulesetcommand so the ruleset overview graph populates
The bundle expects HIR JSON in the same shape srdatalog.hir.emit.hir_to_obj
emits — which by design byte-matches the Nim emit, so the same
renderer serves both ports.
Module Contents¶
Functions¶
Return a |
API¶
- srdatalog.viz.html.program_to_html(program: srdatalog.dsl.Program, *, rule_name: str | None = None, delta: int | None = None, theme: str = 'dark', height_px: int = 600, include_jit: bool = True) str[source]¶
Return a
<iframe srcdoc=...>HTML string that rendersprogram.The iframe is self-contained — no external network fetches, no reliance on labextensions. Drop it into any notebook cell output (Jupyter Lab, classic Notebook, VS Code Jupyter, Colab) and the renderer mounts.
Args: program: the Program to visualize. rule_name: when None, render the ruleset overview (all rules, stratum-grouped). When a string, drill into that one rule’s plan view — shows variant access patterns, clause order, var order with drag-to-reorder. delta: only meaningful with
rule_name. When None (default), shows every variant of the rule (one per delta seed for recursive rules — semi-naive evaluation produces N variants for N body clauses). When an int, filters to just that variant (delta=0 means “delta seeded on body clause 0”). Use to look at one specific version of a rule in isolation. theme: ‘dark’ (default), ‘light’, or ‘high-contrast’. Maps to the renderer’s setTheme message. height_px: iframe height. Default 600px works for most rulesets; bump for larger ones. include_jit: include per-rule JIT C++ kernels in the bundle. The renderer shows them under the JIT tab. Off costs ~2 MB on doop.Each call generates a fresh iframe with a unique element ID, so multiple cells render side-by-side without colliding.