/** * Create a transformer implementation based on a file name * * @param string $filename * * @return \Puml\Transformer\Base * @since 0.1 * @throws \Exception * @todo make this more dynamic, perhaps an observer pattern where the * transformers are registered at this factory. */ public static function create($filename) { $pathInfo = pathinfo($filename); $pathInfo['extension']; switch ($pathInfo['extension']) { case 'png': case 'pdf': case 'dot': $transformer = new GraphViz(); break; default: throw new \Exception('No support found for ' . $pathInfo['extension'] . ' extension'); } $transformer->setTransformation($pathInfo['extension'])->setFilename($filename); return $transformer; }
protected function getResultText(SMWQueryResult $res, $outputmode) { if (!is_callable('GraphViz::graphvizParserHook')) { wfWarn('The SRF Graph printer needs the GraphViz extension to be installed.'); return ''; } $this->isHTML = true; $graphInput = "digraph {$this->m_graphName} {"; if ($this->m_graphSize != '') { $graphInput .= "size=\"{$this->m_graphSize}\";"; } if ($this->m_nodeShape) { $graphInput .= "node [shape={$this->m_nodeShape}];"; } $graphInput .= "rankdir={$this->m_rankdir};"; while ($row = $res->getNext()) { $graphInput .= $this->getGVForItem($row, $outputmode); } $graphInput .= "}"; // Calls graphvizParserHook function from MediaWiki GraphViz extension $result = GraphViz::graphvizParserHook($graphInput, "", $GLOBALS['wgParser']); if ($this->m_graphLegend && $this->m_graphColor) { $arrayCount = 0; $arraySize = count($this->m_graphColors); $result .= "<P>"; foreach ($this->m_labelArray as $m_label) { if ($arrayCount >= $arraySize) { $arrayCount = 0; } $color = $this->m_graphColors[$arrayCount]; $result .= "<font color={$color}>{$color}: {$m_label} </font><br />"; $arrayCount += 1; } $result .= "</P>"; } return $result; }
/** * Create a graph done by graphviz * @param _wikielement graph */ private function _treatGraphviz($code) { $code->data = preg_replace('/\\[graphviz(.*?)\\]/', "", $code->data); $code->data = preg_replace('/\\[\\/graphviz(.*?)\\]/', "", $code->data); //graphviz _classInclude('wikirender|GraphViz'); $type = $code->other; $code = $code->data; $converter = new GraphViz($code, $type); $img = $converter->render(); $map = $converter->getMap(); $mapname = $converter->getMapName(); //var_dump($converter); $code = $map; $code .= "\n" . '<img usemap="#' . $mapname . '" src="' . _url("wiki|file|getGraphViz", array("graph" => $img)) . "\" />\n"; return $code; }