/**
  * @param string $name
  *
  * @return \phpDocumentor\GraphViz\Graph
  */
 private function getGraphByName($name)
 {
     $name = 'cluster_' . $name;
     if (!$this->graph->hasGraph($name)) {
         $graph = $this->graph->create($name);
         $this->graph->addGraph($graph);
     }
     return $this->graph->getGraph($name);
 }
Example #2
0
 /**
  * Convert a Graph to a phpDocumentor graph, usable for printing
  *
  * @param \Gliph\Graph\Digraph $graph The graph to print
  *
  * @return \phpDocumentor\GraphViz\Graph The copied graph
  */
 protected function convertGraph(Digraph $graph)
 {
     $new = Graph::create("dump");
     $nodes = new \SplObjectStorage();
     $ctr = 0;
     foreach ($graph->vertices() as $vertex) {
         $nodes[$vertex] = Node::create('node_' . $ctr++, (string) $vertex);
         $new->setNode($nodes[$vertex]);
     }
     foreach ($graph->edges() as $edge) {
         $new->link(Edge::create($nodes[$edge[0]], $nodes[$edge[1]]));
     }
     return $new;
 }
Example #3
0
 /**
  * Builds a tree of namespace subgraphs with their classes associated.
  *
  * @param GraphVizGraph       $graph
  * @param NamespaceDescriptor $namespace
  *
  * @return void
  */
 protected function buildNamespaceTree(GraphVizGraph $graph, NamespaceDescriptor $namespace)
 {
     $full_namespace_name = $namespace->getFullyQualifiedStructuralElementName();
     if ($full_namespace_name == '\\') {
         $full_namespace_name = 'Global';
     }
     $sub_graph = GraphVizGraph::create('cluster_' . $full_namespace_name)->setLabel($namespace->getName() == '\\' ? 'Global' : $namespace->getName())->setStyle('rounded')->setColor('gray')->setFontColor('gray')->setFontSize('11')->setRankDir('LR');
     $elements = array_merge($namespace->getClasses()->getAll(), $namespace->getInterfaces()->getAll(), $namespace->getTraits()->getAll());
     /** @var ClassDescriptor|InterfaceDescriptor|TraitDescriptor $sub_element */
     foreach ($elements as $sub_element) {
         $node = Node::create($sub_element->getFullyQualifiedStructuralElementName(), $sub_element->getName())->setShape('box')->setFontName($this->nodeFont)->setFontSize('11');
         if ($sub_element instanceof ClassDescriptor && $sub_element->isAbstract()) {
             $node->setLabel('<«abstract»<br/>' . $sub_element->getName() . '>');
         }
         //$full_name = $sub_element->getFullyQualifiedStructuralElementName();
         //$node->setURL($this->class_paths[$full_name]);
         //$node->setTarget('_parent');
         $this->nodeCache[$sub_element->getFullyQualifiedStructuralElementName()] = $node;
         $sub_graph->setNode($node);
     }
     foreach ($namespace->getChildren()->getAll() as $element) {
         $this->buildNamespaceTree($sub_graph, $element);
     }
     $graph->addGraph($sub_graph);
 }
 /**
  * Add a cluster to a graph
  *
  * If the cluster already exists on the graph, then the cluster graph is returned
  *
  * @param Graph $graph
  * @param string $name
  * @param string $label
  * @return Graph $clusterGraph
  */
 protected function _addCluster($graph, $name, $label = null, $attributes = array())
 {
     if ($label === null) {
         $label = $name;
     }
     if (!$graph->hasGraph('cluster_' . $name)) {
         $clusterGraph = Graph::create('cluster_' . $name);
         $this->_addAttributes($clusterGraph, $attributes);
         $this->graph->addGraph($clusterGraph->setLabel($label));
     } else {
         $clusterGraph = $this->graph->getGraph('cluster_' . $name);
     }
     return $clusterGraph;
 }
Example #5
0
 private function createGraph()
 {
     $graph = Graph::create("cfg");
     foreach ($this->options['graph'] as $name => $value) {
         $setter = 'set' . $name;
         $graph->{$setter}($value);
     }
     return $graph;
 }
Example #6
0
 /**
  * Creates a class inheritance diagram.
  *
  * @param \DOMDocument                        $structure      Structure
  *     document used to gather data from.
  * @param \phpDocumentor\Transformer\Transformation $transformation Transformation
  *     element containing the meta-data.
  *
  * @return void
  */
 public function processClass(\DOMDocument $structure, \phpDocumentor\Transformer\Transformation $transformation)
 {
     $filename = $transformation->getTransformer()->getTarget() . DIRECTORY_SEPARATOR . $transformation->getArtifact();
     $graph = \phpDocumentor\GraphViz\Graph::create()->setRankSep('1.0')->setCenter('true')->setRank('source')->setRankDir('RL')->setSplines('true')->setConcentrate('true');
     $xpath = new \DOMXPath($structure);
     $qry = $xpath->query("/project/namespace");
     /** @var \DOMElement $element */
     foreach ($qry as $element) {
         $this->buildNamespaceTree($graph, $element, $xpath, '');
     }
     // link all extended relations
     $qry = $xpath->query('/project/file/interface[extends]|/project/file/class[extends]');
     /** @var \DOMElement $element */
     foreach ($qry as $element) {
         $from_name = $element->getElementsByTagName('full_name')->item(0)->nodeValue;
         $to_name = $element->getElementsByTagName('extends')->item(0)->nodeValue;
         if (!$to_name) {
             continue;
         }
         $from = $graph->findNode($from_name);
         $to = $graph->findNode($to_name);
         if ($from === null) {
             $from = \phpDocumentor\GraphViz\Node::create($from_name);
             $from->setFontColor('gray');
             $from->setLabel($from_name);
             $graph->setNode($from);
         }
         if ($to === null) {
             $to = \phpDocumentor\GraphViz\Node::create($to_name);
             $to->setFontColor('gray');
             $to->setLabel($to_name);
             $graph->setNode($to);
         }
         $edge = \phpDocumentor\GraphViz\Edge::create($from, $to);
         $edge->setArrowHead('empty');
         $graph->link($edge);
     }
     // link all implemented relations
     $qry = $xpath->query('/project/file/interface[imports]|/project/file/class[implements]');
     /** @var \DOMElement $element */
     foreach ($qry as $element) {
         $from_name = $element->getElementsByTagName('full_name')->item(0)->nodeValue;
         foreach ($element->getElementsByTagName('implements') as $implements) {
             $to_name = $implements->nodeValue;
             if (!$to_name) {
                 continue;
             }
             $from = $graph->findNode($from_name);
             $to = $graph->findNode($to_name);
             if ($from === null) {
                 $from = \phpDocumentor\GraphViz\Node::create($from_name);
                 $from->setFontColor('gray');
                 $from->setLabel(addslashes($from_name));
                 $graph->setNode($from);
             }
             if ($to === null) {
                 $to = \phpDocumentor\GraphViz\Node::create($to_name);
                 $to->setFontColor('gray');
                 $to->setLabel(addslashes($to_name));
                 $graph->setNode($to);
             }
             $edge = \phpDocumentor\GraphViz\Edge::create($from, $to);
             $edge->setStyle('dotted');
             $edge->setArrowHead('empty');
             $graph->link($edge);
         }
     }
     $graph->export('svg', $filename);
 }
Example #7
0
    protected function createInternalSystemGraph(InternalSystem $internalSystem)
    {
        $description = wordwrap($internalSystem->getDescription(), 20, "<br />\n");
        $label = <<<LABEL
            <
                <table border="0" cellborder="0" cellspacing="0">
                  <tr><td><font point-size="12">{$internalSystem->getName()}</font></td></tr>
                  <tr><td><font point-size="8">[Internal System]</font></td></tr>
                  <tr><td>{$description}</td></tr>
                </table>
            >
LABEL;
        $internalSystemGraph = Graph::create('cluster__' . $internalSystem->getId());
        $internalSystemGraph->setLabel(trim($label))->setStyle('rounded')->setFontsize(10)->setFontcolor($this->options['color'])->setFontname('helvetica')->setShape('box')->setColor('#263238');
        return $internalSystemGraph;
    }
Example #8
0
 /**
  * @covers phpDocumentor\GraphViz\Graph::__toString
  */
 public function test__toString()
 {
     $graph = Graph::create('My First Graph');
     $this->assertSame((string) $graph, 'digraph "My First Graph" {' . PHP_EOL . PHP_EOL . '}');
     $graph->setLabel('PigeonPost');
     $this->assertSame((string) $graph, 'digraph "My First Graph" {' . PHP_EOL . 'label="PigeonPost"' . PHP_EOL . '}');
 }