/** * Creates a class inheritance diagram. * * @param DOMDocument $structure * @param DocBlox_Transformer_Transformation $transformation * * @return void */ public function processClass(DOMDocument $structure, DocBlox_Transformer_Transformation $transformation) { $filename = $transformation->getTransformer()->getTarget() . DIRECTORY_SEPARATOR . $transformation->getArtifact(); $graph = DocBlox_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(str_replace(array('\\', '$'), '_', $from_name)); $to = $graph->findNode(str_replace(array('\\', '$'), '_', $to_name)); if ($from === null) { $from = DocBlox_GraphViz_Node::create(str_replace(array('\\', '$'), '_', $from_name)); $from->setFontColor('gray'); $from->setLabel(addslashes($from_name)); $graph->setNode($from); } if ($to === null) { $to = DocBlox_GraphViz_Node::create(str_replace(array('\\', '$'), '_', $to_name)); $to->setFontColor('gray'); $to->setLabel(addslashes($to_name)); $graph->setNode($to); } $edge = DocBlox_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(str_replace(array('\\', '$'), '_', $from_name)); $to = $graph->findNode(str_replace(array('\\', '$'), '_', $to_name)); if ($from === null) { $from = DocBlox_GraphViz_Node::create(str_replace(array('\\', '$'), '_', $from_name)); $from->setFontColor('gray'); $from->setLabel(addslashes($from_name)); $graph->setNode($from); } if ($to === null) { $to = DocBlox_GraphViz_Node::create(str_replace(array('\\', '$'), '_', $to_name)); $to->setFontColor('gray'); $to->setLabel(addslashes($to_name)); $graph->setNode($to); } $edge = DocBlox_GraphViz_Edge::create($from, $to); $edge->setStyle('dotted'); $edge->setArrowHead('empty'); $graph->link($edge); } } $graph->export('svg', $filename); $svg = simplexml_load_file($filename); $script = $svg->addChild('script'); $script->addAttribute('xlink:href', 'js/SVGPan.js', 'http://www.w3.org/1999/xlink'); // for the SVGPan file to work no viewBox may be defined and the id of the first <g> node must be renamed to 'viewport' unset($svg['viewBox']); $svg->g['id'] = 'viewport'; $svg->asXML($filename); }
<?php include 'Graph.php'; include 'Edge.php'; include 'Node.php'; include 'Attribute.php'; $graph = DocBlox_GraphViz_Graph::create(); echo $graph->addGraph($graph2 = DocBlox_GraphViz_Graph::create('cluster_bla')->setNode(DocBlox_GraphViz_Node::create('node3')))->setNode(DocBlox_GraphViz_Node::create('node1')->setStyle('filled')->setColor('lightgrey')->setFontSize('20'))->setNode(DocBlox_GraphViz_Node::create('node2'))->link(DocBlox_GraphViz_Edge::create($graph->node1, $graph->node2))->link(DocBlox_GraphViz_Edge::create($graph->node1, $graph2->node3))->link(DocBlox_GraphViz_Edge::create($graph2->node3, $graph->node2)); $graph->export('png', 'test2.png');