本文整理汇总了Golang中github.com/awalterschulze/gographviz.NewGraph函数的典型用法代码示例。如果您正苦于以下问题:Golang NewGraph函数的具体用法?Golang NewGraph怎么用?Golang NewGraph使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewGraph函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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,
)
}
*/
}
开发者ID:looztra,项目名称:gorchestrator,代码行数:50,代码来源:parser.go
示例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
}
开发者ID:irregular,项目名称:atlantis-manager,代码行数:27,代码来源:graph.go
示例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()
}
开发者ID:rossfoley,项目名称:neural-network-go,代码行数:29,代码来源:graphviz.go
示例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)
}
开发者ID:shaunstanislaus,项目名称:go-torch,代码行数:32,代码来源:graph_test.go
示例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
}
开发者ID:shaunstanislaus,项目名称:go-torch,代码行数:32,代码来源:graph.go
示例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
}
开发者ID:yonglehou,项目名称:hpipe,代码行数:59,代码来源:dot.go
示例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
}
开发者ID:go-on,项目名称:sc,代码行数:8,代码来源:synthdef.go
示例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)
}
}
开发者ID:lanrat,项目名称:naken_asm_cfg,代码行数:58,代码来源:data.go
示例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)
}
开发者ID:shaunstanislaus,项目名称:go-torch,代码行数:9,代码来源:graph_test.go
示例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)
}
开发者ID:shaunstanislaus,项目名称:go-torch,代码行数:9,代码来源:graph_test.go
示例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()
}
开发者ID:fiatjaf,项目名称:nodes,代码行数:56,代码来源:graph.go
示例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()
}
开发者ID:prattmic,项目名称:icfp2015,代码行数:10,代码来源:node_graph.go
示例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
}
开发者ID:bestform,项目名称:Nested-Set-Model,代码行数:11,代码来源:nestedSet.go
示例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
}
开发者ID:shaunstanislaus,项目名称:go-torch,代码行数:25,代码来源:graph_test.go
示例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
}
开发者ID:shaunstanislaus,项目名称:go-torch,代码行数:36,代码来源:graph_test.go
示例16: testSingleRootGraph
// The returned graph, represented in ascii:
// +----+ +----+
// | N4 | <-- | N1 | -+
// +----+ +----+ |
// | | |
// | | |
// | v |
// | +----+ |
// | | N2 | |
// | +----+ |
// | | |
// | | |
// | v |
// | +----+ |
// +------> | N3 | <+
// +----+
func testSingleRootGraph() *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", "N4", nil)
g.AddEdge("N1", "N2", true, nil)
g.AddEdge("N2", "N3", true, nil)
g.AddEdge("N4", "N3", true, nil)
g.AddEdge("N1", "N4", true, nil)
g.AddEdge("N1", "N3", true, nil)
return g
}
开发者ID:shaunstanislaus,项目名称:go-torch,代码行数:31,代码来源:graph_test.go
示例17: visualize
func visualize(data *Data) {
graphAst, _ := parser.ParseString(`digraph G {}`)
g := gographviz.NewGraph()
gographviz.Analyse(graphAst, g)
// step1 : add nodes
for node := range data.NodeMap {
g.AddNode("G", node.ID, nil)
}
// step2 : make edge from source node to target node
for _, edge := range data.GetEdges() {
g.AddEdge(edge.Src.ID, edge.Dst.ID, true, nil)
}
output := g.String()
fmt.Println(output)
}
开发者ID:postfix,项目名称:newman-sample,代码行数:18,代码来源:newman.go
示例18: testGraphWithCycles
// The returned graph, represented in ascii:
// +----+ +----+
// +> | N4 | <-- | N1 |
// | +----+ +----+
// | ^ |
// | | |
// | | v
// | | +----+
// | +------- | N2 | <+
// | +----+ |
// | | |
// | | |
// | v |
// | +----+ |
// +------------ | N3 | |
// +----+ |
// | |
// | |
// v |
// +----+ |
// | N5 | -+
// +----+
func testGraphWithCycles() *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", "N4", nil)
g.AddNode("G", "N5", nil)
g.AddEdge("N1", "N2", true, nil)
g.AddEdge("N1", "N4", true, nil)
g.AddEdge("N2", "N3", true, nil)
g.AddEdge("N2", "N4", true, nil)
g.AddEdge("N3", "N4", true, nil)
g.AddEdge("N3", "N5", true, nil)
g.AddEdge("N5", "N2", true, nil)
return g
}
开发者ID:shaunstanislaus,项目名称:go-torch,代码行数:40,代码来源:graph_test.go
示例19: printFunctionGraph
func printFunctionGraph(fgraph map[uint16]map[uint16]bool) {
fn := gographviz.NewGraph()
fname := "Functions"
fn.SetName(fname)
fn.SetDir(true)
fn.SetStrict(true)
for fnaddr := range fgraph {
fn.AddNode(fname, f(fnaddr), nil) //TODO
for calledfn := range fgraph[fnaddr] {
fn.AddEdge(f(fnaddr), f(calledfn), true, nil)
}
}
saveGraph(fn)
}
开发者ID:lanrat,项目名称:naken_asm_cfg,代码行数:19,代码来源:data.go
示例20: main
func main() {
// Creates a new graph
g := gographviz.NewGraph()
g.AddAttr("", "rankdir", "LR")
// Now read the json input
var v orchestrator.Graph
dec := json.NewDecoder(os.Stdin)
if err := dec.Decode(&v); err != nil {
panic(err)
}
// Now for each node, create a node
g.SetName(v.Name)
g.SetDir(true)
m := make(map[int]string)
// Now add every node
for i, _ := range v.Nodes {
v.Nodes[i].Name = strings.Replace(v.Nodes[i].Name, "-", "_", -1)
v.Nodes[i].Name = strings.Replace(v.Nodes[i].Name, ":", "_Method", -1)
g.AddNode("G", v.Nodes[i].Name,
map[string]string{
"id": fmt.Sprintf("\"%v\"", strconv.Itoa(v.Nodes[i].ID)),
"label": fmt.Sprintf("\"%v|%v|%v|%v\"", v.Nodes[i].Name, v.Nodes[i].Engine, v.Nodes[i].Artifact, v.Nodes[i].Args),
"shape": "\"record\"",
})
m[v.Nodes[i].ID] = v.Nodes[i].Name
}
l := v.Digraph.Dim()
for r := 0; r < l; r++ {
for c := 0; c < l; c++ {
if v.Digraph.At(r, c) == 1 {
g.AddEdge(m[r], m[c], true, nil)
}
}
}
// Now add the edges
//g.AddEdge("Hello", "World", true, nil)
s := g.String()
fmt.Println(s)
}
开发者ID:owulveryck,项目名称:gorchestrator,代码行数:41,代码来源:gorchestrator2dot.go
注:本文中的github.com/awalterschulze/gographviz.NewGraph函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论