Skip to content
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

Force svg+xml for GraphViz object as a workaround #268

Merged
merged 2 commits into from
Feb 4, 2025
Merged

Conversation

bvdmitri
Copy link
Member

@bvdmitri bvdmitri commented Feb 4, 2025

@FraserP117 gave me this idea in our private conversation and it actually worked pretty neatly!

Reference https://docs.julialang.org/en/v1/base/io-network/#Multimedia-I/O

The implementation wraps the GraphViz object in a "wrapper" that does only "support" svg and text display formats.
So now if display supports svg it will automatically show the svg image, otherwise it fallbacks to the dot strings as @FraserP117 planned originally. e.g compare:
Screenshot 2025-02-04 at 09 43 31
Screenshot 2025-02-04 at 09 43 54

Copy link

codecov bot commented Feb 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.64%. Comparing base (bbb6781) to head (ddd1dd8).
Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #268   +/-   ##
=======================================
  Coverage   90.64%   90.64%           
=======================================
  Files          16       16           
  Lines        2170     2170           
=======================================
  Hits         1967     1967           
  Misses        203      203           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bvdmitri
Copy link
Member Author

bvdmitri commented Feb 4, 2025

Lets wait for @FraserP117 input before merging

@@ -459,6 +459,40 @@ function convert_strategy(strategy::Symbol)
end
end

"""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm reviewing/testing locally now. Apologies for the delay!

@jhlq
Copy link

jhlq commented Feb 4, 2025

This is a good workaround until the GraphViz package can be updated from the deprecated Cstring vector representation. I did ]dev GraphViz and changed the lines

const julia_cairo_name = Vector{UInt8}("julia:cairo")
const julia_cairo_libname = Vector{UInt8}("julia:cairo")

in src/cairo.jl to

const julia_cairo_name = Base.unsafe_convert(Cstring,"julia:cairo")
const julia_cairo_libname = Base.unsafe_convert(Cstring,"julia:cairo")

and that seems to fix the render bug.

@FraserP117
Copy link

Very nice stuff @bvdmitri. I have tested this locally in VSCodium and Jupyter notebook. Both work quite well.

When using Jupyter notebook, I do seem to get an error relating to the Cairo.jl renderer being unavailable - see the enclosed screenshots.

Jupyter_1_PR_268
Jupyter_2_PR_268

We could hold it up and investigate further but I favour passing this PR and improving from there. Perhaps we can implement the fix that @jhlq used above - in the form of a PR to Cairo.jl?

@bvdmitri bvdmitri merged commit 055421a into main Feb 4, 2025
14 checks passed
@bvdmitri bvdmitri deleted the dev-force-svg branch February 4, 2025 14:51
@bvdmitri
Copy link
Member Author

bvdmitri commented Feb 4, 2025

I think Cairo.jl is fine, the problem is with GraphViz.jl, I opened several issues there but didn't get any response (except for @jhlq). I also couldn't run tests for GraphViz.jl locally. I do encourage you to open a PR to their codebase though @jhlq @FraserP117

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants