Exemplo n.º 1
0
    /**
     * Tests whether the magic __toString method returns a well formatted string
     * as specified in the DOT standard
     *
     * @covers phpDocumentor\GraphViz\Edge::__toString
     *
     * @return void
     */
    public function testToString()
    {
        $this->fixture->setLabel('MyLabel');
        $this->fixture->setWeight(45);
        $dot = <<<DOT
"from" -> "to" [
label="MyLabel"
weight="45"
]
DOT;
        $this->assertSame($dot, (string) $this->fixture);
    }
Exemplo n.º 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;
 }
Exemplo n.º 3
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]);
 }
Exemplo n.º 4
0
 /**
  * Transform the parent
  *
  * @param \Puml\Model\Object $child  The direct child of the parent
  *
  * @return void
  * @since 0.1
  * @throws Exception
  */
 protected function transformParent(\Puml\Model\Object $child)
 {
     if (!$child->hasParent()) {
         throw new \Exception('Unable to transform parent, when no parent available, on class ' . $child->getName());
     }
     $this->level++;
     $parent = $child->getParent();
     $this->transformObject($parent);
     $edge = new Edge($this->graph->findNode($child->getName()), $this->graph->findNode($parent->getName()));
     $edge->setArrowhead('empty');
     $this->graph->link($edge);
     if ($parent->hasParent()) {
         $this->transformParent($parent);
     }
 }
Exemplo n.º 5
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);
     }
 }
Exemplo n.º 7
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);
 }
Exemplo n.º 8
0
    /**
     * @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;
    }