Beispiel #1
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;
 }
Beispiel #2
0
 /**
  * Creates a GraphViz Edge between two nodes.
  *
  * @param Graph  $graph
  * @param string $from_name
  * @param string|ClassDescriptor|InterfaceDescriptor|TraitDescriptor $to
  *
  * @return Edge
  */
 protected function createEdge($graph, $from_name, $to)
 {
     $to_name = !is_string($to) ? $to->getFullyQualifiedStructuralElementName() : $to;
     if (!isset($this->nodeCache[$from_name])) {
         $this->nodeCache[$from_name] = $this->createEmptyNode($from_name, $graph);
     }
     if (!isset($this->nodeCache[$to_name])) {
         $this->nodeCache[$to_name] = $this->createEmptyNode($to_name, $graph);
     }
     return Edge::create($this->nodeCache[$from_name], $this->nodeCache[$to_name]);
 }
Beispiel #3
0
 /**
  * Tests the getTo method returns the same node as passed
  * in the create method
  *
  * @covers phpDocumentor\GraphViz\Edge::getTo
  *
  * @return void
  */
 public function testGetTo()
 {
     $to = new Node('to');
     $edge = Edge::create(new Node('from'), $to);
     $this->assertSame($to, $edge->getTo());
 }
 /**
  * Add graph legend
  *
  * For every type of the relationship in CakePHP we add two nodes (from, to)
  * to the graph and then link them, using the settings of each relationship
  * type.  Nodes are grouped into the Graph Legend cluster, so they don't
  * interfere with the rest of the nodes.
  *
  * @param array $relationsSettings Array with relation types and settings
  * @return void
  */
 protected function _buildGraphLegend($relationsSettings)
 {
     $legendNodeSettings = array('shape' => 'box', 'width' => 0.5, 'fontname' => 'Helvetica', 'fontsize' => 10);
     $legend = $this->_addCluster($this->graph, self::GRAPH_LEGEND);
     foreach ($relationsSettings as $relation => $relationSettings) {
         $from = $relation . '_from';
         $to = $relation . '_to';
         $fromNode = Node::create($from, 'A');
         $this->_addAttributes($fromNode, $legendNodeSettings);
         $legend->setNode($fromNode);
         $toNode = Node::create($to, 'B');
         $this->_addAttributes($toNode, $legendNodeSettings);
         $legend->setNode($toNode);
         $edge = Edge::create($fromNode, $toNode);
         $this->_addAttributes($edge, $relationSettings);
         $legend->link($edge);
     }
 }
Beispiel #5
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);
 }
    /**
     * @param Node $sourceNode
     * @param Node $targetNode
     * @param Usage[] $usages
     * @param bool $highlight
     *
     * @return Edge
     */
    protected function createConnectionEdge(Node $sourceNode, Node $targetNode, array $usages = [], $highlight = false)
    {
        $labels = [];
        foreach ($usages as $usage) {
            $for = wordwrap($usage->getFor(), 20, "<br />\n");
            if (empty($usage->getType())) {
                $label = <<<LABEL
                    <tr><td>{$for}</td></tr>
LABEL;
            } else {
                $label = <<<LABEL
                    <tr><td>{$for}</td></tr>
                    <tr><td><font point-size="8">[{$usage->getType()}]</font></td></tr>
LABEL;
            }
            $labels[] = $label;
        }
        $joinedLabels = implode('', $labels);
        $label = <<<LABEL
            <
                <table border="0" cellborder="0" cellspacing="0">
                {$joinedLabels}
                </table>
            >
LABEL;
        $edge = Edge::create($sourceNode, $targetNode);
        $edge->setLabel(trim($label))->setFontsize(10)->setFontcolor(true === $highlight ? $this->options['highlight-color'] : $this->options['color'])->setFontname('helvetica')->setColor(true === $highlight ? $this->options['highlight-color'] : $this->options['color']);
        return $edge;
    }