type dotMultiGraph struct {
*multi.DirectedGraph
}
func newDotMultiGraph() *dotMultiGraph {
return &dotMultiGraph{DirectedGraph: multi.NewDirectedGraph()}
}
func (g *dotMultiGraph) AddEdge(from, to graph.Node) graph.Line {
e := &dotLine{Line: g.DirectedGraph.NewLine(from, to), attrs: make(map[string]string)}
return e
}
func (g *dotMultiGraph) NewLine(from, to graph.Node) graph.Line {
line := g.DirectedGraph.NewLine(from, to)
dotLine := &dotLine{Line: line, attrs: make(map[string]string)}
return dotLine
}
func (g *dotMultiGraph) SetLine(e graph.Line) {
fmt.Printf("yoo: %+v\n", e.(*dotLine)) // this is where I think I would check if dir == both
g.DirectedGraph.SetLine(e.(*dotLine))
}
type dotLine struct {
graph.Line
attrs map[string]string
}
func (e *dotLine) SetAttribute(attr encoding.Attribute) error {
fmt.Printf("attr: %s\n", attr)
e.attrs[attr.Key] = attr.Value
return nil
}
func TestParsingGraphs(t *testing.T) {
ug := `
digraph "graph" {
graph [fontsize=12]
node [fontsize=12]
edge [fontsize=12]
rankdir=TB;
"N0" -> "N1" [uuid = "<Node1, Node0>", color = "#000000", fontcolor = "#000000", style = "solid", label = "edges", dir = "forward"]
"N0" -> "N2" [uuid = "<Node1, Node2>", color = "#000000", fontcolor = "#000000", style = "solid", label = "edges", dir = "both"]
"N2" -> "N1" [uuid = "<Node2, Node0>", color = "#000000", fontcolor = "#000000", style = "solid", label = "edges", dir = "forward"]
"N0" [uuid="Node1", label="Node1", color="#ffd700", fontcolor = "#000000", shape = "box", style = "filled, solid"]
"N1" [uuid="Node0", label="Node0", color="#ffd700", fontcolor = "#000000", shape = "box", style = "filled, solid"]
"N2" [uuid="Node2", label="Node2\n($cyclic_n)", color="#ffd700", fontcolor = "#000000", shape = "box", style = "filled, solid"]
}
`
// g := multi.NewDirectedGraph()
// multi.DirectedGraph
g := newDotMultiGraph()
err := dot.UnmarshalMulti([]byte(ug), g)
if err != nil {
log.Fatalf("failed to unmarshal DOT data: %v", err)
}
// cycles := topo.DirectedCyclesIn(g)
// if len(cycles) == 0 {
// t.Logf("Analysis result: %s\n", ug) // todo: handle command not found
// t.Logf("Cycles: %s", cycles)
// // Print out the nodes and edges
// t.Log("Nodes:")
// for nodes := g.Nodes(); nodes.Next(); {
// node := nodes.Node()
// t.Logf("Node ID: %v\n", node.ID())
// }
t.Log("Edges:")
for edges := g.Edges(); edges.Next(); {
edge := edges.Edge()
// t.Log(edge)
fmt.Printf("%+v\n", g.Lines(edge.From().ID(), edge.To().ID()).Line())
t.Logf("Edge from %v to %v\n", edge.From().ID(), edge.To().ID())
}
data, err := dot.Marshal(g, "Example Graph", "", "\t")
if err != nil {
log.Fatalf("error marshalling graph to DOT: %v", err)
}
t.Log(string(data))
// t.Errorf("Expected cycles to be > 0, found none")
// }
}