/** * Main visit function * * Visit function to process an automaton (directed, cyclic, discontinuous * graph). No more detailed methods are defined, since the process of * visiting is highly dependent on the concrete visitor implementation. * * Optionally labels may be passed for each node in the graph, which might * be used during the rendering process. * * Returns a string, containing a DOT specification of the graph, to be * rendered with graphviz. * * @param slAutomaton $automaton * @param array $labels * @return string */ public function visit(slAutomaton $automaton, array $labels = array()) { $content = <<<EOSTYLE digraph G { node [ fontname = Arial, fontcolor = "#2e3436", fontsize = 10, style = filled, color = "#2e3436", fillcolor = "#babdb6", shape = ellipse ]; splines = true; overlap = false; EOSTYLE; foreach ($automaton->getNodes() as $node) { $content .= sprintf(" \"%s\" [label = \"%s\"]\n", $node, isset($labels[(string) $node]) ? $labels[(string) $node] : $node); } $content .= "\n"; foreach ($automaton->getNodes() as $node) { foreach ($automaton->getOutgoing($node) as $dst) { if ($automaton instanceof slTypeAutomaton) { $content .= sprintf(" \"%s\" -> \"%s\" [label = \"%s\"]\n", $node, $dst, $automaton->getEdgeLabel($node, $dst)); } else { $content .= sprintf(" \"%s\" -> \"%s\"\n", $node, $dst); } } } return $content . "}\n"; }