dot

package
v0.0.0-...-e9e5634 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2018 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package dot implements GraphViz DOT marshaling and unmarshaling of graphs.

See the GraphViz DOT Guide and the DOT grammar for more information on using specific aspects of the DOT language:

DOT Guide: http://www.graphviz.org/Documentation/dotguide.pdf

DOT grammar: http://www.graphviz.org/doc/info/lang.html

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

func Marshal(g graph.Graph, name, prefix, indent string, strict bool) ([]byte, error)

Marshal returns the DOT encoding for the graph g, applying the prefix and indent to the encoding. Name is used to specify the graph name. If name is empty and g implements Graph, the returned string from DOTID will be used. If strict is true the output bytes will be prefixed with the DOT "strict" keyword.

Graph serialization will work for a graph.Graph without modification, however, advanced GraphViz DOT features provided by Marshal depend on implementation of the Node, Attributer, Porter, Attributers, Structurer, Subgrapher and Graph interfaces.

func Unmarshal

func Unmarshal(data []byte, dst encoding.Builder) error

Unmarshal parses the Graphviz DOT-encoded data and stores the result in dst.

Types

type AttributeSetters

type AttributeSetters interface {
	// DOTAttributeSetters returns the global attribute setters.
	DOTAttributeSetters() (graph, node, edge encoding.AttributeSetter)
}

AttributeSetters is implemented by graph values that can set global DOT attributes.

type Attributers

type Attributers interface {
	DOTAttributers() (graph, node, edge encoding.Attributer)
}

Attributers are graph.Graph values that specify top-level DOT attributes.

type DOTIDSetter

type DOTIDSetter interface {
	SetDOTID(id string)
}

DOTIDSetter is implemented by types that can set a DOT ID.

type Graph

type Graph interface {
	graph.Graph
	DOTID() string
}

Graph wraps named graph.Graph values.

type Node

type Node interface {
	// DOTID returns a DOT node ID.
	//
	// An ID is one of the following:
	//
	//  - a string of alphabetic ([a-zA-Z\x80-\xff]) characters, underscores ('_').
	//    digits ([0-9]), not beginning with a digit.
	//  - a numeral [-]?(.[0-9]+ | [0-9]+(.[0-9]*)?).
	//  - a double-quoted string ("...") possibly containing escaped quotes (\").
	//  - an HTML string (<...>).
	DOTID() string
}

Node is a DOT graph node.

type PortSetter

type PortSetter interface {
	// SetFromPort sets the From port and
	// compass direction of the receiver.
	SetFromPort(port, compass string) error

	// SetToPort sets the To port and compass
	// direction of the receiver.
	SetToPort(port, compass string) error
}

PortSetter is implemented by graph.Edge and graph.Line that can set the DOT port and compass directions of an edge.

type Porter

type Porter interface {
	// FromPort returns the port and compass for the
	// From node of a graph.Edge.
	FromPort() (port, compass string)

	// ToPort returns the port and compass for the
	// To node of a graph.Edge.
	ToPort() (port, compass string)
}

Porter defines the behavior of graph.Edge values that can specify connection ports for their end points. The returned port corresponds to the the DOT node port to be used by the edge, compass corresponds to DOT compass point to which the edge will be aimed.

Example
package main

import (
	"fmt"

	"gonum.org/v1/gonum/graph/encoding/dot"
	"gonum.org/v1/gonum/graph/simple"
)

type edgeWithPorts struct {
	simple.Edge
	fromPort, toPort string
}

func (e *edgeWithPorts) FromPort() (string, string) {
	return e.fromPort, ""
}

func (e *edgeWithPorts) ToPort() (string, string) {
	return e.toPort, ""
}

func main() {
	g := simple.NewUndirectedGraph()
	g.SetEdge(&edgeWithPorts{
		Edge:     simple.Edge{simple.Node(1), simple.Node(0)},
		fromPort: "p1",
		toPort:   "p2",
	})

	result, _ := dot.Marshal(g, "", "", "  ", true)
	fmt.Print(string(result))

}
Output:

strict graph {
  // Node definitions.
  0;
  1;

  // Edge definitions.
  0:p2 -- 1:p1;
}

type Structurer

type Structurer interface {
	Structure() []Graph
}

Structurer represents a graph.Graph that can define subgraphs.

type Subgrapher

type Subgrapher interface {
	Subgraph() graph.Graph
}

Subgrapher wraps graph.Node values that represent subgraphs.

Jump to

Keyboard shortcuts

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