@@ -144,14 +144,11 @@ def show_graph_graphviz(graph_func, *args, graph_filename=None, interactive=Fals
144
144
# Generate graph with graphviz
145
145
digraph = _build_graphviz_graph (graph_func , * args , ** kwargs )
146
146
147
- # if we're in a notebook, return it directly for rendering
148
- if interactive :
149
- return digraph
150
-
151
- # otherwise output to file
152
- buffer = _graphviz_to_buffer (digraph = digraph , image_format = image_format )
153
- with open (graph_filename , "wb" ) as f :
154
- f .write (buffer .read ())
147
+ if graph_filename :
148
+ # output to file
149
+ buffer = _graphviz_to_buffer (digraph = digraph , image_format = image_format )
150
+ with open (graph_filename , "wb" ) as f :
151
+ f .write (buffer .read ())
155
152
return digraph
156
153
157
154
@@ -188,19 +185,16 @@ def show_graph(graph_func, *args, graph_filename=None, **kwargs):
188
185
else :
189
186
_HAVE_INTERACTIVE = False
190
187
191
- # display graph via pillow or ipydagred3
192
- if graph_filename in (None , "widget" ):
193
- if graph_filename == "widget" and not _HAVE_INTERACTIVE :
194
- raise RuntimeError ("Interactive graph viewer only works in Jupyter." )
195
-
188
+ if graph_filename == "widget" and not _HAVE_INTERACTIVE :
189
+ # widget only works in Jupyter for now
190
+ raise RuntimeError ("Interactive graph viewer only works in Jupyter." )
191
+ elif graph_filename == "widget" :
196
192
# render with ipydagred3
197
- if graph_filename == "widget" :
198
- return show_graph_widget (graph_func , * args , ** kwargs )
199
-
193
+ return show_graph_widget (graph_func , * args , ** kwargs )
194
+ elif graph_filename in ("" , None ) and not _HAVE_INTERACTIVE :
200
195
# render with pillow
201
196
return show_graph_pil (graph_func , * args , ** kwargs )
202
-
203
- # TODO we can show graphviz in jupyter without a filename, but preserving existing behavior for now
197
+ # render with graphviz
204
198
return show_graph_graphviz (
205
199
graph_func , * args , graph_filename = graph_filename , interactive = _HAVE_INTERACTIVE , ** kwargs
206
200
)
0 commit comments