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: https://www.graphviz.org/pdf/dotguide.pdf

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

Attribute quoting

Attributes and IDs are quoted if needed during marshalling, to conform with valid DOT syntax. Quoted IDs and attributes are unquoted during unmarshaling, so the data is kept in raw form. As an exception, quoted text with a leading `"<` and a trailing `>"` is not unquoted to ensure preservation of the string during a round-trip.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

func Marshal(g graph.Graph, name, prefix, indent string) ([]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.

    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.

    Attributes and IDs are quoted if needed during marshalling.

    func MarshalMulti

    func MarshalMulti(g graph.Multigraph, name, prefix, indent string) ([]byte, error)

      MarshalMulti returns the DOT encoding for the multigraph 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.

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

      Attributes and IDs are quoted if needed during marshalling.

      func Unmarshal

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

        Unmarshal parses the Graphviz DOT-encoded data and stores the result in dst. If the number of graphs encoded in data is not one, an error is returned and dst will hold the first graph in data.

        Attributes and IDs are unquoted during unmarshalling if appropriate.

        Example (Weighted)
        Output:
        
        {F:a T:b W:0.5}
        {F:a T:c W:1}
        

        func UnmarshalMulti

        func UnmarshalMulti(data []byte, dst encoding.MultiBuilder) error

          UnmarshalMulti parses the Graphviz DOT-encoded data as a multigraph and stores the result in dst. If the number of graphs encoded in data is not one, an error is returned and dst will hold the first graph in data.

          Attributes and IDs are unquoted during unmarshalling if appropriate.

          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 MultiStructurer

                  type MultiStructurer interface {
                  	Structure() []Multigraph
                  }

                    MultiStructurer represents a graph.Multigraph that can define subgraphs.

                    type MultiSubgrapher

                    type MultiSubgrapher interface {
                    	Subgraph() graph.Multigraph
                    }

                      MultiSubgrapher wraps graph.Node values that represent subgraphs.

                      type Multigraph

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

                        Multigraph wraps named graph.Multigraph 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 DOT node port to be used by the edge, compass corresponds to DOT compass point to which the edge will be aimed.

                              Example
                              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.