Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

18 Commits

Repository files navigation

Go Report CardCircleCIcodebeat badge

dotgraph

dotgraph is a package that lets you create and render graphviz dot graphs.

Installation

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.

Usage

Creating a new graph

graph:=graph.New("my_graph")

Adding nodes

graph.AddNode("first node")
graph.AddNode("second node")
graph.AddNode("third node")

Adding directed edges

graph.AddDirectedEdge("first node", "second node", "edge label")

Assiging dot graph attributes

You can apply any dot attributes.

Graph attributes

graph.SetGraphOptions(dotgraph.DotGraphOptions{
"bgcolor": "#333333",
})

Global node attributes

graph.SetNodeGraphOptions(dotgraph.DotGraphOptions{
"fillcolor": "#336699",
"style": "filled",
"fontcolor": "white",
"fontname": "Courier",
"shape": "rectangle",
})

Node attributes for nodes

If you want to assign attributes for nodes matching a pattern you can do the following:

graph.AddNodeGraphPatternOptions("first", dotgraph.DotGraphOptions{
"shape": "oval",
})

Global edge attributes

graph.SetEdgeGraphOptions(dotgraph.DotGraphOptions{
"arrowhead": "open",
"color": "white",
"fontcolor": "white",
"splines": "curved",
})

Edge attributes

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",
})

Render a graph

r:=&renderer.PNGRenderer{
OutputFile: "/tmp/my_graph.png",
}
r.Render(graph.String())

About

Go package to create and render graphviz dot graphs

Topics

Resources

Stars

6 stars

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages