Shamless plug: the Graphviz Visual Editor. It currently cannot do what you ask since it also inserts nodes named nX where X is just a serial number, but if you have a suggestion for how an interface should work that would allow you to do what you want, I might implement it.
I can think of two ways to achieve this:
Let the user select different schemes for automatically naming inserted nodes, where one could be A, B, …, Z and continue with AA, BB, … or A1, B1, C1, …
Let the user enter the node name before inserting it.
Not all labels are valid node IDs. E.g. spaces are not allowed.
The only way to add a label today is to write it in the DOT source. Are you suggesting that the editor should detect that and change the node ID accordingly?
The only way to add a label today is to write it in the DOT source. Are you suggesting that the editor should detect that and change the node ID accordingly?
If there is no ready made tool, I guess I don’t need to reinvent the wheel start writing a parser for dot files, or? Any good APIs/packages (C/C++/Python/perl) I could leverage?
This GVPR program is lightly tested. It is not a general-purpose solution (it drops all subgraphs), but seemingly does what you want.
Command line: gvpr -f simpleRename.gvpr myfile.gv
Here is simpleRename.gvpr:
/*
Generate copy of input graph, replacing names with labels
NOTE: DOES NOT COPY SUBGRAPHS!
NOTE: ugly if you use record OR html nodes
*/
BEGIN {
int id = 0;
int cnt[];
string names[string];
string mapn (string inname, string lbl){
string s;
s = names[inname];
if (lbl==""){
print("// Error:: node ", inname, " has no label");
s=inname;
}if (cnt[lbl]>0){
print("// Error:: duplicate label >", lbl, "<");
s=inname;
}else{
if (s == "") {
s = lbl;
cnt[lbl]=1;
}
}
names[inname] = s;
//print("// mapn returning: ", s);
return s;
}
string getmapn (string inname){
string s;
s = names[inname];
if (s == "") {
print("// Error:: Edge had mapping problem with: ", inname);
}
names[inname] = s;
return s;
}
}
BEG_G {
graph_t g;
node_t aNode;
g=copy (NULL, $G);
for (aNode=fstnode($G);aNode;aNode = nxtnode(aNode)){
node (g, mapn(aNode.name, aNode.label));
}
}
E { edge (node (g, getmapn($.tail.name)), node (g, getmapn($.head.name)), ""); }
END_G {
write (g);
}