Commit 444be204 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Enable drawing to file-like object

parent 0c932865
...@@ -518,8 +518,8 @@ def graph_draw(g, pos=None, vprops=None, eprops=None, vorder=None, eorder=None, ...@@ -518,8 +518,8 @@ def graph_draw(g, pos=None, vprops=None, eprops=None, vorder=None, eorder=None,
(pixels for the screen, points for PDF, etc). (pixels for the screen, points for PDF, etc).
fit_view : bool (optional, default: ``True``) fit_view : bool (optional, default: ``True``)
If ``True``, the layout will be scaled to fit the entire display area. If ``True``, the layout will be scaled to fit the entire display area.
output : string (optional, default: ``None``) output : string or file object (optional, default: ``None``)
Output file name. If not given, the graph will be displayed via Output file name (or object). If not given, the graph will be displayed via
:func:`interactive_window`. :func:`interactive_window`.
fmt : string (default: ``"auto"``) fmt : string (default: ``"auto"``)
Output file format. Possible values are ``"auto"``, ``"ps"``, ``"pdf"``, Output file format. Possible values are ``"auto"``, ``"ps"``, ``"pdf"``,
...@@ -784,7 +784,12 @@ def graph_draw(g, pos=None, vprops=None, eprops=None, vorder=None, eorder=None, ...@@ -784,7 +784,12 @@ def graph_draw(g, pos=None, vprops=None, eprops=None, vorder=None, eorder=None,
return interactive_window(g, pos, vprops, eprops, vorder, eorder, return interactive_window(g, pos, vprops, eprops, vorder, eorder,
nodesfirst, **kwargs) nodesfirst, **kwargs)
else: else:
out, auto_fmt = open_file(output, mode="wb") if isinstance(output, str):
out, auto_fmt = open_file(output, mode="wb")
else:
out = output
if fmt == "auto":
raise ValueError("File format must be specified.")
if fmt == "auto": if fmt == "auto":
fmt = auto_fmt fmt = auto_fmt
...@@ -832,7 +837,7 @@ def graph_draw(g, pos=None, vprops=None, eprops=None, vorder=None, eorder=None, ...@@ -832,7 +837,7 @@ def graph_draw(g, pos=None, vprops=None, eprops=None, vorder=None, eorder=None,
nodesfirst, **kwargs) nodesfirst, **kwargs)
del cr del cr
if output.endswith(".png"): if fmt == "png":
srf.write_to_png(out) srf.write_to_png(out)
return pos return pos
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment