예제 #1
1
 /**
  * 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();
 }
예제 #2
0
 private function addTransitions(Digraph $graph, StateMachine $stateMachine)
 {
     foreach ($stateMachine->getStates() as $stateName) {
         $state = $stateMachine->getState($stateName);
         foreach ($state->getTransitions() as $transitionName) {
             $transition = $stateMachine->getTransition($transitionName);
             $graph->beginEdge(array($stateName, $transition->getState()), array('label' => $transitionName))->end();
         }
     }
 }
예제 #3
0
 public function testSubGraph()
 {
     $graph = new Digraph('G');
     $subgraph = $graph->subgraph('foo');
     $subgraph->edge(array('A', 'B'));
     $this->assertCount(1, $graph->getInstructions(), "Count of instructions");
     $this->assertTrue($subgraph instanceof Subgraph, "Subgraph return");
     $this->assertSame('foo', $subgraph->getId(), "Subgraph identifier");
     $this->assertSame($graph, $subgraph->end(), "Subgraph end");
     $this->assertEquals("subgraph foo {\n    A -> B;\n};\n", $subgraph->render(), "Subgraph rendering");
 }
예제 #4
0
파일: Builder.php 프로젝트: rodrigorm/audit
 /**
  * @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;
 }
 public function __construct(ObjectManager $manager)
 {
     parent::__construct('G');
     $this->attr('node', array('shape' => 'record'));
     $this->set('rankdir', 'LR');
     $data = $this->createData($manager);
     $clusters = array();
     foreach ($data['entities'] as $class => $entity) {
         $clusterName = $this->getCluster($class);
         if (!isset($clusters[$clusterName])) {
             $clusters[$clusterName] = $this->subgraph('cluster_' . $clusterName)->set('label', $clusterName)->set('style', 'filled')->set('color', '#eeeeee')->attr('node', array('style' => 'filled', 'color' => '#eecc88', 'fillcolor' => '#FCF0AD'));
         }
         $label = $this->getEntityLabel($class, $entity);
         $clusters[$clusterName]->node($class, array('label' => $label));
     }
     foreach ($data['relations'] as $association) {
         $attr = array();
         switch ($association['type']) {
             case 'one_to_one':
             case 'one_to_many':
             case 'many_to_one':
             case 'many_to_many':
                 $attr['color'] = '#88888888';
                 $attr['arrowhead'] = 'none';
                 break;
             case 'extends':
         }
         $this->edge(array($association['from'], $association['to']), $attr);
     }
 }
예제 #6
0
 /**
  * Adds all transitions as edges.
  *
  * @param \Finite\StateMachine\StateMachineInterface $stateMachine
  */
 private function addEdges(StateMachineInterface $stateMachine)
 {
     $states = $stateMachine->getStates();
     foreach ($states as $name) {
         $state = $stateMachine->getState($name);
         /* @var $state \Finite\State\StateInterface */
         $transitions = $state->getTransitions();
         foreach ($transitions as $name) {
             $trans = $stateMachine->getTransition($name);
             /* @var $trans Finite\Transition\TransitionInterface */
             $this->graph->beginEdge(array($state->getName(), $trans->getState()), array('label' => $trans->getName()))->end();
         }
     }
 }
예제 #7
0
 /**
  * {@inheritDoc}
  */
 public function render($indent = 0, $spaces = self::DEFAULT_INDENT)
 {
     if (isset($this->options['graph'])) {
         $this->attr('graph', $this->options['graph']);
     }
     // Only one vhost asked ?
     if (isset($this->options['vhost'])) {
         $this->buildVhost($this->options['vhost']);
         return parent::render($indent, $spaces);
     }
     $cluster = 0;
     foreach ($this->definitions['vhosts'] as $vhost) {
         $this->append(new Subgraph("cluster_{$cluster}", $this, $vhost['name'], $this->definitions));
         $cluster++;
     }
     return parent::render($indent, $spaces);
 }
예제 #8
0
 /**
  * Adds all transitions as edges.
  *
  * @param \Finite\StateMachine\StateMachineInterface $stateMachine
  */
 private function addEdges(StateMachineInterface $stateMachine)
 {
     $states = $stateMachine->getStates();
     foreach ($states as $sName) {
         $state = $stateMachine->getState($sName);
         $transitions = $state->getTransitions();
         foreach ($transitions as $tName) {
             $trans = $stateMachine->getTransition($tName);
             $attributes = $this->getEdgeDefaultAttributes($trans);
             if ($this->visitors) {
                 try {
                     foreach ($this->visitors as $visitor) {
                         $attributes = $visitor->getEdgeAttributes($attributes, $trans, $state, $stateMachine);
                     }
                 } catch (SkipElementException $ex) {
                     continue;
                 }
             }
             $this->graph->beginEdge([$state->getName(), $trans->getState()], $attributes)->end();
         }
     }
 }
예제 #9
0
 private function assertGraphWithNode()
 {
     $graph = new Digraph('class_diagram');
     $graph->node('AnNamespace\\AnClass');
     $this->assertGraph($graph);
 }
예제 #10
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);
 }
예제 #11
0
파일: Graph.php 프로젝트: mylen/graphviz
 /**
  * (non-PHPdoc)
  * @see \Alom\Graphviz\Graph::render()
  */
 public function render($indent = 0, $spaces = ' ')
 {
     $str = parent::render($indent, $spaces);
     //         if (null == $filename) {
     //             $stream = tmpfile();
     //             $meta = stream_get_meta_data($stream);
     //             $filename = $meta["uri"];
     //         } else {
     //             $stream = fopen($filename, 'w');
     //         }
     $stream = tmpfile();
     $meta = stream_get_meta_data($stream);
     $filename = $meta["uri"];
     fwrite($stream, $str);
     //         echo '<pre>';
     //         var_dump($str);
     //         echo '</pre>';
     exec($this->command . " " . $filename, $res, $status);
     if ($status !== 0) {
         echo '<p class="alert">' . var_dump($res) . '</p>';
     }
     $res = implode("\n", $res);
     return $res;
 }