0

I'm trying too see whether I can use the Dot programming language to apply it to an old project of mine.

The task is simple: create a high quality graph with ease.

Unfortunately, while it has been fairly easy to implement the details of my graph, I wound up having to take loads of time just for adjusting the layout. Furthermore, it is quite unclear to me how the order of my instructions impact my graph, but it actually looks like putting the last instruction of my code at the beginning produces a completely different output!

Here is the code:

digraph {
TOP [shape=doublecircle]
TOP->TOP->{rank=same a->b->c->b->a}
a:s->c:s
a:nw->a:sw
c:ne->c:se
b:s->b:s
}

so. firstly, i finally mastered the 'get nodes to be on the same horizontal/vertical line' through ranking...

I also kinda fixed the problem of edges doing stupid interconnections (all free space below the graph for connections, and the edge winds up zig-zagging through the whole graph in an awkward way and overlapping everything?) using the direction indicators ":e" and the such (i believe they are called routes...), but it looks like graphviz isn't using them in a smart way, because the result looks funny to me.

Here is the output, how do I get it to avoid edge overlappings and make enough space for future (long) labels?

My graph

(made with dot -Tpng test.dot -o test.png)

(also, I would need to add a c->a edge at the bottom too, but adding one the "normal" way ruined everything)

TylerH
  • 20,799
  • 66
  • 75
  • 101
  • If you want high quality ("publication ready") you probably want to use LaTeX / tikz. graphviz gives you only limited control. – vaettchen Nov 28 '15 at 07:04

1 Answers1

0

You can use invisible nodes to "re-route" your edges as desired (edited as per comments below):

digraph
{
    /* layout */
    // node width to create space for longer labels
    node [ width = 1.75 ];
    { rank=same; a; b; c }

    /* nodes */
    t [ label = "TOP", shape = doublecircle, width = 1];
    a [ label = "short" ];
    b [ label = "medium" ];
    c [ label = "rather  l o n g"]
    // invisible nodes to 're-route' the edges
    x [ style = invis, shape = point, width = 0 ];
    y [ style = invis, shape = point, width = 0 ];

    /* edges */
    t -> t;
    t -> { a b c }
    t -> { a b c } [dir = back ];      // added for reverse arrows
    a -> b -> c -> b -> a;
    a:nw -> a:sw;
    c:ne -> c:se;
    b:s -> b:s;
    // put the invisible nodes at the desired places with invisible edges
    b -> x -> y [ style = invis ];
    // edges to invisible nodes must not have heads
    c:sw -> x [ arrowhead = "none" ];
    x -> a:se;
    a:s ->  y [ arrowhead = "none" ];
    y -> c:s;
}

yields

enter image description here

vaettchen
  • 7,299
  • 22
  • 41
  • wow, very neat! unfortunately, i don't get why there need to be such hacks just to get the layout working with dot... are there any alternative languages anyone might recommend? – nevermindrewind__ Nov 28 '15 at 12:22
  • one more thing. changing `t -> {a b c}` to `t -> {a b c} -> t` gives me this [horrible picture](http://imgur.com/zGdzroW) ... – nevermindrewind__ Nov 28 '15 at 12:46
  • What do you want to achieve? One-liners are clever, but sometimes too clever... By the way, something wrong with an edge having arrows / pointers in both directions? – vaettchen Nov 28 '15 at 13:43
  • Alternative language - I only know LaTeX / tikz which gives you complete power but has a bit more of a learning curve. [dia](https://wiki.gnome.org/action/show/Apps/Dia?action=show&redirect=Dia) is a wysiwyg approach, I don't know it very much but I guess you could use it. Once you are heading in that direction [inkscape](http://www.inkscape.org) is highly praised. – vaettchen Nov 28 '15 at 13:48
  • add `t -> { a b c } [dir = back ];` as a third line under /* edges */. This should give you what you want instead of your "horrible picture"... Assuming that my understanding is correct, I have edited the answer and graph. – vaettchen Nov 28 '15 at 14:17
  • oh ok thanks that is what i needed! i've taken a look at tikz, and it seems to be much more precise at drawing things... – nevermindrewind__ Nov 28 '15 at 14:40