Search code examples
graphviz

Separate attributes for edges in edge list?


I can add edge labels with attributes like so

digraph structs {
  a -> x [label="A"];
  a -> y [label="B"];
}

and I can list all edges together

digraph structs {
  a -> {x; y;}; /* or a -> x,y; */
}

but from the DOT grammar it looks like I can only specify a single set of attributes for all edges in the list

digraph structs {
  a -> {x; y;} [label="D'oh!"];
}

Because of the way that my graph is generated, I'd love to have a way to write something like

digraph structs {
  a -> x [label="X"], y [label="Y"];
}

where the edges from a to x and y are labeled X and Y, respectively. Is that possible without resorting to separate statements for each edge?


Solution

  • You can use the following syntax:

    digraph structs {
      a -> {x [label="X"]; y [label="Y"];}
    }
    

    These are actually separate statements, but it's one-line and close to what you want.