本文整理汇总了Golang中github.com/awalterschulze/gographviz.Graph.String方法的典型用法代码示例。如果您正苦于以下问题:Golang Graph.String方法的具体用法?Golang Graph.String怎么用?Golang Graph.String使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/awalterschulze/gographviz.Graph
的用法示例。
在下文中一共展示了Graph.String方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: saveGraph
func saveGraph(g *gographviz.Graph) {
f, err := os.Create("out/" + g.Name + ".dot")
check(err)
defer f.Close()
_, err = f.WriteString(g.String())
check(err)
}
示例2: dotDump
// dotDump dumps the given image stream tree in DOT syntax
func dotDump(root *Node, g *dot.Graph, graphName string) (string, error) {
if root == nil {
return "", nil
}
// Add current node
rootNamespace, rootName, err := split(root.FullName)
if err != nil {
return "", err
}
attrs := make(map[string]string)
for _, tag := range root.Tags {
setTag(tag, attrs)
}
var tag string
// Inject tag into root's name
once.Do(func() {
tag = root.Tags[0]
})
setLabel(rootName, rootNamespace, attrs, tag)
rootName = validDOT(rootName)
g.AddNode(graphName, rootName, attrs)
// Add edges between current node and its children
for _, child := range root.Children {
for _, edge := range root.Edges {
if child.FullName == edge.To {
_, childName, err := split(child.FullName)
if err != nil {
return "", err
}
childName = validDOT(childName)
edgeNamespace, edgeName, err := split(edge.FullName)
if err != nil {
return "", err
}
edgeName = validDOT(edgeName)
edgeAttrs := make(map[string]string)
setLabel(edgeName, edgeNamespace, edgeAttrs, "")
g.AddEdge(rootName, childName, true, edgeAttrs)
}
}
// Recursively add every child and their children as nodes
if _, err := dotDump(child, g, graphName); err != nil {
return "", err
}
}
dotOutput := g.String()
// Parse DOT output for validation
if _, err := dot.Parse([]byte(dotOutput)); err != nil {
return "", fmt.Errorf("cannot parse DOT output: %v", err)
}
return dotOutput, nil
}
示例3: Render
// Render turns *github.com/awalterschulze/gographviz.Graph into the desired format.
// It requires the dot command to be available in the system.
func Render(g *gographviz.Graph, fmt Format) (string, error) {
if _, err := exec.LookPath("dot"); err != nil {
return "", ErrNoDot
}
cmd := exec.Command("dot", "-T"+string(fmt))
var outBuf, errBuf bytes.Buffer
cmd.Stdin, cmd.Stdout, cmd.Stderr = strings.NewReader(g.String()), &outBuf, &errBuf
if err := cmd.Run(); err != nil {
return "", err
}
return outBuf.String(), nil
}