Subgraph with different rankdir

Hello community,

is it possible to change the rankdirection in various subgraphs? I' ve already tried, but it doesn't work. For example: I have levels, rooms and object in the room. I want to display the levels top to bottom (TB). A level is a subgraph whith contains various rooms, they should be arranged left to right (LR). The objects in the rooms should be arranged TB. And here is an excerpt of my code:

digraph relation {
size="10,70"
rankdir=TB
nodesep=0.7
...
..
.
subgraph cluster_firstlevel{rankdir=LR label="Level 1" fontname=...
____subgraph cluster_room1{rankdir=TB label="Room 1"... Object1[label=number1>, shape=octagon]}
____subgraph cluster_room2(rankdir=TB .........
}}
subgraph cluster_secondlevel{rankdir=LR label="Level 2" fontname=...
____subgraph cluster_room3{rankdir=TB label="Room 3"... Object3[label=number1>, shape=octagon]}
____subgraph cluster_room4(rankdir=TB .........
}}

But that doesn't yield the desired layout.

I wanted to achieve a layout like this:
___________LEVEL 1______________
|ROOM1__| |ROOM2__| |ROOM3___ROOM4___
|Obj1.1__| |Obj2.1__| |...
|Obj1.2__| |Obj2.2__| |..
|Obj1.3__| |...
|Obj1.4__| |..
___________Level 2______________

Thanks for your help.

First, clusters are not

First, clusters are not first-class objects; their position is solely determined by what they contain, so they would only be placed top-to-bottom if that is the relation between the nodes. Second, the rankdir attribute is not a cluster attribute. Once set at the root graph level, that value applies at all levels. (Both of these would be reasonable extensions, but at present, dot doesn't provide them.)
 
 
It is possible to get what you want with a bit more structure in the graph. Taking the simplest case, you get rankdir=TB automatically within rooms and, if there are no edges between objects in rooms at the same level, rooms will be placed left to right. So you just have to get the levels going top-down. You can do this by using invisible edges from the nodes in level i to the nodes in level i+1:
 
digraph G {
  subgraph cluster_level1 {
    label="Level 1"
    subgraph cluster_room1 {
        label="Room 1"
        a -> b
    }
    subgraph cluster_room2 {
        label="Room 2"
        c -> d
    }
  }
  subgraph cluster_level2 {
    label="Level 2"
    subgraph cluster_room2_1 {
        label="Room 1"
        e -> f
    }
    subgraph cluster_room2_2 {
        label="Room 2"
        g -> h
    }
  }
  {edge[style=invis]
    {b d} -> {g e}
  }
}
 
If your graph has edges between levels or rooms, the additions will be more complex but usually still doable.
 

Hello,thank you for your

Hello,
thank you for your answer. Ok, my fault to assume that subgraphs have the same attributes as graphs. I´ve tried your advice and it looks better than befor, but unfortunately i hava edges between object in room at the same level (EDP-planning in a hotel, patchpanel - accesspoints...)

I guess I have to edit the same code for the objects in rooms like that for levels:
{edge[style=invis] /*room1*/
obj1.1 -> Obj1.2 -> ...
}
{edge[style=invis] /*room2*/
obj2.1 -> Obj2.2 -> ...
}

Recent comments