dot

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

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

Go to latest
Published: Sep 1, 2021 License: MIT Imports: 5 Imported by: 18

README

dot

dot language support for Go

See http://godoc.org/github.com/tmc/dot

Todo:

  • parser
  • regression suite

The pydot library used as a reference

License: MIT

Documentation

Overview

Package dot implements an API to produce Graphviz dot language output.

Basic Graph creation:

g := dot.NewGraph("G")
g.SetType(dot.DIGRAPH)
...
g.AddEdge(dot.NewNode("A"), dot.NewNode("B"))
...
fmt.Sprint(g)

Index

Examples

Constants

This section is empty.

Variables

View Source
var AttributeError = errors.New("Invalid Attribute")

Functions

func QuoteIfNecessary

func QuoteIfNecessary(s string) (result string)

Types

type Edge

type Edge struct {
	// contains filtered or unexported fields
}

func NewEdge

func NewEdge(src, dst *Node) *Edge

func (Edge) Destination

func (e Edge) Destination() *Node

func (*Edge) Get

func (c *Edge) Get(attributeName string) string

func (*Edge) GetParentGraph

func (c *Edge) GetParentGraph() *Graph

func (Edge) Name

func (c Edge) Name() string

func (*Edge) Sequence

func (c *Edge) Sequence() int

func (*Edge) Set

func (e *Edge) Set(attributeName, attributeValue string) error

func (*Edge) SetParentGraph

func (c *Edge) SetParentGraph(g *Graph)

func (Edge) Source

func (e Edge) Source() *Node

func (Edge) String

func (e Edge) String() string

func (*Edge) Type

func (c *Edge) Type() string

type Graph

type Graph struct {
	// contains filtered or unexported fields
}

func NewGraph

func NewGraph(name string) *Graph
Example
package main

import (
	"fmt"

	"github.com/tmc/dot"
)

func main() {
	g := dot.NewGraph("G")
	g.Set("label", "Example graph")
	n1, n2 := dot.NewNode("Node1"), dot.NewNode("Node2")

	n1.Set("color", "sienna")

	g.AddNode(n1)
	g.AddNode(n2)

	e := dot.NewEdge(n1, n2)
	e.Set("dir", "both")
	g.AddEdge(e)

	fmt.Println(g)
}
Output:

digraph G {
graph [
  label="Example graph";
];
Node1 [color=sienna];
Node2;
Node1 -> Node2  [ dir=both ]
}

func (*Graph) AddEdge

func (g *Graph) AddEdge(e *Edge)

func (*Graph) AddNode

func (g *Graph) AddNode(n *Node)

func (*Graph) AddSubgraph

func (g *Graph) AddSubgraph(sg *SubGraph)

func (*Graph) Get

func (c *Graph) Get(attributeName string) string

func (*Graph) GetParentGraph

func (c *Graph) GetParentGraph() *Graph

func (*Graph) GetRoot

func (g *Graph) GetRoot() (result *Graph)

func (*Graph) GetSubgraphs

func (g *Graph) GetSubgraphs() (result []*SubGraph)

func (Graph) Name

func (c Graph) Name() string

func (*Graph) SameRank

func (g *Graph) SameRank(nodes []string)

SameRank enforces alignment of the given nodes

func (*Graph) Sequence

func (c *Graph) Sequence() int

func (*Graph) Set

func (g *Graph) Set(attributeName, attributeValue string) error

func (*Graph) SetGlobalEdgeAttr

func (g *Graph) SetGlobalEdgeAttr(attributeName, attributeValue string) error

func (*Graph) SetGlobalNodeAttr

func (g *Graph) SetGlobalNodeAttr(attributeName, attributeValue string) error

func (*Graph) SetParentGraph

func (c *Graph) SetParentGraph(g *Graph)

func (*Graph) SetType

func (g *Graph) SetType(t GraphType)

Set the type of the graph, valid values are GRAPH or DIGRAPH

func (Graph) String

func (g Graph) String() string

func (*Graph) Type

func (c *Graph) Type() string

type GraphObject

type GraphObject interface {
	Type() string
	Get(string) string
	Set(string, string) error
	GetParentGraph() *Graph
	SetParentGraph(g *Graph)
	Sequence() int
}

type GraphType

type GraphType int
const (
	DIGRAPH GraphType = iota
	GRAPH
	SUBGRAPH
)

func (GraphType) String

func (gt GraphType) String() string

type Node

type Node struct {
	// contains filtered or unexported fields
}

func NewNode

func NewNode(name string) *Node

func (*Node) Get

func (c *Node) Get(attributeName string) string

func (*Node) GetParentGraph

func (c *Node) GetParentGraph() *Graph

func (Node) Name

func (c Node) Name() string

func (*Node) Sequence

func (c *Node) Sequence() int

func (*Node) Set

func (n *Node) Set(attributeName, attributeValue string) error

func (*Node) SetParentGraph

func (c *Node) SetParentGraph(g *Graph)

func (Node) String

func (n Node) String() string

func (*Node) Type

func (c *Node) Type() string

type SubGraph

type SubGraph struct {
	Graph
}

func NewSubgraph

func NewSubgraph(name string) *SubGraph

func (*SubGraph) Get

func (c *SubGraph) Get(attributeName string) string

func (*SubGraph) GetParentGraph

func (c *SubGraph) GetParentGraph() *Graph

func (SubGraph) Name

func (c SubGraph) Name() string

func (*SubGraph) Sequence

func (c *SubGraph) Sequence() int

func (*SubGraph) SetParentGraph

func (c *SubGraph) SetParentGraph(g *Graph)

func (*SubGraph) Type

func (c *SubGraph) Type() string

Jump to

Keyboard shortcuts

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