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 ¶
- func AddAttr(attr string)
- func Analyse(graph *ast.Graph, g Interface) error
- func Parse(buf []byte) (*ast.Graph, error)
- func ParseString(buf string) (*ast.Graph, error)
- type Attr
- type Attrs
- type Edge
- type Edges
- type Escape
- func (escape *Escape) AddAttr(parentGraph string, field, value string) error
- func (escape *Escape) AddEdge(src, dst string, directed bool, attrs map[string]string) error
- func (escape *Escape) AddNode(parentGraph string, name string, attrs map[string]string) error
- func (escape *Escape) AddPortEdge(src, srcPort, dst, dstPort string, directed bool, attrs map[string]string) error
- func (escape *Escape) AddSubGraph(parentGraph string, name string, attrs map[string]string) error
- func (escape *Escape) IsNode(name string) bool
- func (escape *Escape) IsSubGraph(name string) bool
- func (escape *Escape) SetName(name string) error
- type Graph
- func (g *Graph) AddAttr(parentGraph string, field string, value string) error
- func (g *Graph) AddEdge(src, dst string, directed bool, attrs map[string]string) error
- func (g *Graph) AddNode(parentGraph string, name string, attrs map[string]string) error
- func (g *Graph) AddPortEdge(src, srcPort, dst, dstPort string, directed bool, attrs map[string]string) error
- func (g *Graph) AddSubGraph(parentGraph string, name string, attrs map[string]string) error
- func (g *Graph) IsNode(name string) bool
- func (g *Graph) IsSubGraph(name string) bool
- func (g *Graph) SetDir(dir bool) error
- func (g *Graph) SetName(name string) error
- func (g *Graph) SetStrict(strict bool) error
- func (g *Graph) String() string
- func (g *Graph) WriteAst() (*ast.Graph, error)
- type Interface
- type Node
- type Nodes
- type Relations
- type SubGraph
- type SubGraphs
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Analyse ¶
Analyse analyses an Abstract Syntax Tree representing a parsed graph into a newly created graph structure Interface.
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" )
type Attrs ¶
Attrs represents attributes for an Edge, Node or Graph.
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.
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 ¶
AddAttr adds an attribute and escapes the parentGraph, field and value, if needed.
func (*Escape) AddNode ¶
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 ¶
AddSubGraph adds a subgraph and escapes the parentGraph, name and attrs, if needed.
func (*Escape) IsSubGraph ¶
IsSubGraph returns whether the, escaped if needed, name is a subgraph in the grahp.
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 ¶
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 ¶
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) AddEdge ¶
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 ¶
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 ¶
AddSubGraph adds a subgraph to a graph/subgraph.
func (*Graph) IsSubGraph ¶
IsSubGraph returns whether a given subgraph name exists as a subgraph in the graph.
func (*Graph) SetStrict ¶
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.
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 Nodes ¶
Nodes represents a set 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 (*Relations) SortedChildren ¶
SortedChildren returns a list of sorted children of the given parent graph.