dotgraph
is a package that lets you create and render graphviz dot graphs.
go get github.com/windler/dotgraph/graph
go get github.com/windler/dotgraph/renderer
If you want to render graphs make sure you have graphviz installed.
graph := graph.New("my_graph")
graph.AddNode("first node")
graph.AddNode("second node")
graph.AddNode("third node")
graph.AddDirectedEdge("first node", "second node", "edge label")
You can apply any dot attributes.
graph.SetGraphOptions(dotgraph.DotGraphOptions{
"bgcolor": "#333333",
})
graph.SetNodeGraphOptions(dotgraph.DotGraphOptions{
"fillcolor": "#336699",
"style": "filled",
"fontcolor": "white",
"fontname": "Courier",
"shape": "rectangle",
})
If you want to assign attributes for nodes matching a pattern you can do the following:
graph.AddNodeGraphPatternOptions("first", dotgraph.DotGraphOptions{
"shape": "oval",
})
graph.SetEdgeGraphOptions(dotgraph.DotGraphOptions{
"arrowhead": "open",
"color": "white",
"fontcolor": "white",
"splines": "curved",
})
If you want to assign attributes for an edge that references a certain node you can do the following:
graph.AddEdgeGraphPatternOptions("first", dotgraph.DotGraphOptions{
"color": "black",
})
r := &renderer.PNGRenderer{
OutputFile: "/tmp/my_graph.png",
}
r.Render(graph.String())