Skip to content

Commit

Permalink
Fix broken update
Browse files Browse the repository at this point in the history
  • Loading branch information
YouGuessedMyName committed Jul 9, 2024
1 parent d0a5747 commit 33261e7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 78 deletions.
80 changes: 10 additions & 70 deletions notebooks/die.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -12,41 +12,9 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "8be7a5250ff84bee89045deba932f1bd",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HTML(value='<b>hi</b>')"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ipywidgets.HTML(\"<b>hi</b>a\")"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"model.html\n"
]
},
{
"data": {
"text/html": [
Expand All @@ -62,36 +30,7 @@
" "
],
"text/plain": [
"<IPython.lib.display.IFrame at 0x10a35c920>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"<stormvogel.visualization.Visualization object at 0x10a35b5f0>\n",
"model.html\n"
]
},
{
"data": {
"text/html": [
"\n",
" <iframe\n",
" width=\"100%\"\n",
" height=\"600px\"\n",
" src=\"model.html\"\n",
" frameborder=\"0\"\n",
" allowfullscreen\n",
" \n",
" ></iframe>\n",
" "
],
"text/plain": [
"<IPython.lib.display.IFrame at 0x10a359f10>"
"<IPython.lib.display.IFrame at 0x7f03ae000150>"
]
},
"metadata": {},
Expand All @@ -100,10 +39,10 @@
{
"data": {
"text/plain": [
"<stormvogel.visualization.Visualization at 0x10a344200>"
"<DisplayHandle display_id=9427932215932410579146286952338>"
]
},
"execution_count": 14,
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -119,9 +58,10 @@
" [(1 / 6, dtmc.new_state(f\"rolled{i}\", {\"rolled\": i})) for i in range(6)]\n",
")\n",
"\n",
"print(stormvogel.visualization.show(dtmc))\n",
"\n",
"stormvogel.visualization.show(dtmc)\n",
"# Show a visualization of the model.\n",
"vis = stormvogel.visualization.show(dtmc)\n",
"dtmc.new_state(\"test\")\n",
"vis.update()\n",
"\n",
"# Print the resulting model in dot format.\n",
"# print(dtmc.to_dot())"
Expand Down Expand Up @@ -151,7 +91,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.4"
"version": "3.11.2"
}
},
"nbformat": 4,
Expand Down
6 changes: 3 additions & 3 deletions notebooks/model.html
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ <h1></h1>


// parsing and collecting nodes and edges from the python
nodes = new vis.DataSet([{"borderWidth": 3, "color": null, "id": 0, "label": "init", "shape": "circle"}, {"borderWidth": 1, "color": null, "id": 1, "label": "rolled0", "shape": "elipse"}, {"borderWidth": 1, "color": null, "id": 2, "label": "rolled1", "shape": "elipse"}, {"borderWidth": 1, "color": null, "id": 3, "label": "rolled2", "shape": "elipse"}, {"borderWidth": 1, "color": null, "id": 4, "label": "rolled3", "shape": "elipse"}, {"borderWidth": 1, "color": null, "id": 5, "label": "rolled4", "shape": "elipse"}, {"borderWidth": 1, "color": null, "id": 6, "label": "rolled5", "shape": "elipse"}]);
edges = new vis.DataSet([{"arrows": "to", "color": null, "from": 0, "label": "1/6", "to": 1}, {"arrows": "to", "color": null, "from": 0, "label": "1/6", "to": 2}, {"arrows": "to", "color": null, "from": 0, "label": "1/6", "to": 3}, {"arrows": "to", "color": null, "from": 0, "label": "1/6", "to": 4}, {"arrows": "to", "color": null, "from": 0, "label": "1/6", "to": 5}, {"arrows": "to", "color": null, "from": 0, "label": "1/6", "to": 6}, {"arrows": "to", "color": null, "from": 1, "label": "1", "to": 1}, {"arrows": "to", "color": null, "from": 2, "label": "1", "to": 2}, {"arrows": "to", "color": null, "from": 3, "label": "1", "to": 3}, {"arrows": "to", "color": null, "from": 4, "label": "1", "to": 4}, {"arrows": "to", "color": null, "from": 5, "label": "1", "to": 5}, {"arrows": "to", "color": null, "from": 6, "label": "1", "to": 6}]);
nodes = new vis.DataSet([{"borderWidth": 3, "color": null, "id": 0, "label": "init", "shape": "circle"}, {"borderWidth": 1, "color": null, "id": 1, "label": "rolled0", "shape": "elipse"}, {"borderWidth": 1, "color": null, "id": 2, "label": "rolled1", "shape": "elipse"}, {"borderWidth": 1, "color": null, "id": 3, "label": "rolled2", "shape": "elipse"}, {"borderWidth": 1, "color": null, "id": 4, "label": "rolled3", "shape": "elipse"}, {"borderWidth": 1, "color": null, "id": 5, "label": "rolled4", "shape": "elipse"}, {"borderWidth": 1, "color": null, "id": 6, "label": "rolled5", "shape": "elipse"}, {"borderWidth": 1, "color": null, "id": 7, "label": "test", "shape": "elipse"}]);
edges = new vis.DataSet([{"arrows": "to", "color": null, "from": 0, "label": "1/6", "to": 1}, {"arrows": "to", "color": null, "from": 0, "label": "1/6", "to": 2}, {"arrows": "to", "color": null, "from": 0, "label": "1/6", "to": 3}, {"arrows": "to", "color": null, "from": 0, "label": "1/6", "to": 4}, {"arrows": "to", "color": null, "from": 0, "label": "1/6", "to": 5}, {"arrows": "to", "color": null, "from": 0, "label": "1/6", "to": 6}, {"arrows": "to", "color": null, "from": 1, "label": "1", "to": 1}, {"arrows": "to", "color": null, "from": 2, "label": "1", "to": 2}, {"arrows": "to", "color": null, "from": 3, "label": "1", "to": 3}, {"arrows": "to", "color": null, "from": 4, "label": "1", "to": 4}, {"arrows": "to", "color": null, "from": 5, "label": "1", "to": 5}, {"arrows": "to", "color": null, "from": 6, "label": "1", "to": 6}, {"arrows": "to", "color": null, "from": 7, "label": "1", "to": 7}]);

nodeColors = {};
allNodes = nodes.get({ returnType: "Object" });
Expand All @@ -294,7 +294,7 @@ <h1></h1>
// adding nodes and edges to the graph
data = {nodes: nodes, edges: edges};

var options = {"nodes": {"color": {"background": "white", "border": "black", "highlight": {"background": "white", "border": "black"}}}, "init": {"borderWidth": 3, "color": null, "shape": "circle"}, "states": {"borderWidth": 1, "color": null, "shape": "elipse"}, "actions": {"borderWidth": 1, "color": null, "shape": "box"}, "numbers": {"fractions": true, "digits": 5, "max_denominator": 20}, "layout": {"randomSeed": 5}};
var options = {"nodes": {"color": {"background": "white", "border": "black", "highlight": {"background": "white", "border": "black"}, "font": {"color": "black", "size": 14}}}, "init": {"borderWidth": 3, "color": null, "shape": "circle", "repulsion": 1}, "states": {"borderWidth": 1, "color": null, "shape": "elipse", "repulsion": 1}, "actions": {"borderWidth": 1, "color": null, "shape": "box", "repulsion": 1}, "numbers": {"fractions": true, "digits": 5, "max_denominator": 20}, "edges": {"font": {"color": "black", "size": 14}}, "layout": {"randomSeed": 5}};



Expand Down
13 changes: 8 additions & 5 deletions stormvogel/visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from fractions import Fraction
from html import escape

from IPython.display import HTML, IFrame, display
from IPython.display import HTML, display
from pyvis.network import Network

from stormvogel.layout import DEFAULT, Layout
Expand Down Expand Up @@ -58,12 +58,12 @@ def update(self):
try:
self.nt.write_html(self.name, open_browser=False, notebook=self.notebook)
# Not using show here to stop the print message.
iframe = IFrame(self.name, width=self.nt.width, height=self.nt.height)
self.handle.update(iframe) # type: ignore
self.handle.update(self.custom_iframe) # type: ignore
except AttributeError:
raise Exception(
"show should be called at least once before calling update."
)
return self.handle

def show(self):
"""Show or update the constructed graph as a html file."""
Expand All @@ -73,7 +73,7 @@ def show(self):

# We build our own iframe because we want to embed the model in the
# output instead of saving it to a file
custom_iframe = f"""
self.custom_iframe = f"""
<iframe
style="width: {self.nt.width}; height: calc({self.nt.height} + 50px);"
frameborder="0"
Expand All @@ -83,7 +83,10 @@ def show(self):
></iframe>"""

# We use a random id which will avoid collisions in most cases.
return display(HTML(custom_iframe), display_id=random.randrange(0, 10**31))
self.handle = display(
HTML(self.custom_iframe), display_id=random.randrange(0, 10**31)
)
return self.handle

def show_editor(self):
"""Display an interactive layout editor. Use the update() method to apply changes."""
Expand Down

0 comments on commit 33261e7

Please sign in to comment.