/**
  * 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();
 }
Exemple #2
0
 /**
  * @return Alom\Graphviz\Digraph
  */
 private function buildGraph()
 {
     $graph = new Digraph('class_diagram');
     foreach ($this->graph as $dependent => $dependencies) {
         $graph->node($dependent);
         foreach (array_keys($dependencies) as $dependency) {
             $graph->edge(array($dependent, $dependency));
         }
     }
     return $graph;
 }
Exemple #3
0
 private function assertGraphWithNode()
 {
     $graph = new Digraph('class_diagram');
     $graph->node('AnNamespace\\AnClass');
     $this->assertGraph($graph);
 }
Exemple #4
0
 public function dot(Digraph $g, string $curPath = '')
 {
     $name = $curPath;
     if ($name == '') {
         $name = 'root';
     }
     // first, generate node about ourself
     $opt = array('label' => $name);
     if ($this->handler != null) {
         $opt['label'] .= "\n" . implode('', $this->exportHandler(array()));
     }
     $g->node($name, $opt);
     // then, generate edges and related nodes
     foreach ($this->childNodes as $k => $node) {
         $path = $k;
         $childPath = $curPath . '/' . $path;
         $g->edge(array($name, $childPath), array('label' => $path));
         $node->dot($g, $childPath);
     }
     // last, generate regexpChild
     if ($this->varChild == null) {
         return;
     }
     $childPath = $curPath . '/[var]';
     $g->edge(array($name, $childPath), array('label' => '[*]'));
     $this->varChild->dot($g, $childPath);
 }