Пример #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
 /**
  * Renders the state machine.
  *
  * @param  \Finite\StateMachine\StateMachineInterface $stateMachine
  * @param  string                                     $target
  * @throws Exception
  */
 public function render(StateMachineInterface $stateMachine)
 {
     $this->graph = new Digraph('state_machine');
     $this->addNodes($stateMachine);
     $this->addEdges($stateMachine);
     $this->graph->end();
     return $this->graph->render();
 }
Пример #3
0
 public function testRender()
 {
     $graph = new Digraph('G');
     $this->assertEquals("digraph G {\n};\n", $graph->render(), "Render empty graph");
     $this->assertEquals("    digraph G {\n    };\n", $graph->render(1), "Render empty graph with indent");
     $this->assertEquals("  digraph G {\n  };\n", $graph->render(1, "  "), "Render empty graph with indent and spaces");
     $mock = $this->getMock('Alom\\Graphviz\\Digraph\\InstructionInterface', array('render'));
     $mock->expects($this->once())->method('render')->with(2, "  ")->will($this->returnValue("    foobarbaz;\n"));
     $graph->append($mock);
     $this->assertEquals("  digraph G {\n    foobarbaz;\n  };\n", $graph->render(1, "  "), "Render with statements");
 }
Пример #4
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);
 }
Пример #5
0
 /**
  * (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;
 }