drjrm3
drjrm3

Reputation: 4718

change order of nodes in subgroup in graphviz

In the following code:

digraph G { 
  splines=true;

  bpx_launch -> bpx_preproc [color=red];

  subgraph cluster_0 {
    slice01;
    slice02;
    slice03;
    slice_i;
    slice_N;
    color=black;
  }

  bpx_launch -> bpx_postproc [color=red];
  bpx_launch -> bpx_validate [color=red];
  bpx_launch -> slice01 [color=red];
  bpx_launch -> slice02 [color=red];
  bpx_launch -> slice03 [color=red];
  bpx_launch -> slice_i [color=red];
  bpx_launch -> slice_N [color=red];

  bpx_preproc -> slice01 [color=blue];
  bpx_preproc -> slice02 [color=blue];
  bpx_preproc -> slice03 [color=blue];
  bpx_preproc -> slice_i [color=blue];
  bpx_preproc -> slice_N [color=blue];

  slice01 -> bpx_postproc [color=blue];
  slice02 -> bpx_postproc [color=blue];
  slice03 -> bpx_postproc [color=blue];
  slice_i -> bpx_postproc [color=blue];
  slice_N -> bpx_postproc [color=blue];

  bpx_postproc -> bpx_validate [color=blue];
}

I end up getting slice_N, slice01, slice02, slice03, slice_i, but I would prefer slice01, slice02, slice03, slice_i, slice_N. Is there any way to change that order?

Also, how do I add a key for arrows? I would like to show a little legend which explains that "x -> y" means "x launches y" for red and "x must run before y" for blue.

EDIT: Mistakenly had the first 'bpx_launch' as 'bpx' so it didn't make sense - it should all read as 'bpx_launch' - there should be no node named 'bpx'

Upvotes: 1

Views: 183

Answers (1)

stefan
stefan

Reputation: 3759

Currently (version 2.38) ordering other than by rankdir is not working within clusters neither by the order of appearence nor by edges.

without clusters

digraph G { 
    splines=true;

    legend [shape=plaintext label=<<table  border="0" cellborder="0"><tr><td><font color="red">- launches</font></td></tr><tr><td><font color="blue">- runs before</font></td></tr></table>> ]

    { rank=same color=black
        slice01 -> slice02 -> slice03 -> slice_i -> slice_N [style=invis]
    }

    edge [color=red]
    bpx_launch -> bpx_preproc;
    bpx_launch -> bpx_postproc;
    bpx_launch -> bpx_validate;
    bpx_launch -> slice01;
    bpx_launch -> slice02;
    bpx_launch -> slice03;
    bpx_launch -> slice_i;
    bpx_launch -> slice_N;

    edge [color=blue]
    bpx_preproc -> slice01;
    bpx_preproc -> slice02;
    bpx_preproc -> slice03;
    bpx_preproc -> slice_i;
    bpx_preproc -> slice_N;
    slice01 -> bpx_postproc;
    slice02 -> bpx_postproc;
    slice03 -> bpx_postproc;
    slice_i -> bpx_postproc;
    slice_N -> bpx_postproc;
    bpx_postproc -> bpx_validate;
}

you get

enter image description here

Upvotes: 1

Related Questions