Search code examples
javagraphvizdotgraph-drawing

How do I use special characters in a dot file node_id?


I am looking forward to write a script that will automatically take input from a file and declare the nodes and edges, and produce a graph that can be visualized in any visualization software.

I tried dot language and graphViz. This language uses grammar which clearly declare the nodes of the graph like this: node1;, node2; and does not allow any special character except _.

It works well in all the cases but when I want to declare a node named java.lang.object it shows grammatical error because of presence of . and I can't change its grammar.

Can anyone help me by suggestion some other language which can take input from text file and can draw a graph on any visualization software.


Solution

  • That's actually quite easy to do in graphviz, simply put some quotes around the node names. Or you may define first your node using a simple identifier and a label attribute.

    Both techniques demonstrated here:

    digraph g {
      "java.lang.object" -> "my.class";
      "my.class" -> "special < chars >";
      n1 [label="more.strange<node>names"];
      "special < chars >" -> n1;
    }