Skip to content

Commit

Permalink
implemented feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
quffaro committed Oct 23, 2024
1 parent 5491829 commit b51c89e
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/graphics/Graphviz.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ References:
"""
module Graphviz
export Expression, Statement, Attributes, Graph, Digraph, Subgraph,
Node, NodeID, Edge, Label, pprint, run_graphviz
Node, NodeID, Edge, Label, pprint, run_graphviz, view_graphviz

using DataStructures: OrderedDict
using StructEquality
Expand Down Expand Up @@ -172,6 +172,20 @@ function Base.show(io::IO, ::MIME"image/svg+xml", graph::Graph)
run_graphviz(io, graph, format="svg")
end

function view_graphviz(g::Graph; path::String="")
filepath = isempty(path) ? "$(tempname()).png" : path
open(filepath, "w") do io
run_graphviz(io, g, format="png")

Check warning on line 178 in src/graphics/Graphviz.jl

View check run for this annotation

Codecov / codecov/patch

src/graphics/Graphviz.jl#L175-L178

Added lines #L175 - L178 were not covered by tests
end
if Sys.islinux()
run(`xdg-open $filepath`, wait=false)
elseif Sys.isapple()
run(`open $filepath`, wait=false)
elseif Sys.iswindows()
run(`start $filepath`, wait=false)

Check warning on line 185 in src/graphics/Graphviz.jl

View check run for this annotation

Codecov / codecov/patch

src/graphics/Graphviz.jl#L180-L185

Added lines #L180 - L185 were not covered by tests
end
end

# Pretty-print
##############

Expand Down Expand Up @@ -275,18 +289,4 @@ end

indent(io::IO, n::Int) = print(io, " "^n)

function to_graphviz_with_viewer(g::Graph; path::String="", kw...)
filepath = isempty(path) ? "$(tempname()).png" : path
open(filepath, "w") do io
run_graphviz(io, to_graphviz(g), format="png")
end
if Sys.islinux()
run(`feh $filepath`, wait=false)
elseif Sys.isapple()
run(`open $filepath`, wait=false)
elseif Sys.iswindows()
run(`start $filepath`, wait=false)
end
end

end

0 comments on commit b51c89e

Please sign in to comment.