简体   繁体   中英

Swap positions of two nodes in a GraphViz diagram (DOT)

I use the DOT language to create a diagram in R . As I get a strange result, I am interested how to swap positions of two nodes: node 8 and node c4?

The code:

digraph DAG {
    # Initialization of node attributes
    node [shape = box, color = blue]; 2; 3; 4; 

    # Revision to node attributes
    { node [shape = box,style = filled,fillcolor = yellow];  8}

    # Revision to node attributes
    { node [shape = diamond, color = "red"];  c1; c2; c3; c4}

    { rank=same; c1; c2; c3}
    { rank=same; 8; c4}

    # Initialization of edge attributes
    edge [color = green, rel = yields]

    # Edge statements
    2->c1 [headport = w]; 
    c1->c2->c3 
    c2->c1 [tailport = n, headport = n];

    8->c3  [tailport = n, headport = s];
    c3->3  [tailport = e, headport = n]; 
    c3->c2 [tailport = n, headport = n];

    3->c4  [tailport = s, headport = n];
    c4->4  [tailport = s, headport = n];
    c4->8  [tailport = w, headport = e];
}

The (incorrect) result is:

在此处输入图片说明

for "wrong way" edges you may

  • swap nodes and use attribute dir = back to invert its 'force'
  • use attribute constraint = none to disable its 'force'

in your case you substitute

8->c4  [tailport = e, headport = w, dir = back];

by either

c4->8  [tailport = w, headport = e, constraint = none];

or by

8->c4  [tailport = e, headport = w, dir = back];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM