dot: preserve the label of the nodes
It is very handy that we now have name_automaton
that allows to preserve some names for the states. Unfortunately in the case of dot
, the states have a label, and an identifier. And we record only the identifier, not the label:
import vcsn
a = vcsn.automaton('''$ -> foo
foo -> bar x
bar -> $''', strip=False)
print(a.dot())
digraph
{
vcsn_context = "letterset<char_letters(x)>, b"
rankdir = LR
edge [arrowhead = vee, arrowsize = .6]
{
node [shape = point, width = 0]
I0
F1
}
{
node [fillcolor = cadetblue1, shape = circle, style = "filled,rounded", height = 0.4, width = 0.4, fixedsize = true]
0 [label = "foo", shape = box, fixedsize = false]
1 [label = "bar", shape = box, fixedsize = false]
}
I0 -> 0
0 -> 1 [label = "x"]
1 -> F1
}
print(vcsn.automaton(a.dot(), strip=False))
digraph
{
vcsn_context = "letterset<char_letters(x)>, b"
rankdir = LR
edge [arrowhead = vee, arrowsize = .6]
{
node [shape = point, width = 0]
I0
F1
}
{
node [shape = circle, style = rounded, width = 0.5]
0 [label = "0", shape = box]
1 [label = "1", shape = box]
}
I0 -> 0
0 -> 1 [label = "x"]
1 -> F1
}
As can be seen, in the latter case, we forgot the names foo
and bar
of the states, and keep their former identifiers (0
, and 1
) as if they were the genuine names.
So we must teach our dot reader to remember both the label and the id of the nodes. If a node is unlabeled, then consider that its label is its id. But keep only the label. The difficulty is that it is the id which is used to specify the transitions, so we need to keep both.