Skip to content

Commit

Permalink
Floating viewer for Graphviz output (#947)
Browse files Browse the repository at this point in the history
* adding viewer

* implemented feedback
  • Loading branch information
quffaro authored Oct 23, 2024
1 parent b40e631 commit 764b4c0
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion 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")
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)
end
end

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

Expand Down

0 comments on commit 764b4c0

Please sign in to comment.