2

Is there a way to make a node come somewhere after another node, but without using the rank=same method? Same constrains the graph quite significantly, but after gives it a bit more freedom.

a graph

digraph G {
    rankdir=LR
    a->b->c->d
    a->x->y
    {rank = same; d; x;}
}

In this example I don't care that x is the same rank as d, just that it's after c.

A similar question has been asked before, but not answered: Python - Graphviz force rank to be at least the same

Subgraphs could be used as a grouping strategy, but I'm already using subgraphs. I don't think that a node can be in two simultaniously.

digraph G {
    rankdir=LR
    a->b->c->d
    a->x->y
    subgraph cluster_after{
        x; d; y;
    }
}

enter image description here

Both of these methods need a bit of user awareness, but what I'd realy like is to be able to say that "lighting comes after electricity" but without having to know how far after, how many nodes are in between, or how they're connected. Is this possible?

Ben
  • 12,614
  • 4
  • 37
  • 69

1 Answers1

4

If I translate "lightning comes after electricity" into "x comes after c", than you can achieve this effect by telling graphviz c -> x[ style = invis ]. That creates an invisible hierarchic relation between the two:

digraph G 
{
    rankdir = LR;
    a -> b -> c -> d;
    a -> x -> y;
    c -> x[ style = invis ];
}

produces

enter image description here

I'm not understanding well your last half sentence "but without having to know...", though. In my solution, x will alwys be one level below c, if you don't give other specific instructions.

vaettchen
  • 7,299
  • 22
  • 41