Skip to content

Cannot create a mixed directed/undirected graph #114

@marco-brandizi

Description

@marco-brandizi

I'm trying to build a graph programmatically that has both directed and undirected edges. Following this suggestion, I've tried to create two subgraphs and add them into a top container:

MutableGraph containerGraph = Factory.mutGraph ()
	.setDirected ( true )
	.graphAttrs ().add ( RankDir.LEFT_TO_RIGHT );

// Shoul yield A->B
MutableGraph digraph = Factory.mutGraph ().setDirected ( true ).graphAttrs ().add ( RankDir.LEFT_TO_RIGHT );
digraph.add ( Factory.mutNode ( "A" ).addLink ( Factory.mutNode ( "B" ) ) );

// Should yield A-C
MutableGraph graph = Factory.mutGraph ().setDirected ( false ).graphAttrs ().add ( RankDir.LEFT_TO_RIGHT );
graph.add ( Factory.mutNode ( "A" ).addLink ( Factory.mutNode ( "C" ) ) );

containerGraph.add ( digraph );
containerGraph.add ( graph );

Graphviz viz = Graphviz.fromGraph ( containerGraph );
viz.render ( Format.PLAIN ).toOutputStream ( new FileOutputStream ( "target/dot-merge-test.dot" ) );
viz.render ( Format.PNG ).toOutputStream ( new FileOutputStream ( "target/dot-merge-test.png" ) );

I expected the result to have nested subgraph blocks, but the result has everything merged into a single graph, which of edges are all directed (as per the top container):

graph 1 2 1.25
node A 0.375 0.625 0.75 0.5 A solid ellipse black lightgrey
node B 1.625 1 0.75 0.5 B solid ellipse black lightgrey
node C 1.625 0.25 0.75 0.5 C solid ellipse black lightgrey
edge A B 4 0.72287 0.72747 0.85327 0.76748 1.005 0.81404 1.1458 0.85724 solid black
edge A C 4 0.72287 0.52253 0.85327 0.48252 1.005 0.43596 1.1458 0.39276 solid black
stop

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions