https://github.com/windler/dotgraph
Go package to create and render graphviz dot graphs
https://github.com/windler/dotgraph
dot go golang graphviz graphviz-dot png render
Last synced: 6 months ago
JSON representation
Go package to create and render graphviz dot graphs
- Host: GitHub
- URL: https://github.com/windler/dotgraph
- Owner: windler
- License: mit
- Created: 2018-02-04T14:56:55.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-10-29T12:00:58.000Z (almost 7 years ago)
- Last Synced: 2025-03-26T09:04:37.059Z (6 months ago)
- Topics: dot, go, golang, graphviz, graphviz-dot, png, render
- Language: Go
- Size: 13.7 KB
- Stars: 6
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
[](https://goreportcard.com/report/github.com/windler/dotgraph) [](https://circleci.com/gh/windler/dotgraph) [](https://codebeat.co/projects/github-com-windler-dotgraph-master)
# dotgraph
`dotgraph` is a package that lets you create and render [graphviz dot graphs](https://www.graphviz.org/).## Installation
```bash
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](https://www.graphviz.org/) installed.
## Usage
### Creating a new graph
```go
graph := graph.New("my_graph")
```### Adding nodes
```go
graph.AddNode("first node")
graph.AddNode("second node")
graph.AddNode("third node")
```
### Adding directed edges
```go
graph.AddDirectedEdge("first node", "second node", "edge label")
```### Assiging dot graph attributes
You can apply any [dot attributes](https://graphviz.gitlab.io/_pages/doc/info/attrs.html).#### Graph attributes
```go
graph.SetGraphOptions(dotgraph.DotGraphOptions{
"bgcolor": "#333333",
})
```#### Global node attributes
```go
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:```go
graph.AddNodeGraphPatternOptions("first", dotgraph.DotGraphOptions{
"shape": "oval",
})
```#### Global edge attributes
```go
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:```go
graph.AddEdgeGraphPatternOptions("first", dotgraph.DotGraphOptions{
"color": "black",
})
```### Render a graph
```go
r := &renderer.PNGRenderer{
OutputFile: "/tmp/my_graph.png",
}r.Render(graph.String())
```