Exemplo n.º 1
0
Arquivo: graph.go Projeto: jnb666/gogp
// Layout runs the dot program to layout the graph.
// If format is "" uses dot format, else specify an output renderer, e.g. "svg".
// The Graphviz dot program must be installed in your path.
func Layout(graph *gv.Graph, format string) ([]byte, error) {
	f, err := ioutil.TempFile("", "gogp")
	if err != nil {
		return nil, err
	}
	// write to tmpfile
	w := bufio.NewWriter(f)
	fmt.Fprint(w, graph.String())
	w.Flush()
	f.Close()
	file := f.Name()
	defer os.Remove(file)
	// process with dot
	args := []string{file}
	if format != "" {
		args = append(args, "-T"+format)
	}
	var outData, errData bytes.Buffer
	cmd := exec.Command("dot", args...)
	cmd.Stdout = &outData
	cmd.Stderr = &errData
	if err := cmd.Run(); err != nil {
		if errData.Len() > 0 {
			err = errors.New(errData.String())
		}
		return nil, err
	}
	return outData.Bytes(), nil
}
Exemplo n.º 2
0
func DrawPool(graph *ggv.Graph, name string, p Pool) {
	fpath := poolPath + "/" + name
	attr := map[string]string{}
	lbl := " | <f1> HealthCheckEvery : " + p.HealthCheckEvery + " | <f2> Degraded : " + p.Degraded +
		" | <f3> Critical : " + p.Critical + " | <f4> Healthz : " + p.Healthz + " | <f5> Request : " + p.Request

	attr["shape"] = "record"
	attr["label"] = "\"{ <f0>" + name + lbl + "} \""
	attr["color"], attr["fillcolor"], attr["fontcolor"] = GetColorAttr(fpath)
	attr["fontname"] = font
	attr["style"] = "\"filled\""
	graph.AddNode(graphName, "\""+fpath+"\"", attr)
}
Exemplo n.º 3
0
func DrawTrie(graph *ggv.Graph, name string, t Trie) {
	fpath := triePath + "/" + name
	attr := map[string]string{}
	lbl := " | <f1> Rules : "
	for _, v := range t.Rules {
		lbl = lbl + v + ", "
	}
	lbl = lbl[0 : len(lbl)-2]
	attr["shape"] = "record"
	attr["label"] = "\"{ <f0>" + name + lbl + "} \""
	attr["color"], attr["fillcolor"], attr["fontcolor"] = GetColorAttr(fpath)
	attr["fontname"] = font
	attr["style"] = "\"filled\""
	graph.AddNode(graphName, "\""+fpath+"\"", attr)
}
Exemplo n.º 4
0
func DrawHosts(graph *ggv.Graph, parentName string, hosts []string) {
	fpath := poolPath + "/" + parentName + "/hosts"
	attr := map[string]string{}
	lbl := ""
	i := 1
	for _, v := range hosts {
		lbl = lbl + "| <f" + strconv.FormatInt(int64(i), 10) + "> " + v + " "
	}
	attr["shape"] = "record"
	attr["label"] = "\"{ <f0> Hosts " + lbl + "} \""
	attr["color"], attr["fillcolor"], attr["fontcolor"] = GetColorAttr(fpath)
	attr["fontname"] = font
	attr["style"] = "\"filled\""
	graph.AddNode(graphName, "\""+fpath+"\"", attr)
	graph.AddEdge("\""+poolPath+"/"+parentName+"\"", "\""+fpath+"\"", true, PoolEdgeAttr)
}
Exemplo n.º 5
0
func DrawRule(graph *ggv.Graph, name string, r Rule) {
	fpath := rulePath + "/" + name
	attr := map[string]string{}
	lbl := " | <f1> Type : " + r.Type + " | <f2> Value : " + r.Value
	if r.Pool != "" {
		lbl = lbl + "| <f3> " + StrikethroughString("Next : "+r.Next) + " | <f4> Pool : " + r.Pool
	} else {
		lbl = lbl + "| <f3> Next : " + r.Next + " | <f4> " + StrikethroughString("Pool : "+r.Pool)
	}
	attr["shape"] = "record"
	attr["label"] = "\"{ <f0>" + name + lbl + "} \""
	attr["color"], attr["fillcolor"], attr["fontcolor"] = GetColorAttr(fpath)
	attr["fontname"] = font
	attr["style"] = "\"filled\""
	graph.AddNode(graphName, "\""+fpath+"\"", attr)
}