Skip to content

Commit

Permalink
XXX more graphviz porting
Browse files Browse the repository at this point in the history
  • Loading branch information
purpleidea committed Jul 26, 2023
1 parent 1729fda commit 488bebd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
12 changes: 8 additions & 4 deletions lib/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -773,11 +773,15 @@ func (obj *Main) Run() error {

Logf("graph: %+v", obj.ge.Graph()) // show graph
if obj.Graphviz != "" {
filter := obj.GraphvizFilter
if filter == "" {
filter = "dot" // directed graph default
gv := &pgraph.Graphviz{
Filter: obj.GraphvizFilter,
Filename: obj.Graphviz,
Hostname: hostname,
Graphs: map[*pgraph.Graph]*pgraph.GraphvizOpts{
obj.ge.Graph(): nil,
},
}
if err := obj.ge.Graph().ExecGraphviz(filter, obj.Graphviz, hostname); err != nil {
if err := gv.Exec(); err != nil {
Logf("graphviz: %+v", err)
} else {
Logf("graphviz: successfully generated graph!")
Expand Down
22 changes: 11 additions & 11 deletions pgraph/graphviz.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ type Graphviz struct {
// options that should be used to format them during display.
Graphs map[*Graph]*GraphvizOpts

// Program is the graphviz program to run. The default is "dot".
Program string
// Filter is the graphviz program to run. The default is "dot".
Filter string

// Filename is the output location for the graph.
Filename string
Expand Down Expand Up @@ -108,7 +108,7 @@ func (obj *Graphviz) Text() string {
name := obj.name()
str += fmt.Sprintf("digraph \"%s\" {\n", name)
str += fmt.Sprintf("\tlabel=\"%s\";\n", name)
//if obj.program() == "dot" || true {
//if obj.filter() == "dot" || true {
str += fmt.Sprintf("\tnewrank=true;\n")
//}

Expand All @@ -126,16 +126,16 @@ func (obj *Graphviz) Text() string {
// Exec writes out the graphviz data and runs the correct graphviz filter
// command.
func (obj *Graphviz) Exec() error {
program := ""
switch obj.Program {
filter := ""
switch obj.Filter {
case "":
program = graphvizDefaultFilter
filter = graphvizDefaultFilter

case "dot", "neato", "twopi", "circo", "fdp", "sfdp", "patchwork", "osage":
program = obj.Program
filter = obj.Filter

default:
return fmt.Errorf("invalid graphviz program selected")
return fmt.Errorf("invalid graphviz filter selected")
}

if obj.Filename == "" {
Expand All @@ -161,9 +161,9 @@ func (obj *Graphviz) Exec() error {
}
}

path, err := exec.LookPath(program)
path, err := exec.LookPath(filter)
if err != nil {
return errwrap.Wrapf(err, "the Graphviz program is missing")
return errwrap.Wrapf(err, "the Graphviz filter is missing")
}

out := fmt.Sprintf("%s.png", filename)
Expand Down Expand Up @@ -264,7 +264,7 @@ func (obj *Graph) ExecGraphviz(filename string) error {
obj: nil,
},

//Program: program,
//Filter: filter,
Filename: filename,
//Hostname: hostname,
}
Expand Down

0 comments on commit 488bebd

Please sign in to comment.