dot

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2019 License: MIT Imports: 4 Imported by: 4

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

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

	Style string
}

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
	IsSubGraph bool

	// string attributes
	Rank string
}

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, style string)

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

func (*Graph) AddNewLine

func (graph *Graph) AddNewLine()

AddNewLine schedules a newline to be written in the output dotfile

func (*Graph) AddSubGraph

func (graph *Graph) AddSubGraph(sGraph *Graph)

AddSubGraph 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) Write

func (graph *Graph) Write(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

	// string attributes
	Label       string
	Group       string
	Color       string
	Style       string
	ColorScheme string
	FontColor   string
	FontName    string
	Shape       string

	// int attributes
	Peripheries int
}

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

func NewVertexDescription

func NewVertexDescription(id string) VertexDescription

NewVertexDescription returns a new VertexDescription with the given ID.

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