/** * Will return the script required by GraphViz (dot) to render the graph * * @param StateMachine $sm * @return string */ public function render(StateMachine $sm) { $graph = new Digraph('G'); $graph->set('truecolor', true); foreach ($sm->getStates() as $state) { $graph->node($state->getValue(), $this->renderState($state, $this->profile['states'])); } foreach ($sm->getStates() as $state) { /** @var Event[] $connectors */ $connectors = array_merge($state->getEvents(), $state->getTimeOuts()); foreach ($connectors as $event) { $p = $this->profile['events']['default']; foreach ($this->profile['events']['exclusiveRoles'] as $exclusiveRole => $roleProfile) { if ($event->isExclusiveTo($exclusiveRole)) { $p = array_merge($p, $roleProfile); break; } } if ($event instanceof Timeout) { $p = array_merge($p, $this->profile['events']['timeout']); } elseif ($event->isRefresh()) { $p = array_merge($p, $this->profile['events']['refresh']); } $fontcolor = $p['fontcolor']; $fillcolor = $p['fillcolor']; $color = $p['color']; $style = $p['style']; $graph->edge([$state->getValue(), $event->getTarget()], ['label' => chr(1) . '<<table border="0" cellspacing="0" cellpadding="2"><tr><td>' . $event->getLabel() . '</td></tr></table>>', 'margin' => 10, 'arrowsize' => 0.6, 'fontsize' => 9, 'fontname' => 'Helvetica Neue', 'fontcolor' => $fontcolor, 'fillcolor' => $fillcolor, 'color' => $color, 'style' => $style]); } } return $graph->render(); }
/** * Returns the dot representation of a state machine. * * @param StateMachine $stateMachine The state machine to dump. * * @return string */ public function render(StateMachine $stateMachine) { $graph = new Digraph('G'); $graph->set('rankdir', 'LR'); $this->addStates($graph, $stateMachine); $this->addTransitions($graph, $stateMachine); $graph->end(); return $graph->render(); }
/** * @expectedException InvalidArgumentException * @dataProvider provideIncorrectSetUsage */ public function testIncorrectSetUsage($name) { $graph = new Digraph('G'); $graph->set($name, 'foo'); }