Beispiel #1
0
func (p *dotParse) Enter(name string, n *combos.Node) error {
	if name == "SubGraph" {
		p.subgraph += 1
		return nil
	}
	p.curGraph = fmt.Sprintf("%v-%d", n.Get(1).Value.(string), p.graphId)
	// errors.Logf("DEBUG", "enter %v %v", p.curGraph, n)
	return nil
}
Beispiel #2
0
func (p *dotParse) loadVertex(n *combos.Node) (err error) {
	sid := n.Get(0).Value.(string)
	attrs := make(map[string]interface{})
	for _, attr := range n.Get(1).Children {
		name := attr.Get(0).Value.(string)
		value := attr.Get(1).Value.(string)
		attrs[name] = value
	}
	attrs["graphId"] = p.graphId
	id := p.nextId
	p.nextId++
	p.vids[sid] = id
	label := sid
	if l, has := attrs["label"]; has {
		label = l.(string)
	}
	return p.b.addVertex(id, p.labels.Color(label), label, attrs)
}
Beispiel #3
0
func (p *dotParse) edge(n *combos.Node) (err error) {
	srcSid := n.Get(0).Value.(string)
	targSid := n.Get(1).Value.(string)
	attrs := make(map[string]interface{})
	for _, attr := range n.Get(2).Children {
		name := attr.Get(0).Value.(string)
		value := attr.Get(1).Value.(string)
		attrs[name] = value
	}
	label := ""
	if l, has := attrs["label"]; has {
		label = l.(string)
	}
	attrs["label"] = label
	attrs["src"] = p.vid(srcSid)
	attrs["targ"] = p.vid(targSid)

	j, err := json.Marshal(attrs)
	if err != nil {
		return err
	}

	_, err = fmt.Fprintf(p.output, "edge	%v\n", string(j))
	return err
}
Beispiel #4
0
func (p *dotParse) loadEdge(n *combos.Node) (err error) {
	getId := func(sid string) (int32, error) {
		if _, has := p.vids[sid]; !has {
			err := p.loadVertex(combos.NewNode("Node").
				AddKid(combos.NewValueNode("ID", sid)).
				AddKid(combos.NewNode("Attrs")))
			if err != nil {
				return 0, err
			}
		}
		return p.vids[sid], nil
	}
	srcSid := n.Get(0).Value.(string)
	sid, err := getId(srcSid)
	if err != nil {
		return err
	}
	targSid := n.Get(1).Value.(string)
	tid, err := getId(targSid)
	if err != nil {
		return err
	}
	label := ""
	for _, attr := range n.Get(2).Children {
		name := attr.Get(0).Value.(string)
		if name == "label" {
			label = attr.Get(1).Value.(string)
			break
		}
	}
	return p.b.addEdge(sid, tid, p.labels.Color(label), label)
}