本文整理汇总了Golang中github.com/awalterschulze/gographviz.NewGraph函数的典型用法代码示例。如果您正苦于以下问题:Golang NewGraph函数的具体用法?Golang NewGraph怎么用?Golang NewGraph使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewGraph函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
var t toscalib.ServiceTemplateDefinition
err := t.Parse(os.Stdin)
if err != nil {
log.Fatal(err)
}
// Creates a new graph
g := gographviz.NewGraph()
g.AddAttr("", "rankdir", "LR")
g.SetName("G")
g.SetDir(true)
e := toscaexec.GeneratePlaybook(t)
for i, p := range e.Index {
g.AddNode("G", fmt.Sprintf("%v", i),
map[string]string{
"id": fmt.Sprintf("\"%v\"", i),
"label": fmt.Sprintf("\"%v|%v\"", p.NodeTemplate.Name, p.OperationName),
"shape": "\"record\"",
})
}
l := e.AdjacencyMatrix.Dim()
for r := 0; r < l; r++ {
for c := 0; c < l; c++ {
if e.AdjacencyMatrix.At(r, c) == 1 {
g.AddEdge(fmt.Sprintf("%v", r), fmt.Sprintf("%v", c), true, nil)
}
}
}
log.Println("here")
s := g.String()
fmt.Println(s)
/*
d, _ := yaml.Marshal(e)
fmt.Println(string(d))
*/
/*
for i, n := range e.Index {
log.Printf("[%v] %v:%v -> %v %v",
i,
n.NodeTemplate.Name,
n.OperationName,
n.NodeTemplate.Interfaces[n.InterfaceName].Operations[n.OperationName].Implementation,
n.NodeTemplate.Interfaces[n.InterfaceName].Operations[n.OperationName].Inputs,
)
}
*/
}
示例2: DotTrie
func DotTrie(name string, json bool) (string, error) {
var err error
Zk = datamodel.Zk.Conn
ZC := zCfg{map[string]Pool{}, map[string]Rule{}, map[string]Trie{}}
Edges := Edges{map[string]bool{}, map[string]bool{}, map[string]bool{}}
graph := ggv.NewGraph()
graph.SetName(graphName)
graph.SetDir(true)
result := zkGraph{graph, &ZC, &Edges}
if name == "all" {
err = ZC.ParseAllTrie()
} else {
err = ZC.ParseWholeTrie(name)
}
if err != nil {
return "{}", err
}
str, err := ZC.ToJSON()
if err != nil {
return "{}", err
}
if json {
return str, nil
}
str = result.JSONtoDot(str)
return str, nil
}
示例3: CreateGraph
func (nn NeuralNetwork) CreateGraph() string {
graph := graphviz.NewGraph()
graph.SetDir(true)
graph.SetName("NeuralNetwork")
for layerIndex, layer := range nn.layers {
for i, neuron := range layer.neurons {
name := nodeName(layerIndex, i)
attrs := make(map[string]string)
if neuron.bias != 0.0 {
attrs["label"] = label(name, neuron.bias)
}
graph.AddNode(name, name, attrs)
}
for b, neuron := range layer.neurons {
for a, weight := range neuron.weights {
if weight != 0.0 {
attrs := make(map[string]string)
attrs["label"] = fmt.Sprintf("%v", weight)
aLabel := nodeName(layerIndex-1, a)
bLabel := nodeName(layerIndex, b)
graph.AddEdge(aLabel, bLabel, true, attrs)
}
}
}
}
return graph.String()
}
示例4: TestDFSAlmostEmptyGraph
func TestDFSAlmostEmptyGraph(t *testing.T) {
g := ggv.NewGraph()
g.SetName("G")
g.AddNode("G", "N1", nil)
g.SetDir(true)
nodeToOutEdges := map[string][]*ggv.Edge{}
buffer := new(bytes.Buffer)
mockPathStringer := new(mockPathStringer)
anythingType := mock.AnythingOfType("map[string]*gographviz.Node")
mockPathStringer.On("pathAsString", []ggv.Edge{}, anythingType).Return("").Once()
searcherWithTestStringer := &defaultSearcher{
pathStringer: mockPathStringer,
}
searcherWithTestStringer.dfs(searchArgs{
root: "N1",
path: []ggv.Edge{},
nodeToOutEdges: nodeToOutEdges,
nameToNodes: g.Nodes.Lookup,
buffer: buffer,
statusMap: make(map[string]discoveryStatus),
})
correctOutput := ""
actualOutput := buffer.String()
assert.Equal(t, correctOutput, actualOutput)
mockPathStringer.AssertExpectations(t)
}
示例5: GraphAsText
// GraphAsText is the standard implementation of Grapher
func (g *defaultGrapher) GraphAsText(dotText []byte) (string, error) {
graphAst, err := parser.ParseBytes(dotText)
if err != nil {
return "", err
}
dag := ggv.NewGraph() // A directed acyclic graph
ggv.Analyse(graphAst, dag)
if len(dag.Edges.Edges) == 0 {
return "", errNoActivity
}
nodeToOutEdges := g.collectionGetter.generateNodeToOutEdges(dag)
inDegreeZeroNodes := g.collectionGetter.getInDegreeZeroNodes(dag)
nameToNodes := dag.Nodes.Lookup
buffer := new(bytes.Buffer)
statusMap := make(map[string]discoveryStatus)
for _, root := range inDegreeZeroNodes {
g.searcher.dfs(searchArgs{
root: root,
path: nil,
nodeToOutEdges: nodeToOutEdges,
nameToNodes: nameToNodes,
buffer: buffer,
statusMap: statusMap,
})
}
return buffer.String(), nil
}
示例6: Deserialize
func (this *DotSerializer) Deserialize(data []byte) (*DAG, error) {
ast, err := dotparser.ParseBytes(data)
if err != nil {
return nil, err
}
graph := dot.NewGraph()
dot.Analyse(ast, graph)
p := NewDAG(graph.Name)
for src, dests := range graph.Edges.SrcToDsts {
for dest, _ := range dests {
if orig, ok := p.Jobs[src]; !ok {
n := dotNameToDAGJob(graph, src)
n.Post = append(n.Post, dest)
p.Jobs[src] = n
} else {
orig.Post = append(orig.Post, dest)
}
if orig, ok := p.Jobs[dest]; !ok {
n := dotNameToDAGJob(graph, dest)
n.Prev = append(n.Prev, src)
p.Jobs[dest] = n
} else {
orig.Prev = append(orig.Prev, src)
}
if _, ok := p.InDegrees[src]; !ok {
p.InDegrees[src] = 0
}
if orig, ok := p.InDegrees[dest]; !ok {
p.InDegrees[dest] = 1
} else {
p.InDegrees[dest] = orig + 1
}
}
}
for _, edge := range graph.Edges.Edges {
if v, ok := edge.Attrs["nonstrict"]; ok {
nonstrict, err := util.StringToBool(strings.Trim(v, "\""))
if err != nil {
log.Error(err)
return nil, err
}
if len(edge.Src) != 0 && len(edge.Dst) != 0 {
r := NewRelation()
r.NonStrict = nonstrict
if _, ok := p.Relations[edge.Src]; !ok {
p.Relations[edge.Src] = make(map[string]*Relation)
}
p.Relations[edge.Src][edge.Dst] = r
}
}
}
return p, nil
}
示例7: newGraph
func newGraph(name string) *gographviz.Graph {
g := gographviz.NewGraph()
g.SetName(name)
g.SetDir(true)
g.AddAttr(name, "rankdir", "BT")
// g.AddAttr(name, "ordering", "in")
return g
}
示例8: printDotGraph
func printDotGraph(functions []uint16) {
brAttr1 := make(map[string]string)
//brAttr1["label"] = "T"
brAttr1["color"] = "green"
brAttr2 := make(map[string]string)
brAttr2["color"] = "red"
//brAttr2["label"] = "F"
for _, addr := range functions {
b := blockMap[addr]
fn := gographviz.NewGraph()
//fname := "\""+b.fnString()+"\""
fname := b.fnString()
fn.SetName(fname)
fn.SetDir(true)
fn.SetStrict(true)
// DFS
visited := make(map[uint16]bool)
var s stack
s.Put(addr)
for !s.Empty() {
a := s.Pop()
if !visited[a] {
visited[a] = true
fn.AddNode(fname, blockMap[a].addrString(), blockMap[a].getAttributes())
if len(blockMap[a].branches) == 1 {
if blockMap[blockMap[a].branches[0]] != nil {
fn.AddEdge(blockMap[a].addrString(), blockMap[blockMap[a].branches[0]].addrString(), true, nil)
if !visited[blockMap[a].branches[0]] {
s.Put(blockMap[a].branches[0])
}
}
}
if len(blockMap[a].branches) == 2 {
if blockMap[blockMap[a].branches[1]] != nil {
fn.AddEdge(blockMap[a].addrString(), blockMap[blockMap[a].branches[1]].addrString(), true, brAttr2)
if !visited[blockMap[a].branches[1]] {
s.Put(blockMap[a].branches[1])
}
}
if blockMap[blockMap[a].branches[0]] != nil {
fn.AddEdge(blockMap[a].addrString(), blockMap[blockMap[a].branches[0]].addrString(), true, brAttr1)
if !visited[blockMap[a].branches[0]] {
s.Put(blockMap[a].branches[0])
}
}
}
}
}
saveGraph(fn)
}
}
示例9: TestGetInDegreeZeroNodesEmptyGraph
func TestGetInDegreeZeroNodesEmptyGraph(t *testing.T) {
g := ggv.NewGraph()
g.SetName("G")
g.SetDir(true)
var correctInDegreeZeroNodes []string
actualInDegreeZeroNodes := new(defaultCollectionGetter).getInDegreeZeroNodes(g)
assert.Equal(t, correctInDegreeZeroNodes, actualInDegreeZeroNodes)
}
示例10: TestGenerateNodeToOutEdgesEmptyGraph
func TestGenerateNodeToOutEdgesEmptyGraph(t *testing.T) {
g := ggv.NewGraph()
g.SetName("G")
g.SetDir(true)
correctNodeToOutEdges := make(map[string][]*ggv.Edge)
actualNodeToOutEdges := new(defaultCollectionGetter).generateNodeToOutEdges(g)
assert.Equal(t, correctNodeToOutEdges, actualNodeToOutEdges)
}
示例11: GenerateDotString
func GenerateDotString(res []struct {
ANAME string
BNAME string
AID int
BID int
RELKIND string
RELID int
URLS []string
}, attrs url.Values) string {
attrs.Del("url")
attrs.Del("r")
// split our slice in a slice with only nodes and a slice with only rels
var splitAt int
for index, row := range res {
if row.BNAME != "" {
splitAt = index
break
}
}
graphName := "nodes"
g := gographviz.NewGraph()
g.SetName(graphName)
g.SetDir(true)
g.AddAttr(graphName, "size", "\"15,1000\"")
g.AddAttr(graphName, "ratio", "compress")
for k := range attrs {
g.AddAttr(graphName, k, attrs.Get(k))
}
// add nodes
for _, row := range res[:splitAt] {
g.AddNode(graphName, strconv.Itoa(row.AID), map[string]string{
"id": strconv.Itoa(row.AID),
"label": nodeTable(row.ANAME, row.URLS),
"shape": "box",
"fontname": "Verdana",
"fontsize": "9",
})
}
// add edges
for _, row := range res[splitAt:] {
g.AddEdge(strconv.Itoa(row.AID), strconv.Itoa(row.BID), true, map[string]string{
"id": strconv.Itoa(row.RELID),
"label": row.RELKIND,
"dir": relationshipDir(row.RELKIND),
"tooltip": row.RELKIND,
"fontname": "Verdana",
"fontsize": "9",
})
}
return g.String()
}
示例12: Graph
func (n *Node) Graph() string {
g := gographviz.NewGraph()
g.SetName("Tree")
g.SetDir(true)
g.AddNode("Tree", "root", nil)
n.addToGraph(g, "root")
return g.String()
}
示例13: ToGraphViz
func (n *Node) ToGraphViz() string {
graphAst, _ := parser.ParseString(`digraph NestedSet {}`)
graph := gographviz.NewGraph()
gographviz.Analyse(graphAst, graph)
n.addToGraphViz(graph, "NestedSet", "")
output := graph.String()
return output
}
示例14: testGraphWithClusterNodes
// The returned graph, represented in ascii:
// +----------+
// | Ignoreme |
// +----------+
// +----+ +----------+
// | N2 | <-- | N1 |
// +----+ +----------+
// |
// |
// v
// +----------+
// | N3 |
// +----------+
func testGraphWithClusterNodes() *ggv.Graph {
g := ggv.NewGraph()
g.SetName("G")
g.SetDir(true)
g.AddNode("G", "N1", nil)
g.AddNode("G", "N2", nil)
g.AddNode("G", "N3", nil)
g.AddNode("G", "Ignore me!", nil)
g.AddEdge("N1", "N2", true, nil)
g.AddEdge("N1", "N3", true, nil)
return g
}
示例15: testGraphWithTooltip
// The returned graph, represented in ascii:
// +----+
// | N1 | -+
// +----+ |
// | |
// | |
// v |
// +----+ |
// | N2 | |
// +----+ |
// | |
// | |
// v |
// +----+ |
// | N3 | |
// +----+ |
// | |
// | |
// v |
// +----+ |
// | N4 | <+
// +----+
func testGraphWithTooltip() *ggv.Graph {
g := ggv.NewGraph()
g.SetName("G")
g.SetDir(true)
g.AddNode("G", "N1", map[string]string{"tooltip": "function1"})
g.AddNode("G", "N2", map[string]string{"tooltip": "function2"})
g.AddNode("G", "N3", map[string]string{"tooltip": "function3"})
g.AddNode("G", "N4", map[string]string{"tooltip": "function4"})
g.AddEdge("N1", "N2", true, nil)
g.AddEdge("N2", "N3", true, nil)
g.AddEdge("N3", "N4", true, nil)
g.AddEdge("N1", "N4", true, nil)
return g
}