stricaud / gvgen

Graphviz Python dot generator
MIT License
40 stars 9 forks source link

Nested subgraphs are not nesting correctly. #12

Open hyakuhei opened 2 years ago

hyakuhei commented 2 years ago

I think there's a problem with subgraph creation.

A single nested set of graphs will create the expected graph, but multiple sets of nested structures do not seem to generate the correct dot.

Example of working, single nest:

from gvgen import *

graph = GvGen()

# Everything in our graph should be within this 
mainContainer = graph.newItem("Main Container")

# a2 nests under a1 which nests under mainContainer
a1 = graph.newItem("a1", mainContainer)
a2 = graph.newItem("a2", a1)
a3 = graph.newItem("a3", a2)

with open("testout.dot", 'w') as f:
    graph.dot(f)

Results in: working-example

However, an attempt to add a second set of nested objects results in unexpected results:

from gvgen import *

graph = GvGen()

# Everything in our graph should be within this 
mainContainer = graph.newItem("Main Container")

# a2 nests under a1 which nests under mainContainer
a1 = graph.newItem("a1", mainContainer)
a2 = graph.newItem("a2", a1)
a3 = graph.newItem("a3", a2)

b1 = graph.newItem("b1", mainContainer)
b2 = graph.newItem("b2", b1)
b3 = graph.newItem("b3", b2)

with open("testout.dot", 'w') as f:
    graph.dot(f)

Results in: broken-example

Which is not correct, the expected output should look closer to: expected-output

hyakuhei commented 2 years ago

Looking at https://github.com/stricaud/gvgen/issues/9 it looks like this issue arose previously, and @stricaud attempted to address.

hyakuhei commented 2 years ago

The problem lies in the browse and tree functions.

I wrote an alternative implementation here - it doesn't include styling or smartlinks but does do the nested rendering correctly - hope it helps!

hyakuhei commented 2 years ago

Demo script showing the issue: https://gist.github.com/hyakuhei/33f48cf48cc15062631634433ac7454b

stricaud commented 2 years ago

Thanks, this is indeed an issue. I have no time to fix it right now but will be on this ASAP.

stricaud commented 2 years ago

If you want to work on fixing this and publish a pull request, I would be more than happy to merge it! If not, still need to wait a little.

hyakuhei commented 2 years ago

I decided to implement my own dot-generator instead of looking to fix this in GvGen. It doesn't manage styling the same way but handles drawing, nesting and implements a similar idea to the smartLinks feature you have in GvGen.

The Dot class in util.py contains all the functionality