gographviz

package module
v0.0.0-...-1888791 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2017 License: Apache-2.0, BSD-3-Clause Imports: 7 Imported by: 1

README

Parses the Graphviz DOT language and creates an interface, in golang, with which to easily create new and manipulate existing graphs which can be written back to the DOT format.

This parser has been created using gocc.

Example (Parse and Edit)

graphAst, _ := gographviz.ParseString(`digraph G {}`)
graph := gographviz.NewGraph()
if err := gographviz.Analyse(graphAst, graph); err != nil {
    panic(err)
}
graph.AddNode("G", "a", nil)
graph.AddNode("G", "b", nil)
graph.AddEdge("a", "b", true, nil)
output := graph.String()

Documentation

The godoc includes some more examples.

Installation

go get github.com/fighterlyt/gographviz

Tests

Build Status

Users

  • aptly - Debian repository management tool
  • gorgonai - A Library that helps facilitate machine learning in Go

Mentions

Using Golang and GraphViz to Visualize Complex Grails Applications

Documentation

Overview

Package gographviz provides parsing for the DOT grammar into an abstract syntax tree representing a graph, analysis of the abstract syntax tree into a more usable structure, and writing back of this structure into the DOT format.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddAttr

func AddAttr(attr string)

func Analyse

func Analyse(graph *ast.Graph, g Interface) error

Analyse analyses an Abstract Syntax Tree representing a parsed graph into a newly created graph structure Interface.

func Parse

func Parse(buf []byte) (*ast.Graph, error)

Parse parses the buffer into a abstract syntax tree representing the graph.

func ParseString

func ParseString(buf string) (*ast.Graph, error)

ParseString parses the buffer into a abstract syntax tree representing the graph.

Types

type Attr

type Attr string

Attr is an attribute key

const (
	// Damping http://www.graphviz.org/content/attrs#dDamping
	Damping Attr = "Damping"
	// K http://www.graphviz.org/content/attrs#dK
	K Attr = "K"
	// URL http://www.graphviz.org/content/attrs#dURL
	URL Attr = "URL"
	// Background http://www.graphviz.org/content/attrs#d_background
	Background Attr = "_background"
	// Area http://www.graphviz.org/content/attrs#darea
	Area Attr = "area"
	// ArrowHead http://www.graphviz.org/content/attrs#darrowhead
	ArrowHead Attr = "arrowhead"
	// ArrowSize http://www.graphviz.org/content/attrs#darrowsize
	ArrowSize Attr = "arrowsize"
	// ArrowTail http://www.graphviz.org/content/attrs#darrowtail
	ArrowTail Attr = "arrowtail"
	// BB http://www.graphviz.org/content/attrs#dbb
	BB Attr = "bb"
	// BgColor http://www.graphviz.org/content/attrs#dbgcolor
	BgColor Attr = "bgcolor"
	// Center http://www.graphviz.org/content/attrs#dcenter
	Center Attr = "center"
	// Charset http://www.graphviz.org/content/attrs#dcharset
	Charset Attr = "charset"
	// ClusterRank http://www.graphviz.org/content/attrs#dclusterrank
	ClusterRank Attr = "clusterrank"
	// Color http://www.graphviz.org/content/attrs#dcolor
	Color Attr = "color"
	// ColorScheme http://www.graphviz.org/content/attrs#dcolorscheme
	ColorScheme Attr = "colorscheme"
	// Comment http://www.graphviz.org/content/attrs#dcomment
	Comment Attr = "comment"
	// Compound http://www.graphviz.org/content/attrs#dcompound
	Compound Attr = "compound"
	// Concentrate http://www.graphviz.org/content/attrs#dconcentrate
	Concentrate Attr = "concentrate"
	// Constraint http://www.graphviz.org/content/attrs#dconstraint
	Constraint Attr = "constraint"
	// Decorate http://www.graphviz.org/content/attrs#ddecorate
	Decorate Attr = "decorate"
	// DefaultDist http://www.graphviz.org/content/attrs#ddefaultdist
	DefaultDist Attr = "defaultdist"
	// Dim http://www.graphviz.org/content/attrs#ddim
	Dim Attr = "dim"
	// Dimen http://www.graphviz.org/content/attrs#ddimen
	Dimen Attr = "dimen"
	// Dir http://www.graphviz.org/content/attrs#ddir
	Dir Attr = "dir"
	// DirEdgeConstraints http://www.graphviz.org/content/attrs#ddir
	DirEdgeConstraints Attr = "diredgeconstraints"
	// Distortion http://www.graphviz.org/content/attrs#ddistortion
	Distortion Attr = "distortion"
	// DPI http://www.graphviz.org/content/attrs#ddpi
	DPI Attr = "dpi"
	// EdgeURL http://www.graphviz.org/content/attrs#d:edgeURL
	EdgeURL Attr = "edgeURL"
	// EdgeHREF http://www.graphviz.org/content/attrs#d:edgehref
	EdgeHREF Attr = "edgehref"
	// EdgeTarget http://www.graphviz.org/content/attrs#d:edgetarget
	EdgeTarget Attr = "edgetarget"
	// EdgeTooltip http://www.graphviz.org/content/attrs#d:edgetooltip
	EdgeTooltip Attr = "edgetooltip"
	// Epsilon http://www.graphviz.org/content/attrs#d:epsilon
	Epsilon Attr = "epsilon"
	// ESep http://www.graphviz.org/content/attrs#d:epsilon
	ESep Attr = "esep"
	// FillColor http://www.graphviz.org/content/attrs#dfillcolor
	FillColor Attr = "fillcolor"
	// FixedSize http://www.graphviz.org/content/attrs#dfixedsize
	FixedSize Attr = "fixedsize"
	// FontColor http://www.graphviz.org/content/attrs#dfontcolor
	FontColor Attr = "fontcolor"
	// FontName http://www.graphviz.org/content/attrs#dfontname
	FontName Attr = "fontname"
	// FontNames http://www.graphviz.org/content/attrs#dfontnames
	FontNames Attr = "fontnames"
	// FontPath http://www.graphviz.org/content/attrs#dfontpath
	FontPath Attr = "fontpath"
	// FontSize http://www.graphviz.org/content/attrs#dfontsize
	FontSize Attr = "fontsize"
	// ForceLabels http://www.graphviz.org/content/attrs#dforcelabels
	ForceLabels Attr = "forcelabels"
	// GradientAngle http://www.graphviz.org/content/attrs#dgradientangle
	GradientAngle Attr = "gradientangle"
	// Group http://www.graphviz.org/content/attrs#dgroup
	Group Attr = "group"
	// HeadURL http://www.graphviz.org/content/attrs#dheadURL
	HeadURL Attr = "headURL"
	// HeadLP http://www.graphviz.org/content/attrs#dhead_lp
	HeadLP Attr = "head_lp"
	// HeadClip http://www.graphviz.org/content/attrs#dheadclip
	HeadClip Attr = "headclip"
	// HeadHREF http://www.graphviz.org/content/attrs#dheadhref
	HeadHREF Attr = "headhref"
	// HeadLabel http://www.graphviz.org/content/attrs#dheadlabel
	HeadLabel Attr = "headlabel"
	// HeadPort http://www.graphviz.org/content/attrs#dheadport
	HeadPort Attr = "headport"
	// HeadTarget http://www.graphviz.org/content/attrs#dheadtarget
	HeadTarget Attr = "headtarget"
	// HeadTooltip http://www.graphviz.org/content/attrs#dheadtooltip
	HeadTooltip Attr = "headtooltip"
	// Height http://www.graphviz.org/content/attrs#dheight
	Height Attr = "height"
	// HREF http://www.graphviz.org/content/attrs#dhref
	HREF Attr = "href"
	// ID http://www.graphviz.org/content/attrs#did
	ID Attr = "id"
	// Image http://www.graphviz.org/content/attrs#dimage
	Image Attr = "image"
	// ImagePath http://www.graphviz.org/content/attrs#dimagepath
	ImagePath Attr = "imagepath"
	// ImageScale http://www.graphviz.org/content/attrs#dimagescale
	ImageScale Attr = "imagescale"
	// InputScale http://www.graphviz.org/content/attrs#dinputscale
	InputScale Attr = "inputscale"
	// Label http://www.graphviz.org/content/attrs#dlabel
	Label Attr = "label"
	// LabelURL http://www.graphviz.org/content/attrs#dlabelURL
	LabelURL Attr = "labelURL"
	// LabelScheme http://www.graphviz.org/content/attrs#dlabel_scheme
	LabelScheme Attr = "label_scheme"
	// LabelAngle http://www.graphviz.org/content/attrs#dlabelangle
	LabelAngle Attr = "labelangle"
	// LabelDistance http://www.graphviz.org/content/attrs#dlabeldistance
	LabelDistance Attr = "labeldistance"
	// LabelFloat http://www.graphviz.org/content/attrs#dlabelfloat
	LabelFloat Attr = "labelfloat"
	// LabelFontColor http://www.graphviz.org/content/attrs#dlabelfontcolor
	LabelFontColor Attr = "labelfontcolor"
	// LabelFontName http://www.graphviz.org/content/attrs#dlabelfontname
	LabelFontName Attr = "labelfontname"
	// LabelFontSize http://www.graphviz.org/content/attrs#dlabelfontsize
	LabelFontSize Attr = "labelfontsize"
	// LabelHREF http://www.graphviz.org/content/attrs#dlabelhref
	LabelHREF Attr = "labelhref"
	// LabelJust http://www.graphviz.org/content/attrs#dlabeljust
	LabelJust Attr = "labeljust"
	// LabelLOC http://www.graphviz.org/content/attrs#dlabelloc
	LabelLOC Attr = "labelloc"
	// LabelTarget http://www.graphviz.org/content/attrs#dlabeltarget
	LabelTarget Attr = "labeltarget"
	// LabelTooltip http://www.graphviz.org/content/attrs#dlabeltooltip
	LabelTooltip Attr = "labeltooltip"
	// Landscape http://www.graphviz.org/content/attrs#dlandscape
	Landscape Attr = "landscape"
	// Layer http://www.graphviz.org/content/attrs#dlayer
	Layer Attr = "layer"
	// LayerListSep http://www.graphviz.org/content/attrs#dlayerlistsep
	LayerListSep Attr = "layerlistsep"
	// Layers http://www.graphviz.org/content/attrs#dlayers
	Layers Attr = "layers"
	// LayerSelect http://www.graphviz.org/content/attrs#dlayerselect
	LayerSelect Attr = "layerselect"
	// LayerSep http://www.graphviz.org/content/attrs#dlayersep
	LayerSep Attr = "layersep"
	// Layout http://www.graphviz.org/content/attrs#dlayout
	Layout Attr = "layout"
	// Len http://www.graphviz.org/content/attrs#dlen
	Len Attr = "len"
	// Levels http://www.graphviz.org/content/attrs#dlevels
	Levels Attr = "levels"
	// LevelsGap http://www.graphviz.org/content/attrs#dlevelsgap
	LevelsGap Attr = "levelsgap"
	// LHead http://www.graphviz.org/content/attrs#dlhead
	LHead Attr = "lhead"
	// LHeight http://www.graphviz.org/content/attrs#dlheight
	LHeight Attr = "lheight"
	// LP http://www.graphviz.org/content/attrs#dlp
	LP Attr = "lp"
	// LTail http://www.graphviz.org/content/attrs#dltail
	LTail Attr = "ltail"
	// LWidth http://www.graphviz.org/content/attrs#dlwidth
	LWidth Attr = "lwidth"
	// Margin http://www.graphviz.org/content/attrs#dmargin
	Margin Attr = "margin"
	// MaxIter http://www.graphviz.org/content/attrs#dmaxiter
	MaxIter Attr = "maxiter"
	// MCLimit http://www.graphviz.org/content/attrs#dmclimit
	MCLimit Attr = "mclimit"
	// MinDist http://www.graphviz.org/content/attrs#dmindist
	MinDist Attr = "mindist"
	// MinLen http://www.graphviz.org/content/attrs#dmindist
	MinLen Attr = "minlen"
	// Mode http://www.graphviz.org/content/attrs#dmode
	Mode Attr = "mode"
	// Model http://www.graphviz.org/content/attrs#dmodel
	Model Attr = "model"
	// Mosek http://www.graphviz.org/content/attrs#dmosek
	Mosek Attr = "mosek"
	// NewRank http://www.graphviz.org/content/attrs#dnewrank
	NewRank Attr = "newrank"
	// NodeSep http://www.graphviz.org/content/attrs#dnodesep
	NodeSep Attr = "nodesep"
	// NoJustify http://www.graphviz.org/content/attrs#dnojustify
	NoJustify Attr = "nojustify"
	// Normalize http://www.graphviz.org/content/attrs#dnormalize
	Normalize Attr = "normalize"
	// NoTranslate http://www.graphviz.org/content/attrs#dnotranslate
	NoTranslate Attr = "notranslate"
	// NSLimit http://www.graphviz.org/content/attrs#dnslimit
	NSLimit Attr = "nslimit"
	// NSLimit1 http://www.graphviz.org/content/attrs#dnslimit1
	NSLimit1 Attr = "nslimit1"
	// Ordering http://www.graphviz.org/content/attrs#dnslimit1
	Ordering Attr = "ordering"
	// Orientation http://www.graphviz.org/content/attrs#dorientation
	Orientation Attr = "orientation"
	// OutputOrder http://www.graphviz.org/content/attrs#doutputorder
	OutputOrder Attr = "outputorder"
	// Overlap http://www.graphviz.org/content/attrs#doverlap
	Overlap Attr = "overlap"
	// OverlapScaling http://www.graphviz.org/content/attrs#doverlap_scaling
	OverlapScaling Attr = "overlap_scaling"
	// OverlapShrink http://www.graphviz.org/content/attrs#doverlap_shrink
	OverlapShrink Attr = "overlap_shrink"
	// Pack http://www.graphviz.org/content/attrs#dpack
	Pack Attr = "pack"
	// PackMode http://www.graphviz.org/content/attrs#dpackmode
	PackMode Attr = "packmode"
	// Pad http://www.graphviz.org/content/attrs#dpad
	Pad Attr = "pad"
	// Page http://www.graphviz.org/content/attrs#dpage
	Page Attr = "page"
	// PageDir http://www.graphviz.org/content/attrs#dpagedir
	PageDir Attr = "pagedir"
	// PenColor http://www.graphviz.org/content/attrs#dpencolor
	PenColor Attr = "pencolor"
	// PenWidth http://www.graphviz.org/content/attrs#dpenwidth
	PenWidth Attr = "penwidth"
	// Peripheries http://www.graphviz.org/content/attrs#dperipheries
	Peripheries Attr = "peripheries"
	// Pin http://www.graphviz.org/content/attrs#dperipheries
	Pin Attr = "pin"
	// Pos http://www.graphviz.org/content/attrs#dpos
	Pos Attr = "pos"
	// QuadTree http://www.graphviz.org/content/attrs#dquadtree
	QuadTree Attr = "quadtree"
	// Quantum http://www.graphviz.org/content/attrs#dquantum
	Quantum Attr = "quantum"
	// Rank http://www.graphviz.org/content/attrs#drank
	Rank Attr = "rank"
	// RankDir http://www.graphviz.org/content/attrs#drankdir
	RankDir Attr = "rankdir"
	// RankSep http://www.graphviz.org/content/attrs#dranksep
	RankSep Attr = "ranksep"
	// Ratio http://www.graphviz.org/content/attrs#dratio
	Ratio Attr = "ratio"
	// Rects http://www.graphviz.org/content/attrs#drects
	Rects Attr = "rects"
	// Regular http://www.graphviz.org/content/attrs#dregular
	Regular Attr = "regular"
	// ReMinCross http://www.graphviz.org/content/attrs#dremincross
	ReMinCross Attr = "remincross"
	// RepulsiveForce http://www.graphviz.org/content/attrs#drepulsiveforce
	RepulsiveForce Attr = "repulsiveforce"
	// Resolution http://www.graphviz.org/content/attrs#dresolution
	Resolution Attr = "resolution"
	// Root http://www.graphviz.org/content/attrs#droot
	Root Attr = "root"
	// Rotate http://www.graphviz.org/content/attrs#drotate
	Rotate Attr = "rotate"
	// Rotation http://www.graphviz.org/content/attrs#drotation
	Rotation Attr = "rotation"
	// SameHead http://www.graphviz.org/content/attrs#dsamehead
	SameHead Attr = "samehead"
	// SameTail http://www.graphviz.org/content/attrs#dsametail
	SameTail Attr = "sametail"
	// SamplePoints http://www.graphviz.org/content/attrs#dsamplepoints
	SamplePoints Attr = "samplepoints"
	// Scale http://www.graphviz.org/content/attrs#dscale
	Scale Attr = "scale"
	// SearchSize http://www.graphviz.org/content/attrs#dsearchsize
	SearchSize Attr = "searchsize"
	// Sep http://www.graphviz.org/content/attrs#dsep
	Sep Attr = "sep"
	// Shape http://www.graphviz.org/content/attrs#dshape
	Shape Attr = "shape"
	// ShapeFile http://www.graphviz.org/content/attrs#dshapefile
	ShapeFile Attr = "shapefile"
	// ShowBoxes http://www.graphviz.org/content/attrs#dshowboxes
	ShowBoxes Attr = "showboxes"
	// Sides http://www.graphviz.org/content/attrs#dsides
	Sides Attr = "sides"
	// Size http://www.graphviz.org/content/attrs#dsize
	Size Attr = "size"
	// Skew http://www.graphviz.org/content/attrs#dskew
	Skew Attr = "skew"
	// Smoothing http://www.graphviz.org/content/attrs#dsmoothing
	Smoothing Attr = "smoothing"
	// SortV http://www.graphviz.org/content/attrs#dsortv
	SortV Attr = "sortv"
	// Splines http://www.graphviz.org/content/attrs#dsplines
	Splines Attr = "splines"
	// Start http://www.graphviz.org/content/attrs#dstart
	Start Attr = "start"
	// Style http://www.graphviz.org/content/attrs#dstyle
	Style Attr = "style"
	// StyleSheet http://www.graphviz.org/content/attrs#dstylesheet
	StyleSheet Attr = "stylesheet"
	// TailURL http://www.graphviz.org/content/attrs#dtailURL
	TailURL Attr = "tailURL"
	// TailLP http://www.graphviz.org/content/attrs#dtail_lp
	TailLP Attr = "tail_lp"
	// TailClip http://www.graphviz.org/content/attrs#dtailclip
	TailClip Attr = "tailclip"
	// TailHREF http://www.graphviz.org/content/attrs#dtailhref
	TailHREF Attr = "tailhref"
	// TailLabel http://www.graphviz.org/content/attrs#dtaillabel
	TailLabel Attr = "taillabel"
	// TailPort http://www.graphviz.org/content/attrs#dtailport
	TailPort Attr = "tailport"
	// TailTarget http://www.graphviz.org/content/attrs#dtailtarget
	TailTarget Attr = "tailtarget"
	// TailTooltip http://www.graphviz.org/content/attrs#dtailtooltip
	TailTooltip Attr = "tailtooltip"
	// Target http://www.graphviz.org/content/attrs#dtarget
	Target Attr = "target"
	// Tooltip http://www.graphviz.org/content/attrs#dtooltip
	Tooltip Attr = "tooltip"
	// TrueColor http://www.graphviz.org/content/attrs#dtooltip
	TrueColor Attr = "truecolor"
	// Vertices http://www.graphviz.org/content/attrs#dvertices
	Vertices Attr = "vertices"
	// ViewPort http://www.graphviz.org/content/attrs#dviewport
	ViewPort Attr = "viewport"
	// VoroMargin http://www.graphviz.org/content/attrs#dvoro_margin
	VoroMargin Attr = "voro_margin"
	// Weight http://www.graphviz.org/content/attrs#dweight
	Weight Attr = "weight"
	// Width http://www.graphviz.org/content/attrs#dwidth
	Width Attr = "width"
	// XDotVersion http://www.graphviz.org/content/attrs#dxdotversion
	XDotVersion Attr = "xdotversion"
	// XLabel http://www.graphviz.org/content/attrs#dxlabel
	XLabel Attr = "xlabel"
	// XLP http://www.graphviz.org/content/attrs#dxlp
	XLP Attr = "xlp"
	// Z http://www.graphviz.org/content/attrs#dz
	Z Attr = "z"

	// MinCross is not in the documentation, but found in the Ped_Lion_Share (lion_share.gv.txt) example
	MinCross Attr = "mincross"
	// SSize is not in the documentation, but found in the siblings.gv.txt example
	SSize Attr = "ssize"
	// Outline is not in the documentation, but found in the siblings.gv.txt example
	Outline Attr = "outline"
	// F is not in the documentation, but found in the transparency.gv.txt example
	F Attr = "f"
)

func NewAttr

func NewAttr(key string) (Attr, error)

NewAttr creates a new attribute key by checking whether it is a valid key

type Attrs

type Attrs map[Attr]string

Attrs represents attributes for an Edge, Node or Graph.

func NewAttrs

func NewAttrs(m map[string]string) (Attrs, error)

NewAttrs creates an empty Attributes type.

func (Attrs) Add

func (attrs Attrs) Add(field string, value string) error

Add adds an attribute name and value.

func (Attrs) Ammend

func (attrs Attrs) Ammend(more Attrs)

Ammend only adds the missing attributes to attrs Attrs type.

func (Attrs) Copy

func (attrs Attrs) Copy() Attrs

Copy returns a copy of the attributes map

func (Attrs) Extend

func (attrs Attrs) Extend(more Attrs)

Extend adds the attributes into attrs Attrs type overwriting duplicates.

type Edge

type Edge struct {
	Src     string
	SrcPort string
	Dst     string
	DstPort string
	Dir     bool
	Attrs   Attrs
}

Edge represents an Edge.

type Edges

type Edges struct {
	SrcToDsts map[string]map[string][]*Edge
	DstToSrcs map[string]map[string][]*Edge
	Edges     []*Edge
}

Edges represents a set of Edges.

func NewEdges

func NewEdges() *Edges

NewEdges creates a blank set of Edges.

func (*Edges) Add

func (edges *Edges) Add(edge *Edge)

Add adds an Edge to the set of Edges.

func (Edges) Sorted

func (edges Edges) Sorted() []*Edge

Sorted returns a sorted list of Edges.

type Escape

type Escape struct {
	*Graph
}

Escape is just a Graph that escapes some strings when required.

func NewEscape

func NewEscape() *Escape

NewEscape returns a graph which will try to escape some strings when required

func (*Escape) AddAttr

func (escape *Escape) AddAttr(parentGraph string, field, value string) error

AddAttr adds an attribute and escapes the parentGraph, field and value, if needed.

func (*Escape) AddEdge

func (escape *Escape) AddEdge(src, dst string, directed bool, attrs map[string]string) error

AddEdge adds an edge and escapes the src, dst and attrs, if needed.

func (*Escape) AddNode

func (escape *Escape) AddNode(parentGraph string, name string, attrs map[string]string) error

AddNode adds a node and escapes the parentGraph, name and attrs, if needed.

func (*Escape) AddPortEdge

func (escape *Escape) AddPortEdge(src, srcPort, dst, dstPort string, directed bool, attrs map[string]string) error

AddPortEdge adds an edge with ports and escapes the src, dst and attrs, if needed.

func (*Escape) AddSubGraph

func (escape *Escape) AddSubGraph(parentGraph string, name string, attrs map[string]string) error

AddSubGraph adds a subgraph and escapes the parentGraph, name and attrs, if needed.

func (*Escape) IsNode

func (escape *Escape) IsNode(name string) bool

IsNode returns whether the, escaped if needed, name is a node in the graph.

func (*Escape) IsSubGraph

func (escape *Escape) IsSubGraph(name string) bool

IsSubGraph returns whether the, escaped if needed, name is a subgraph in the grahp.

func (*Escape) SetName

func (escape *Escape) SetName(name string) error

SetName sets the graph name and escapes it, if needed.

type Graph

type Graph struct {
	Attrs     Attrs
	Name      string
	Directed  bool
	Strict    bool
	Nodes     *Nodes
	Edges     *Edges
	SubGraphs *SubGraphs
	Relations *Relations
}

Graph is the analysed representation of the Graph parsed from the DOT format.

func NewAnalysedGraph

func NewAnalysedGraph(graph *ast.Graph) (*Graph, error)

NewAnalysedGraph creates a Graph structure by analysing an Abstract Syntax Tree representing a parsed graph.

func NewGraph

func NewGraph() *Graph

NewGraph creates a new empty graph, ready to be populated.

Example
g := NewGraph()
if err := g.SetName("G"); err != nil {
	panic(err)
}
if err := g.SetDir(true); err != nil {
	panic(err)
}
if err := g.AddNode("G", "Hello", nil); err != nil {
	panic(err)
}
if err := g.AddNode("G", "World", nil); err != nil {
	panic(err)
}
if err := g.AddEdge("Hello", "World", true, nil); err != nil {
	panic(err)
}
s := g.String()
fmt.Println(s)
Output:

digraph G {
	Hello->World;
	Hello;
	World;

}

func Read

func Read(buf []byte) (*Graph, error)

Read parses and creates a new Graph from the data.

Example
g, err := Read([]byte(`digraph G {Hello->World}`))
if err != nil {
	panic(err)
}
s := g.String()
fmt.Println(s)
Output:

digraph G {
	Hello->World;
	Hello;
	World;

}

func (*Graph) AddAttr

func (g *Graph) AddAttr(parentGraph string, field string, value string) error

AddAttr adds an attribute to a graph/subgraph.

func (*Graph) AddEdge

func (g *Graph) AddEdge(src, dst string, directed bool, attrs map[string]string) error

AddEdge adds an edge to the graph from node src to node dst. This does not imply the adding of missing nodes. If directed is set to true then SetDir(true) must also be called or there will be a syntax error in the output.

func (*Graph) AddNode

func (g *Graph) AddNode(parentGraph string, name string, attrs map[string]string) error

AddNode adds a node to a graph/subgraph. If not subgraph exists use the name of the main graph. This does not imply the adding of a missing subgraph.

func (*Graph) AddPortEdge

func (g *Graph) AddPortEdge(src, srcPort, dst, dstPort string, directed bool, attrs map[string]string) error

AddPortEdge adds an edge to the graph from node src to node dst. srcPort and dstPort are the port the node ports, leave as empty strings if it is not required. This does not imply the adding of missing nodes.

func (*Graph) AddSubGraph

func (g *Graph) AddSubGraph(parentGraph string, name string, attrs map[string]string) error

AddSubGraph adds a subgraph to a graph/subgraph.

func (*Graph) IsNode

func (g *Graph) IsNode(name string) bool

IsNode returns whether a given node name exists as a node in the graph.

func (*Graph) IsSubGraph

func (g *Graph) IsSubGraph(name string) bool

IsSubGraph returns whether a given subgraph name exists as a subgraph in the graph.

func (*Graph) SetDir

func (g *Graph) SetDir(dir bool) error

SetDir sets whether the graph is directed (true) or undirected (false).

func (*Graph) SetName

func (g *Graph) SetName(name string) error

SetName sets the graph name.

func (*Graph) SetStrict

func (g *Graph) SetStrict(strict bool) error

SetStrict sets whether a graph is strict. If the graph is strict then multiple edges are not allowed between the same pairs of nodes, see dot man page.

func (*Graph) String

func (g *Graph) String() string

String returns a DOT string representing the Graph.

func (*Graph) WriteAst

func (g *Graph) WriteAst() (*ast.Graph, error)

WriteAst creates an Abstract Syntrax Tree from the Graph.

type Interface

type Interface interface {
	SetStrict(strict bool) error
	SetDir(directed bool) error
	SetName(name string) error
	AddPortEdge(src, srcPort, dst, dstPort string, directed bool, attrs map[string]string) error
	AddEdge(src, dst string, directed bool, attrs map[string]string) error
	AddNode(parentGraph string, name string, attrs map[string]string) error
	AddAttr(parentGraph string, field, value string) error
	AddSubGraph(parentGraph string, name string, attrs map[string]string) error
	String() string
}

Interface allows you to parse the graph into your own structure.

type Node

type Node struct {
	Name  string
	Attrs Attrs
}

Node represents a Node.

type Nodes

type Nodes struct {
	Lookup map[string]*Node
	Nodes  []*Node
}

Nodes represents a set of Nodes.

func NewNodes

func NewNodes() *Nodes

NewNodes creates a new set of Nodes.

func (*Nodes) Add

func (nodes *Nodes) Add(node *Node)

Add adds a Node to the set of Nodes, extending the attributes of an already existing node.

func (Nodes) Sorted

func (nodes Nodes) Sorted() []*Node

Sorted returns a sorted list of nodes.

type Relations

type Relations struct {
	ParentToChildren map[string]map[string]bool
	ChildToParents   map[string]map[string]bool
}

Relations represents the relations between graphs and nodes. Each node belongs the main graph or a subgraph.

func NewRelations

func NewRelations() *Relations

NewRelations creates an empty set of relations.

func (*Relations) Add

func (relations *Relations) Add(parent string, child string)

Add adds a node to a parent graph.

func (*Relations) SortedChildren

func (relations *Relations) SortedChildren(parent string) []string

SortedChildren returns a list of sorted children of the given parent graph.

type SubGraph

type SubGraph struct {
	Attrs Attrs
	Name  string
}

SubGraph represents a Subgraph.

func NewSubGraph

func NewSubGraph(name string) *SubGraph

NewSubGraph creates a new Subgraph.

type SubGraphs

type SubGraphs struct {
	SubGraphs map[string]*SubGraph
}

SubGraphs represents a set of SubGraphs.

func NewSubGraphs

func NewSubGraphs() *SubGraphs

NewSubGraphs creates a new blank set of SubGraphs.

func (*SubGraphs) Add

func (subgraphs *SubGraphs) Add(name string)

Add adds and creates a new Subgraph to the set of SubGraphs.

func (*SubGraphs) Sorted

func (subgraphs *SubGraphs) Sorted() []*SubGraph

Sorted returns a sorted list of SubGraphs.

Directories

Path Synopsis
Abstract Syntax Tree representing the DOT grammar
Abstract Syntax Tree representing the DOT grammar
internal
parser
A parser for the DOT grammar.
A parser for the DOT grammar.

Jump to

Keyboard shortcuts

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