Graphviz: how to rotate a node (or a subgraph)?
Asked Answered
P

4

9

I am trying to have a node (or a subgraph, enclosing a node - whichever is possible/easier) rotated, like shown in this image:

desired rotated node effect

(Note that it doesn't matter to me if the "B" label is rotated - only that the 'verti-*' texts in the record [or rather, the whole record node] are rotated as shown)

 

However, the closest I can to that, is the following dot code:

digraph graphname {
    node [fontname=Monospace, fontsize=14]; 
    subgraph clusterMasterBox {
        node [shape=record];
        l1 [label = "{ horiz-1 \r| \
 horiz-2 \r| \
 horiz-3 \r| \
 horiz-4 \r} \
"];
        subgraph clusterSubRotateBox {
            rotate=90;
            node [shape=record,rotate=90];
            l2 [label = "{ verti-1 \r| \
 verti-2 \r| \
 verti-3 \r| \
 verti-4 \r} \
"];     
            label="B";
        }
    label="A"
    }
}

The only reason I have the subgraph clusterSubRotateBox there (and the only reason why it is nested inside the clusterMasterBox), is because I hoped I could assign rotation to it, but apparently I cannot - as the above code generates this image:

gviz rotate actual

So my question is - is there a way to rotate a record node; if not on its own, then maybe as a part of subgraph (or a different kind of 'object')?

Thanks in advance for any suggestions,
Cheers!

Phia answered 23/12, 2010 at 0:22 Comment(0)
E
4

there should be a "rotation" attribute on the graph object (see http://www.graphviz.org/doc/info/attrs.html#drotation) but it didn't do anything in my test. and, it would only apply to the whole graph (not cluster/subgraph) according to the docs. i guess you'd first render the subgraph to postscript and then include it in the final graph as a custom shape for a single placeholder node. if you can't get "rotation" to do its thing, surely postscript has a simple way to apply a transform (rotation in this case), probably as simple as prefixing the generated code with some coordinates definition. sorry for the handwaving but i don't have time to try it now.

Embracery answered 15/4, 2011 at 14:42 Comment(1)
Thanks for the comment, @mwx! That is the best answer so far (just a confirmation that the rotation attribute applies only to the whole graph is nice to have), so +1 and accept...Phia
B
7

If you want to rotate a single record based node then rankdir will work. I tried it for my graph,

digraph plugnoid {
    rankdir=LR;
    node[shape=Mrecord];
    plugnoid [label="swarm| {<load0> onLoad|<plugin0> Plugin|<quit0> onQuit}|{<run0>run|<rehash0>rehash}"];}

enter image description here

The rankdir can have values LR,RL and TB(default). When I changed the rankdir to TB the output changed,

enter image description here

You may want to try them on your graph to get desired results. I experienced that when I used subgraph and set different rankdir the result was not as good. Please see http://www.graphviz.org/doc/info/shapes.html#record for more details.

Barbbarba answered 16/7, 2014 at 7:3 Comment(0)
I
5

For a single node, there is the orientation attribute. I just used

node[shape=hexagon, orientation=30]

To make a hexagon with a point at the top rather than a flat top.

Unfortunately doesn't seem to work on 'record' types :-(

Immoralist answered 1/8, 2017 at 7:0 Comment(1)
This works on the shape, but unfortunately, does not rotate the label.Esterify
E
4

there should be a "rotation" attribute on the graph object (see http://www.graphviz.org/doc/info/attrs.html#drotation) but it didn't do anything in my test. and, it would only apply to the whole graph (not cluster/subgraph) according to the docs. i guess you'd first render the subgraph to postscript and then include it in the final graph as a custom shape for a single placeholder node. if you can't get "rotation" to do its thing, surely postscript has a simple way to apply a transform (rotation in this case), probably as simple as prefixing the generated code with some coordinates definition. sorry for the handwaving but i don't have time to try it now.

Embracery answered 15/4, 2011 at 14:42 Comment(1)
Thanks for the comment, @mwx! That is the best answer so far (just a confirmation that the rotation attribute applies only to the whole graph is nice to have), so +1 and accept...Phia
O
0

Graphviz does not support partial rotation - only entire graphs or polygonial nodes (https://www.graphviz.org/docs/attrs/rotate/ and https://graphviz.org/docs/attrs/orientation/). To accomplish your goal, create a separate graph for each node or cluster you want rotated, and use dot (or desired engine) to create images (png, svg, etc.) Then include each image into an node using the image attribute (https://graphviz.org/docs/attrs/image/).
Note that Graphviz only supports rotate=90, while you are asking for -90. Use some other image manipulation program to rotate the result by 180 (good grief)
of the complete graphLike so:
rotatePart1a.gv

digraph graphname {
    node [fontname=Monospace, fontsize=14];

    subgraph clusterMasterBox {
      label="A"
      {rank=same  // keep on same rank
      
        l2 [shape=plain label="" image="rotatePart1b.png"]

        node [shape=record];
        l1 [label = "{ horiz-1 \r| \
 horiz-2 \r| \
 horiz-3 \r| \
 horiz-4 \r} \
"];

    }
    }
}

rotatePart1b.gv

digraph graphname {
    rotate=90;
    node [fontname=Monospace, fontsize=14]; 
 
        subgraph clusterSubRotateBox {

            node [shape=record]  // rotation at node-level is silently ignored
            l2 [label = "{ verti-1 \r| \
 verti-2 \r| \
 verti-3 \r| \
 verti-4 \r} \
"];     
            label="B";
        }
}

Giving:
enter image description here

Oculist answered 15/6, 2022 at 3:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.