Skip to content

Commit 72091c9

Browse files
committed
fix remaining tutorial bugs
1 parent 287a49f commit 72091c9

3 files changed

Lines changed: 17 additions & 14 deletions

File tree

docs/examples/layouts.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,15 @@
6969
# GA
7070

7171
# %%
72+
import threading
7273
import ipywidgets as ipyw
7374
import textwrap
7475

7576
select = ipyw.Dropdown(options=layouts.keys(), value="SugiyamaLayout")
7677
widget = MatplotlibGraph(GA)
7778
info = ipyw.HTML()
7879

79-
80-
def set_layout(_):
81-
info.value = f"Computing..."
82-
l = select.value
83-
print(l, layouts[l])
84-
print(cppinclude(layouts[l]))
80+
def run_layout(l):
8581
L = getattr(ogdf, l)()
8682
GA.clearAllBends()
8783
try:
@@ -101,19 +97,29 @@ def set_layout(_):
10197
f"Failed ({textwrap.shorten(str(e), width=100, placeholder='...')})"
10298
)
10399
raise
100+
finally:
101+
select.disabled = False
104102
info.value = f"Success <a href='{L.__doc__}' target='_blank'>(Docs)</a>"
105103
widget.update_all(GA)
106104
widget.ax.relim()
107105
widget.ax.autoscale()
108106
widget.ax.figure.canvas.draw_idle()
109107

110108

109+
def set_layout(_):
110+
info.value = f"Computing..."
111+
select.disabled = True
112+
l = select.value
113+
print(l, layouts[l])
114+
print(cppinclude(layouts[l]))
115+
threading.Thread(target=run_layout, args=(l,)).start()
116+
117+
111118
select.observe(set_layout, names="value")
112119

113120
display(ipyw.VBox([ipyw.HBox([select, info]), widget.ax.figure.canvas]))
114121

115122
# %%
116-
117123
# TutteLayout requires the graph to be triconnected
118124
cppinclude("ogdf/energybased/TutteLayout.h")
119125
cppinclude("ogdf/basic/simple_graph_alg.h")

docs/tutorial/2 embeddings.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
# likewise, reordering nodes and edges in the interactive preview doesn't change the order
4141

4242
# %% [markdown]
43-
# ![img/adjList.png](attachment:img/adjList.png)
43+
# ![img/adjList.png](img/adjList.png)
4444

4545

4646
# %%
@@ -103,7 +103,7 @@ def dump(o):
103103
# try to locate this face in your drawing!
104104

105105
# %% [markdown]
106-
# ![img/faceOrder.png](attachment:img/faceOrder.png)
106+
# ![img/faceOrder.png](img/faceOrder.png)
107107

108108
# %%
109109
# instead of manually trying to find a planar embedding, OGDF can do that for us!
@@ -115,5 +115,3 @@ def dump(o):
115115
print("\n".join(str(n) for n in G.nodes))
116116
# the embedding is different!?
117117
# how does this embedding differ from the one we found?
118-
119-
# %%

docs/tutorial/7 iterative dfs C++.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# In this notebook, we'll show how to gradually migrate Python code to more efficient C++ code, while keeping the interactivity of Jupyter's notebooks. We'll use the "iterative DFS" from the Python tutorial as example for the migration, so make sure to have that notebook open for comparison! First, we'll create our example graph (in plain Python for simplicity):
33

44
# %%
5-
# %matplotlib widget
65
from ogdf_python import ogdf, cppinclude
76

87
cppinclude("ogdf/basic/graph_generators/randomized.h")
@@ -140,7 +139,7 @@
140139
# The [`%%writefile` cell magic](https://ipython.readthedocs.io/en/stable/interactive/magics.html#cellmagic-writefile) below will create the file for you, which we can `cppinclude` in the cell after.
141140

142141
# %%
143-
# %%writefile dfs_step.h
142+
%%writefile dfs_step.h
144143

145144
using namespace ogdf; // stop prefixing everything with ogdf::
146145

@@ -212,7 +211,7 @@ def dump(): # utility function for easily displaying the current state
212211
# The widget works as before!
213212

214213
# enable the interactive widget
215-
# # %matplotlib widget
214+
%matplotlib widget
216215
import ipywidgets
217216
from ogdf_python.matplotlib import MatplotlibGraph
218217

0 commit comments

Comments
 (0)