dotgraph

module
v0.0.0-...-04e185e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2018 License: MIT

README

Go Report Card CircleCI codebeat 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())

Directories

Path Synopsis
mocks
Code generated by mockery v1.0.0
Code generated by mockery v1.0.0

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL