-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdot.go
39 lines (31 loc) · 768 Bytes
/
dot.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
package goneo
import (
"fmt"
. "github.com/BuJo/goneo/db"
)
// DumpDot formats the given DB in Graphviz format.
func DumpDot(db DatabaseService) string {
str := "digraph G {\n"
for _, n := range db.GetAllNodes() {
label := ""
if len(n.Properties()) > 0 {
// Select a property which is long'ish
for _, p := range n.Properties() {
if len(p) > 2 {
label = p
break
}
}
} else if len(n.Labels()) > 0 {
// Otherwise try to use a label
label = n.Labels()[0]
}
str += fmt.Sprintf("\tn%d [label=\"[%d]\\n%s\"]\n", n.Id(), n.Id(), label)
}
str += "\n\n"
for _, r := range db.GetAllRelations() {
str += fmt.Sprintf("\tn%d -> n%d [label=\"%s\"]\n", r.Start().Id(), r.End().Id(), r.Type())
}
str += "}\n"
return str
}