Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Subgraph layout in graphviz

I have code to display two subgraphs:

graph {
    rankdir=LR;
    subgraph cluster01 {
        label="t=0"
        a0 [label="A"];
        a1 [label="B"];
        a2 [label="C"];
        a5 [label="E"];
        a0 -- a1;
        a1 -- a2 ;
        a2 -- a0;
    };

    subgraph cluster02
    {
        label="t=10"
        b0 [label="A"];
        b5 [label="E"];
        b1 [label="B"];
        b2 [label="C"];

        b0 -- b1;
        b2 -- b5;
    };

    a0--b0 [style=dotted];
    a1--b1 [style=dotted];
    a2--b2 [style=dotted];
    a5--b5 [style=dotted];
}

This code displays two subgraphs like this:

http://i.stack.imgur.com/F23SY.png

But I want to have it like this:

http://i.stack.imgur.com/jUpIp.png

I hope someone will help me fix the "rankdir" to get it done.

like image 369
bdur Avatar asked Sep 17 '12 16:09

bdur


People also ask

How do you make a graph on Graphviz?

Create a graph object, assemble the graph by adding nodes and edges, and retrieve its DOT source code string. Save the source code to a file and render it with the Graphviz installation of your system. Use the view option/method to directly inspect the resulting (PDF, PNG, SVG, etc.) file with its default application.

What is rank in Graphviz?

Ranks and Subgraphs To work out the layout, Graphviz uses a system it calls "ranks". Each node is assigned a higher rank than the highest ranked node that point to it. If your rank direction is set to left to right ( rankdir=LR ), then nodes with a higher rank are placed further to the right.

What is Graphviz Neato?

NEATO is a utility that draws undirected graphs, which are common in telecommu- nications. and computer programming. It draws a graph by constructing a virtual physical model and running an iterative solver to find a low-energy configuration.

Why is Graphviz used?

Graphviz is an open-source python module that is used to create graph objects which can be completed using different nodes and edges. It is based on the DOT language of the Graphviz software and in python it allows us to download the source code of the graph in DOT language.


1 Answers

The following was achieved by using invisible edges and constraint=false on some edges:

graphviz output

graph {
    rankdir=LR;
    subgraph cluster01 {
        label="t=0";
        a0 [label="A"];
        a1 [label="B"];
        a2 [label="C"];
        a5 [label="E"];
        a0 -- a1;
        a1 -- a2;
        a2 -- a5 [style=invis];
        a2 -- a0 [constraint=false];
    };

    subgraph cluster02
    {
        label="t=10"
        b0 [label="A"];
        b5 [label="E"];
        b1 [label="B"];
        b2 [label="C"];

        b0 -- b1;
        b1 -- b2 [style=invis];
        b2 -- b5;
    };

    edge[constraint=false];
    a0--b0 [style=dotted];
    a1--b1 [style=dotted];
    a2--b2 [style=dotted];
    a5--b5 [style=dotted];
}
like image 112
marapet Avatar answered Sep 21 '22 20:09

marapet