示例#1
0
    /**
     * Tests whether the magic __toString method returns a well formatted string
     * as specified in the DOT standard
     *
     * @covers phpDocumentor\GraphViz\Node::__toString
     *
     * @return void
     */
    public function testToString()
    {
        $this->fixture->setfontsize(12);
        $this->fixture->setfontname('Bitstream Vera Sans');
        $dot = <<<DOT
"name" [
label="label"
fontsize="12"
fontname="Bitstream Vera Sans"
]
DOT;
        $this->assertSame($dot, (string) $this->fixture);
    }
示例#2
0
    /**
     * Tests whether the magic __toString method returns a well formatted string
     * as specified in the DOT standard when the label contains slashes.
     *
     * @covers phpDocumentor\GraphViz\Node::__toString
     */
    public function testToStringWithLabelContainingSlashes()
    {
        $this->fixture->setfontsize(12);
        $this->fixture->setfontname('Bitstream Vera Sans');
        $this->fixture->setLabel('\\phpDocumentor\\Descriptor\\ProjectDescriptor');
        $dot = <<<DOT
"name" [
label="\\\\phpDocumentor\\\\Descriptor\\\\ProjectDescriptor"
fontsize="12"
fontname="Bitstream Vera Sans"
]
DOT;
        $this->assertSame($dot, (string) $this->fixture);
    }
示例#3
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;
 }
示例#4
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);
 }
示例#5
0
 /**
  * Transform the object to an UML scheme
  *
  * @param \Puml\Model\Object $object
  *
  * @return void
  * @since 0.1
  */
 protected function transformObject(\Puml\Model\Object $object)
 {
     $label = implode('|', array(addslashes($object->getName()), implode($this->transformProperties($object->getProperties())), implode($this->transformMethods($object->getMethods()))));
     $node = new Node($object->getName());
     $node->setShape('record')->setPos('0, ' . (0 + $this->level * 3) . '!')->setLabel('"{' . $label . '}"');
     $this->graph->setNode($node);
 }
 /**
  * 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);
     }
 }
示例#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);
 }
示例#8
0
    protected function createExternalUserNode(ExternalUser $externalUser, $highlight = false)
    {
        $description = wordwrap($externalUser->getDescription(), 20, "<br />\n");
        $label = <<<LABEL
            <
                <table border="0" cellborder="0" cellspacing="0">
                    <tr><td><font point-size="12">{$externalUser->getName()}</font></td></tr>
                    <tr><td><font point-size="8">[External user]</font></td></tr>
                    <tr><td>{$description}</td></tr>
                </table>
            >
LABEL;
        $externalUserNode = Node::create($externalUser->getId(), trim($label));
        $externalUserNode->setStyle('dashed')->setFontsize(10)->setFontcolor(true === $highlight ? $this->options['highlight-color'] : $this->options['color'])->setFontname('helvetica')->setShape('underline')->setColor(true === $highlight ? $this->options['highlight-color'] : $this->options['color']);
        return $externalUserNode;
    }