|
4 | 4 | import anywidget |
5 | 5 | import traitlets |
6 | 6 | from IPython.display import display |
7 | | -from ipywidgets.embed import embed_minimal_html |
8 | 7 |
|
| 8 | +# from ipywidgets.embed import embed_minimal_html |
9 | 9 | from .ipython_magic import IN_IPYTHON |
10 | 10 |
|
11 | 11 | CURRENT_DIR = pathlib.Path(__file__).parent |
@@ -33,7 +33,21 @@ def display_or_open(self) -> None: |
33 | 33 | # 2. Write the widget to it with embed_minimal_html |
34 | 34 | # 3. Open the file using the open function from graphviz |
35 | 35 | file = pathlib.Path.cwd() / "tmp.html" |
| 36 | + file.write_text(HTML.replace("MAGIC_STRING", str(self.egraphs))) |
36 | 37 | # https://github.com/manzt/anywidget/issues/339#issuecomment-1755654547 |
37 | | - embed_minimal_html(file, views=[self], drop_defaults=False) |
| 38 | + # embed_minimal_html(file, views=[self], drop_defaults=False) |
| 39 | + # Instead of embedding widget, just save |
38 | 40 | print("Visualizer widget saved to", file) |
39 | 41 | webbrowser.open(file.as_uri()) |
| 42 | + |
| 43 | + |
| 44 | +HTML = """ |
| 45 | +<div id="egraph-visualizer"></div> |
| 46 | +<link rel="stylesheet" href="https://esm.sh/egraph-visualizer/dist/style.css" /> |
| 47 | +<script type="module"> |
| 48 | + import { mount } from "https://esm.sh/egraph-visualizer"; |
| 49 | + const egraphs = MAGIC_STRING; |
| 50 | + const mounted = mount(document.getElementById("egraph-visualizer")); |
| 51 | + mounted.render(egraphs); |
| 52 | +</script> |
| 53 | +""" |
0 commit comments