Nesting cluster subgraphs doesn't work
ondrajz opened this issue · comments
What I am trying to achive:
Code I used:
g := gographviz.NewGraph()
g.SetName("G")
g.SetDir(true)
g.AddNode("G", "Ga", nil)
g.AddNode("G", "Gb", nil)
g.AddEdge("Ga", "Gb", true, nil)
g.AddSubGraph("G", "clusterone", map[string]string{
"style": "filled",
"fillcolor": "red",
})
g.AddNode("clusterone", "sA", nil)
g.AddNode("clusterone", "sB", nil)
g.AddEdge("sA", "sB", true, nil)
g.AddSubGraph("clusterone", "clustertwo", map[string]string{
"style": "filled",
"fillcolor": "blue",
})
g.AddNode("clustertwo", "ssA", nil)
g.AddNode("clustertwo", "ssB", nil)
g.AddEdge("ssA", "ssB", true, nil)
fmt.Println(g.String())
However this is what the result looked like:
Am I doing something wrong?
I just check the source code of Graph.AddSubgraph
function and it seems you are not even using parameter parentGraph
.
...
func (this *Graph) AddSubGraph(parentGraph string, name string, attrs map[string]string) {
this.SubGraphs.Add(name)
for key, value := range attrs {
this.AddAttr(name, key, value)
}
}
...
https://github.com/awalterschulze/gographviz/blob/master/graph.go#L98
Could you please send me the dot grammar for the first picture?
Here's the dot format
for the first picture.
digraph G {
Ga->Gb;
sA->sB;
ssA->ssB;
subgraph clusterone {
fillcolor=red;
style=filled;
sA;
sB;
subgraph clustertwo {
fillcolor=blue;
style=filled;
ssA;
ssB;
}
}
Ga;
Gb;
}
I was refactoring dot output go-callvis to use the gographviz. However I needed to display type cluster inside package cluster and after realizing that it isn't possible using your package I ended up with using just simple templates
It seems the ast
can handle the subgraphs of subgraphs but it seems to be as you say. I am struggling to see how I intended to do subgraphs or subgraphs and the parentGraph is ignored. Very weird.
Hopefully this fixes the issue
057e6a5
For interest sake does this fix also solve you cluster issue?
I mean I think using a template here is fine. This is more of a graphviz dot grammar parser for go than anything else. But if there is something to fix. I should at least look into it.
I tested my previous code and it seems it's nesting properly now. That means it would fix the issue with grouping nodes in my project if I were to use this.
Thank you for help!