コード例 #1
0
ファイル: write.go プロジェクト: chewxy/gographviz
func appendAttrs(list ast.StmtList, attrs Attrs) ast.StmtList {
	for _, name := range attrs.SortedNames() {
		attribute, ok := common.StringToAttribute(name)
		if !ok {
			// TODO fix this
		}

		value := attrs[attribute]
		// TODO: Fix This
		// Test fails if the below is uncommented out.
		// The problem however, lies with the test, as in the documentation, all string values must be enclosed in double quotes

		// var value string
		// if attribute.TakesColor() || attribute.TakesString() {
		// 	value = fmt.Sprintf("%q", attrs[attribute])
		// } else  {
		// 	value = attrs[attribute]
		// }

		stmt := &ast.Attr{
			Field: ast.Id(name),
			Value: ast.Id(value),
		}
		list = append(list, stmt)
	}
	return list
}
コード例 #2
0
ファイル: write.go プロジェクト: cjnygard/origin
func appendAttrs(list ast.StmtList, attrs Attrs) ast.StmtList {
	for _, name := range attrs.SortedNames() {
		stmt := &ast.Attr{
			Field: ast.Id(name),
			Value: ast.Id(attrs[name]),
		}
		list = append(list, stmt)
	}
	return list
}
コード例 #3
0
ファイル: write.go プロジェクト: chewxy/gographviz
func (this *writer) Write() *ast.Graph {
	t := &ast.Graph{}
	t.Strict = this.Strict
	t.Type = ast.GraphType(this.Directed)
	t.Id = ast.Id(this.Name)

	t.StmtList = appendAttrs(t.StmtList, this.Attrs)

	for _, edge := range this.Edges.Edges {
		t.StmtList = append(t.StmtList, this.newEdgeStmt(edge))
	}

	subGraphs := this.SubGraphs.Sorted()
	for _, s := range subGraphs {
		if _, ok := this.writtenLocations[s.Name]; !ok {
			t.StmtList = append(t.StmtList, this.newSubGraph(s.Name))
		}
	}

	nodes := this.Nodes.Sorted()
	for _, n := range nodes {
		if _, ok := this.writtenLocations[n.Name]; !ok {
			t.StmtList = append(t.StmtList, this.newNodeStmt(n.Name))
		}
	}

	return t
}
コード例 #4
0
ファイル: write.go プロジェクト: chewxy/gographviz
func (this *writer) newSubGraph(name string) *ast.SubGraph {
	sub := this.SubGraphs.SubGraphs[name]
	this.writtenLocations[sub.Name] = true
	s := &ast.SubGraph{}
	s.Id = ast.Id(sub.Name)
	s.StmtList = appendAttrs(s.StmtList, sub.Attrs)
	children := this.Relations.SortedChildren(name)
	for _, child := range children {
		s.StmtList = append(s.StmtList, this.newNodeStmt(child))
	}
	return s
}