gographviz

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2015 License: Apache-2.0, BSD-3-Clause, Apache-2.0 Imports: 10 Imported by: 0

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.

Installation

go get github.com/awalterschulze/gographviz

Tests

Build Status

Users

aptly - Debian repository management tool

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 Analyse

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

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)

Parses the buffer into a abstract syntax tree representing the graph.

Types

type Attrs

type Attrs map[string]string

Represents attributes for an Edge, Node or Graph.

func NewAttrs

func NewAttrs() Attrs

Creates an empty Attributes type.

func (Attrs) Add

func (this Attrs) Add(field string, value string)

Adds an attribute name and value.

func (Attrs) Ammend

func (this Attrs) Ammend(more Attrs)

Only adds the missing attributes to this Attrs type.

func (Attrs) Copy

func (this Attrs) Copy() Attrs

func (Attrs) Extend

func (this Attrs) Extend(more Attrs)

Adds the attributes into this Attrs type overwriting duplicates.

func (Attrs) SortedNames

func (this Attrs) SortedNames() []string

type Edge

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

Represents an Edge.

type Edges

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

Represents a set of Edges.

func NewEdges

func NewEdges() *Edges

Creates a blank set of Edges.

func (*Edges) Add

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

Adds an Edge to the set of Edges.

func (Edges) Sorted

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

Retrusn a sorted list of Edges.

type Escape

type Escape struct {
	Interface
}

func (*Escape) AddAttr

func (this *Escape) AddAttr(parentGraph string, field, value string)

func (*Escape) AddEdge

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

func (*Escape) AddNode

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

func (*Escape) AddPortEdge

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

func (*Escape) AddSubGraph

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

func (*Escape) SetName

func (this *Escape) SetName(name string)

type Graph

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

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

func NewGraph

func NewGraph() *Graph

Creates a new empty graph, ready to be populated.

Example
g := NewGraph()
g.SetName("G")
g.SetDir(true)
g.AddNode("G", "Hello", nil)
g.AddNode("G", "World", nil)
g.AddEdge("Hello", "World", true, nil)
s := g.String()
fmt.Println(s)
Output:

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

}

func (*Graph) AddAttr

func (this *Graph) AddAttr(parentGraph string, field string, value string)

Adds an attribute to a graph/subgraph.

func (*Graph) AddEdge

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

Adds an edge to the graph from node src to node dst. This does not imply the adding of missing nodes.

func (*Graph) AddNode

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

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 (this *Graph) AddPortEdge(src, srcPort, dst, dstPort string, directed bool, attrs map[string]string)

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 (this *Graph) AddSubGraph(parentGraph string, name string, attrs map[string]string)

Adds a subgraph to a graph/subgraph.

func (*Graph) IsNode

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

func (*Graph) IsSubGraph

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

func (*Graph) SetDir

func (this *Graph) SetDir(dir bool)

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

func (*Graph) SetName

func (this *Graph) SetName(name string)

Sets the graph name.

func (*Graph) SetStrict

func (this *Graph) SetStrict(strict bool)

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

Returns a DOT string representing the Graph.

func (*Graph) WriteAst

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

Creates an Abstract Syntrax Tree from the Graph.

type Interface

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

Implementing this interface allows you to parse the graph into your own structure.

func NewAnalysedGraph

func NewAnalysedGraph(graph *ast.Graph) Interface

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

func NewEscape

func NewEscape() Interface

Returns a graph which will try to escape some strings when required

func Read

func Read(buf []byte) (Interface, error)

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;

}

type Node

type Node struct {
	Name  string
	Attrs Attrs
}

Represents a Node.

type Nodes

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

Represents a set of Nodes.

func NewNodes

func NewNodes() *Nodes

Creates a new set of Nodes.

func (*Nodes) Add

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

Adds a Node to the set of Nodes, ammending the attributes of an already existing node.

func (Nodes) Sorted

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

Returns a sorted list of nodes.

type Relations

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

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

func NewRelations

func NewRelations() *Relations

Creates an empty set of relations.

func (*Relations) Add

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

Adds a node to a parent graph.

func (*Relations) SortedChildren

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

type SubGraph

type SubGraph struct {
	Attrs Attrs
	Name  string
}

Represents a Subgraph.

func NewSubGraph

func NewSubGraph(name string) *SubGraph

Creates a new Subgraph.

type SubGraphs

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

Represents a set of SubGraphs.

func NewSubGraphs

func NewSubGraphs() *SubGraphs

Creates a new blank set of SubGraphs.

func (*SubGraphs) Add

func (this *SubGraphs) Add(name string)

Adds and creates a new Subgraph to the set of SubGraphs.

func (*SubGraphs) Sorted

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

Directories

Path Synopsis
Abstract Syntax Tree representing the DOT grammar
Abstract Syntax Tree representing the DOT grammar
A parser for the DOT grammar.
A parser for the DOT grammar.
A scanner for the DOT grammar that has been derived from the standard golang scanner with extra added literals.
A scanner for the DOT grammar that has been derived from the standard golang scanner with extra added literals.

Jump to

Keyboard shortcuts

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