-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdraw_test.go
51 lines (41 loc) · 1.07 KB
/
draw_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package brahms_test
import (
"fmt"
"io"
"os"
"os/exec"
"testing"
"github.com/advanderveer/brahms"
"github.com/advanderveer/go-test"
)
func drawPNG(t *testing.T, buf io.Reader, name string) {
f, err := os.Create(name)
test.Ok(t, err)
defer f.Close()
cmd := exec.Command("neato", "-Tpng")
cmd.Stdin = buf
cmd.Stdout = f
test.Ok(t, cmd.Run())
}
func draw(t testing.TB, w io.Writer, views map[*brahms.Node]brahms.View, dead, joins map[brahms.NID]struct{}) {
fmt.Fprintln(w, `digraph {`)
fmt.Fprintln(w, `layout=neato;`)
fmt.Fprintln(w, `overlap=scalexy;`)
fmt.Fprintln(w, `sep="+1";`)
for self, v := range views {
id := self.Hash()
fmt.Fprintf(w, "\t"+`"%.8x" [style="filled,solid",label="%s"`, id.Bytes(), self)
if _, ok := dead[id]; ok {
fmt.Fprintf(w, `,fillcolor="red"`)
} else if _, ok := joins[id]; ok {
fmt.Fprintf(w, `,fillcolor="blue"`)
} else {
fmt.Fprintf(w, `,fillcolor="#ffffff"`)
}
fmt.Fprintf(w, "]\n")
for _, n := range v {
fmt.Fprintf(w, "\t"+`"%.8x" -> "%.8x";`+"\n", id.Bytes(), n.Hash().Bytes())
}
}
fmt.Fprintln(w, `}`)
}