-
Notifications
You must be signed in to change notification settings - Fork 213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add configurable format for notebook visualization #138
Comments
From upstream https://gitlab.com/graphviz/graphviz/-/issues/1605 I understand that the upstream bug was fixed in upstream
I assume that you mean that the machines are tied to the latest version of
Independent of the upstream bug, I think we could still add configureable backend for notebook visualization (not sure though if e.g. PDF would work). |
Yes.
For PDF I had this in my mind, but it is not well suited for this package. In Here, some ideas, for a PR that I could create, where I need your opinion: Implement An alternative would be to define A further alternative would be to dynamically define the I must say, all of them have disadvantages. Defining |
Thanks for your notes. How about we implement https://ipython.readthedocs.io/en/stable/config/integrating.html#MyObject._repr_mimebundle_ returning a |
Made some room for this feature (feel free to send a PR): graphviz/graphviz/jupyter_integration.py Lines 8 to 12 in 44ff5c3
|
Just in case: some more documentation on |
Thank you. I used that notebook for the PR. |
Thanks. Yes, see my review: #150 (review) Fixing/adapting the tests SG. Let me know if you have questions. |
Merged #150 and applied more improvements, maybe you want to take a look. |
Your changes look good. Nevertheless, for documentation, if someone wants to replace a repr: def repr_pdf_to_svg(dot):
import tempfile
from pathlib import Path
import subprocess
pdf_data = dot.pipe(format='pdf')
with tempfile.TemporaryDirectory() as tmpdir:
tmpdir = Path(tmpdir)
pdf = tmpdir / 'image.pdf'
pdf.write_bytes(pdf_data)
subprocess.run([
'inkscape',
'--without-gui',
f'--file={pdf}',
'--export-plain-svg=main.svg',
], cwd=tmpdir)
return Path(tmpdir / 'main.svg').read_text()
import graphviz
from IPython.display import display, display_svg, display_png, display_jpeg
graphviz.jupyter_integration.JupyterIntegration._repr_pdf_to_svg = repr_pdf_to_svg
# graphviz.jupyter_integration.JUPYTER_FORMATS['pdf_svg'] = 'image/svg+xml'
graphviz.jupyter_integration.MIME_TYPES['image/svg+xml'] = '_repr_pdf_to_svg'
# graphviz.set_jupyter_format('pdf_svg')
g = graphviz.Digraph('G', filename='hello.gv')
g.edge('Hello', 'World')
display(g) |
Included in 0.19 release, closing. Thanks for the contribution. |
In Ubuntu 20.04, the default graphviz (i.e. C code, not python) version is 2.43.0.
In https://gitlab.com/graphviz/graphviz/-/issues/1605 someone reported a bug,
that the scale was wrongly calculated (introduced in 2.42.0 and fixed in 2.42.4, not sure, how the versioning works, but 2.43.0 is between them).
I am not in the position to update the C graphviz, but I can easily update the Python graphviz (i.e. this package).
Are you interested in a PR, that has a workaround to fix this?
I observed this bug, when I tried to visualize a Graph in a Jupyter Lab Notebook.
While the small examples worked, the larger ones got broken.
Here is the image from https://gitlab.com/graphviz/graphviz/-/issues/1605 it
should give you an idea, what happened in my notebook (Sorry, my examples were too complicated to post them here):
When the graph gets to large, I see something like the first image, while small examples produce the correct output.
At the moment I use the following wrapper to fix the visualization, because I cannot replace the C lib.
I am not sure, which workaround would be the best solution.
Examples:
The text was updated successfully, but these errors were encountered: