0

Suppose I define a node:

"somenode" [xlabel="somenode"]

Is there an automatic variable, as in make such that I can write, for example (in pseudo code) something like:

"somenode" [xlabel=$@]
Chris
  • 28,822
  • 27
  • 83
  • 158
  • 1
    `m4` may come to the rescue, see [here](https://stackoverflow.com/questions/46595101/how-can-i-create-named-edge-types-in-graphviz-dot-neato/46872510#46872510) – vaettchen Feb 04 '19 at 07:14

2 Answers2

1

You can use graphviz-py to make a variable.

Code

digraph g {
{{ some_node_name = "somenode" }}

"{{= some_node_name }}" [xlabel="{{= some_node_name }}"]

}

Output

Output

Alwin
  • 786
  • 9
  • 19
  • 1
    I like it. I might also try `envsubst` if I had this problem again. Can't remember the exact context of the question. – Chris Feb 15 '22 at 22:03
0

If attribute supports type escString (which label attribute does) you can use \N for node name and \G for graph name. On edge label you can use \T for tail node name and \H for head node name.

digraph {
    Node1 [xlabel="\N"]
    Node2 -> Node3 [xlabel="\T" label="\H"]
}

Result:

Dany
  • 4,521
  • 1
  • 15
  • 32