dot

package module
v0.0.0-...-94a425d Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2018 License: MIT Imports: 2 Imported by: 5

README

go-dot

Simple dot file writer in go

Example use

import (
       os
       
       dot "github.com/zenground0/go-dot"
)

g := dot.NewGraph("MyGraph", os.Stdout)
var v1 dot.VertexDescription
v1.ID = "V1"
v1.Label = "Node1"
v1.Color = "blue2"
g.AddVertex(&v1)
var v2 dot.VertexDescription
v2.ID = "V2"
v2.Label = "Node2"
v2.Color = "blue1"
g.AddVertex(&v2)

g.AddEdge(v1, v2, true)
g.WriteDot()

output:

digraph MyGraph {
	V1 [label="Node1" color="blue2"]
	V2 [label="Node2" color="blue1"]
	V1 -> V2
}

Contribute

Currently attribute support is barebones. Only attributes "label" and "color" are implemented. PRs welcome to extend this or add other features. Check the issues for proposals in flight, or this reference http://www.graphviz.org/pdf/dotguide.pdf for new ideas.

License

MIT © Protocol Labs, Inc

Documentation

Overview

Package dot provides an abstraction for painlessly building and printing graphviz dot-files

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EdgeDescription

type EdgeDescription struct {
	From     VertexDescription
	To       VertexDescription
	Directed bool
}

EdgeDescription is an element containing all the information needed to fully describe a dot-file edge

func (*EdgeDescription) Write

func (e *EdgeDescription) Write(w io.Writer) error

Write writes the edge description to a writer

type Element

type Element interface {
	Write(io.Writer) error
}

Element captures the information of a dot-file element, typically corresoponding to one line of the file

type Graph

type Graph struct {
	Name string
	Body []Element
}

Graph is the graphviz dot-file graph representation.

func NewGraph

func NewGraph(name string) Graph

NewGraph returns a new dot-file graph object given the provided name

func (*Graph) AddComment

func (graph *Graph) AddComment(text string)

AddComment interprets the given argument as the text of a comment and schedules the comment to be written in the output dotfile

func (*Graph) AddEdge

func (graph *Graph) AddEdge(v1 *VertexDescription, v2 *VertexDescription, directed bool)

AddEdge constructs an edgedescription connecting the two vertices given as parameters and schedules this element to be written in the output dotfile

Example
buf := new(bytes.Buffer)
g := NewGraph("testGraph")
vTo := &VertexDescription{
	ID: "vTo",
}
vFrom := &VertexDescription{
	ID: "vFrom",
}
g.AddEdge(vTo, vFrom, true)
g.WriteDot(buf)

s := buf.String()
lines := strings.Split(s, "\n")
fmt.Printf("%d\n", len(lines))
if len(lines) < 3 {
	return
}
fmt.Println(lines[2])
Output:

5
vTo -> vFrom

func (*Graph) AddNewLine

func (graph *Graph) AddNewLine()

AddNewLine schedules a newline to be written in the output dotfile

func (*Graph) AddVertex

func (graph *Graph) AddVertex(v *VertexDescription)

AddVertex schedules the vertexdescription to be written in the output dotfile

func (*Graph) WriteDot

func (graph *Graph) WriteDot(w io.Writer) error

WriteDot writes the elements scheduled on this Graph to the provided writer to construct a valid dot-file

type Literal

type Literal struct {
	Line string
}

Literal is an element consisting of the corresponding literal string printed in the dot-file

func (*Literal) Write

func (lit *Literal) Write(w io.Writer) error

Write writes the literal to a writer

type VertexDescription

type VertexDescription struct {
	ID    string
	Label string
	Color string
}

VertexDescription is an element containing all the information needed to fully describe a dot-file vertex

func (*VertexDescription) Write

func (v *VertexDescription) Write(w io.Writer) error

Write writes the vertex description to a writer

Jump to

Keyboard shortcuts

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