From 549182948d82280a4ebe915bd6c50546bdf8cdb0 Mon Sep 17 00:00:00 2001 From: Matt Date: Tue, 22 Oct 2024 12:41:09 -0400 Subject: [PATCH 1/2] adding viewer --- src/graphics/Graphviz.jl | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/graphics/Graphviz.jl b/src/graphics/Graphviz.jl index b812a5054..799d98011 100644 --- a/src/graphics/Graphviz.jl +++ b/src/graphics/Graphviz.jl @@ -275,4 +275,18 @@ 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 From b51c89ea662be69b51003578357151e270d53210 Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 23 Oct 2024 15:54:06 -0400 Subject: [PATCH 2/2] implemented feedback --- src/graphics/Graphviz.jl | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/graphics/Graphviz.jl b/src/graphics/Graphviz.jl index 799d98011..7a08e4c4b 100644 --- a/src/graphics/Graphviz.jl +++ b/src/graphics/Graphviz.jl @@ -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 @@ -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 ############## @@ -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