Skip to content

Commit 764b4c0

Browse files
authored
Floating viewer for Graphviz output (#947)
* adding viewer * implemented feedback
1 parent b40e631 commit 764b4c0

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/graphics/Graphviz.jl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ References:
77
"""
88
module Graphviz
99
export Expression, Statement, Attributes, Graph, Digraph, Subgraph,
10-
Node, NodeID, Edge, Label, pprint, run_graphviz
10+
Node, NodeID, Edge, Label, pprint, run_graphviz, view_graphviz
1111

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

175+
function view_graphviz(g::Graph; path::String="")
176+
filepath = isempty(path) ? "$(tempname()).png" : path
177+
open(filepath, "w") do io
178+
run_graphviz(io, g, format="png")
179+
end
180+
if Sys.islinux()
181+
run(`xdg-open $filepath`, wait=false)
182+
elseif Sys.isapple()
183+
run(`open $filepath`, wait=false)
184+
elseif Sys.iswindows()
185+
run(`start $filepath`, wait=false)
186+
end
187+
end
188+
175189
# Pretty-print
176190
##############
177191

0 commit comments

Comments
 (0)