gvgen icon indicating copy to clipboard operation
gvgen copied to clipboard

Nested subgraphs are not nesting correctly.

Open hyakuhei opened this issue 3 years ago • 6 comments

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 avatar Dec 14 '21 23:12 hyakuhei

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

hyakuhei avatar Dec 15 '21 00:12 hyakuhei

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 avatar Dec 17 '21 20:12 hyakuhei

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

hyakuhei avatar Dec 18 '21 15:12 hyakuhei

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

stricaud avatar Dec 20 '21 15:12 stricaud

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.

stricaud avatar Dec 29 '21 01:12 stricaud

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

hyakuhei avatar Dec 29 '21 02:12 hyakuhei