@@ -84,7 +84,7 @@ def _build_graph_for_viz(graph_func, *args, **kwargs):
8484def _build_graphviz_graph (graph_func , * args , ** kwargs ):
8585 from graphviz import Digraph
8686
87- nodes , edges = _build_graph_for_viz (graph_func = graph_func , * args , ** kwargs )
87+ nodes , edges = _build_graph_for_viz (graph_func , * args , ** kwargs )
8888
8989 digraph = Digraph (strict = True )
9090 digraph .attr (rankdir = "LR" , size = "150,150" )
@@ -137,21 +137,18 @@ def show_graph_pil(graph_func, *args, **kwargs):
137137 image .show ()
138138
139139
140- def show_graph_graphviz (graph_func , * args , graph_filename = None , interactive = False , ** kwargs ):
140+ def show_graph_graphviz (graph_func , * args , graph_filename = None , ** kwargs ):
141141 # extract the format of the image
142142 image_format = graph_filename .split ("." )[- 1 ] if graph_filename else "png"
143143
144144 # Generate graph with graphviz
145145 digraph = _build_graphviz_graph (graph_func , * args , ** kwargs )
146146
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 ())
155152 return digraph
156153
157154
@@ -188,19 +185,14 @@ def show_graph(graph_func, *args, graph_filename=None, **kwargs):
188185 else :
189186 _HAVE_INTERACTIVE = False
190187
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" :
196192 # 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 :
200195 # render with pillow
201196 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
204- return show_graph_graphviz (
205- graph_func , * args , graph_filename = graph_filename , interactive = _HAVE_INTERACTIVE , ** kwargs
206- )
197+ # render with graphviz
198+ return show_graph_graphviz (graph_func , * args , graph_filename = graph_filename , ** kwargs )
0 commit comments