====== Graphviz Plugin ====== ---- plugin ---- description: Graph Visualization (from text with links between objects to image) author : Andreas Gohr email : andi@splitbrain.org type : Syntax lastupdate : 2016-02-03 compatible : anteater, 2011-05-25, adora belle, weatherwax, ponder stibbons, Hrun, Detritus depends : conflicts : similar : GNUplot, Ditaa, svgedit, seqdia tags : media, images, diagram, graphviz downloadurl: https://github.com/splitbrain/dokuwiki-plugin-graphviz/zipball/master bugtracker : https://github.com/splitbrain/dokuwiki-plugin-graphviz/issues sourcerepo : https://github.com/splitbrain/dokuwiki-plugin-graphviz/ donationurl: http://donate.dokuwiki.org/graphviz ---- This plugin can create directed and non-directed graph images from a textual description language called "dot" using the Graphviz program. It can use a locally installed graphviz or use Google's chart API for rendering. The plugin supports exporting to OpenOffice through the [[odt|ODT Plugin]] (only with a local graphviz install). For more information on Graphviz and the dot language refer to the [[http://www.graphviz.org/Documentation.php|Graphviz documentation]] This plugin was originally written by [[calle@ioslo.net|Carl-Christian Salvesen]]. The current plugin is a nearly complete rewrite and differs on how it works internally and where graphs are stored. ===== Download and Installation ===== Search and install the plugin using the [[plugin:extension|Extension Manager]]. Refer to [[:Plugins]] on how to install plugins manually. ==== Changes ==== {{rss>https://github.com/splitbrain/dokuwiki-plugin-graphviz/commits/master.atom date}} ===== Configuration ===== The full path to your graphviz' ''dot'' binary can be configured in the config manager. When it isn't configured, remote rendering at Google is used. ===== Syntax and Usage ===== Any Graphviz compatible graph definition can be given with ''graphviz'' tags. The rendering engine can optionally be given as argument in the opening tag. Supported are ''dot'', ''neato'', ''twopi'', ''circo'' and ''fdp'' with ''dot'' being the default: * ''dot'' -- "hierarchical" or layered drawings of directed graphs. This is the best tool to use if edges have directionality. * ''neato'' -- "spring model" layouts. This is the best tool to use if the graph is not too large (about 100 nodes) and you don't know anything else about it. Neato attempts to minimize a global energy function, which is equivalent to statistical multi-dimensional scaling. * ''fdp'' -- "spring model" layouts similar to those of neato, but does this by reducing forces rather than working with energy. * ''twopi'' -- radial layouts, after Graham Wills 97. Nodes are placed on concentric circles depending their distance from a given root node. * ''circo'' -- circular layout, after Six and Tollis 99, Kauffman and Wiese 02. This is suitable for certain diagrams of multiple cyclic structures, such as certain telecommunications networks. You can also specify ''left'', ''center'' or ''right'' to align the resulting image. A parameter in the form of ''////x////'' is interpreted as wanted output size. To only specify width ''width=////'' or ''////x0'' can be used, for height ''height=////'' or ''0x////''. ==== Example ==== digraph ATN { rankdir=LR; s25[fontsize=11, label="25", shape=doublecircle, fixedsize=true, width=.6]; s239[fontsize=24,label="239", shape=circle, fixedsize=true, width=.55, peripheries=1]; s240[fontsize=11,label="240", shape=circle, fixedsize=true, width=.55, peripheries=1]; s241[fontsize=11,label="241", shape=circle, fixedsize=true, width=.55, peripheries=1]; s242[fontsize=11,label="242", shape=circle, fixedsize=true, width=.55, peripheries=1]; s243[fontsize=11,label="{→\n243\nd=24|{|}}", shape=record, fixedsize=false, peripheries=1]; s244[fontsize=11,label="←\n244", shape=circle, fixedsize=true, width=.55, peripheries=1]; s245[fontsize=11,label="245", shape=circle, fixedsize=true, width=.55, peripheries=1]; s246[fontsize=11,label="246", shape=circle, fixedsize=true, width=.55, peripheries=1]; s247[fontsize=11,label="→\n247+", shape=circle, fixedsize=true, width=.55, peripheries=1]; s24[fontsize=11,label="24", shape=circle, fixedsize=true, width=.55, peripheries=1]; s248[fontsize=11,label="←\n248", shape=circle, fixedsize=true, width=.55, peripheries=1]; s249[fontsize=11,label="{249+\nd=25|{|}}", shape=record, fixedsize=false, peripheries=1]; s250[fontsize=11,label="250", shape=circle, fixedsize=true, width=.55, peripheries=1]; s251[fontsize=11,label="251", shape=circle, fixedsize=true, width=.55, peripheries=1]; s252[fontsize=11,label="252", shape=circle, fixedsize=true, width=.55, peripheries=1]; s24 -> s239 [fontname="Times-Italic", label="ε"]; s239 -> s247 [fontsize=11, fontname="Courier", arrowsize=.7, label = "'{'", arrowhead = normal]; s247 -> s240 [fontname="Times-Italic", label="ε"]; s240 -> s243 [fontsize=11, fontname="Courier", arrowsize=.7, label = "'case'", arrowhead = normal]; s243:p0 -> s241 [fontname="Times-Italic", label="ε"]; s243:p1 -> s242 [fontname="Times-Italic", label="ε"]; s241 -> s244 [fontsize=11, fontname="Courier", arrowsize=.7, label = "'null'", arrowhead = normal]; s242 -> s244 [fontsize=11, fontname="Courier", arrowsize=.7, label = "", arrowhead = normal]; s244 -> s245 [fontname="Times-Italic", label="ε"]; s245 -> s246 [fontsize=11, fontname="Courier", arrowsize=.7, label = "'=>'", arrowhead = normal]; s246 -> s248 [fontsize=11, fontname="Courier", arrowsize=.7, label = "", arrowhead = normal]; s248 -> s249 [fontname="Times-Italic", label="ε"]; s249:p0 -> s247 [fontname="Times-Italic", label="ε", style="dashed"]; s249:p1 -> s250 [fontname="Times-Italic", label="ε"]; s250 -> s251 [fontname="Times-Italic", label="ε"]; s251 -> s252 [fontsize=11, fontname="Courier", arrowsize=.7, label = "'}'", arrowhead = normal]; s252 -> s25 [fontname="Times-Italic", label="ε"]; } {{ http://img97.imageshack.us/img97/2613/dotb.png?nolink& }} ===== how to display dot MAPs ===== * For UNIX users ( since assumes a PATH of /usr/bin/dot ) Using an old version of Graphviz I fixed to display **dot** maps //(nodes that when you click on them link to a URL ie another page in your wiki or an external link.) // This is a fragment of the render section of the syntax file ie ( I replaced my render function with this ): /** * Create output */ function render($mode, &$renderer, $data) { global $conf; global $gr_ext; $gr_ext='png'; $grf_ext='.'.$gr_ext; if($data[1] == 'map' && strlen($data[0]) > 1) { if ( !is_dir($conf['mediadir'] . '/graphviz') ) io_mkdir_p($conf['mediadir'] . '/graphviz'); //Using dokuwiki framework $hash = md5(serialize($data)); $filename = $conf['mediadir'] . '/graphviz/'.$hash.$grf_ext; $url = ml('graphviz:'.$hash.$grf_ext); //Using dokuwiki framework //$renderer->doc .= '

valor filename=['.$filename.']

'; //$renderer->doc .= '

valor url=['.$url .']

'; // if already exist render if ( is_readable($filename) ) { // cached. // generate the map to variable $kk1 = "sed '1d'|sed '\$d'"; $cmd = "echo '$data[0]' | /usr/bin/dot -Tcmapx | ".$kk1; //$renderer->doc .= '

DSP-graph value cmd=>['.$cmd.']

'; //Debug cmd exec( $cmd, $map); //$renderer->doc .= '

valor map=['.$map .']

'; $maphtml = implode("\n",$map); // add the target - cant do this with DOT $maphtml = str_replace("doc .= ''; $renderer->doc .= $maphtml; $renderer->doc .= ''; // Link the Image below with the map above by hash $renderer->doc .= ''; return true; } if (!$this->createImageMap($filename, $data[0], $data[1])) { // generate the map $kk1 = "sed '1d'|sed '\$d'"; $cmd = "echo '$data[0]' | /usr/bin/dot -Tcmapx | ".$kk1; //$renderer->doc .= '

CR-graph value cmd=>['.$cmd.']

'; //Debug cmd exec( $cmd, $map); $maphtml= implode("\n",$map); // add the target - cant do this with DOT $maphtml=str_replace("doc .= ''; $renderer->doc .= $maphtml; $renderer->doc .= ''; // Link the Image below with the map above by hash $renderer->doc .= ''; } else { $renderer->doc .= '**ERROR RENDERING GRAPHVIZ**'; } return true; }
My 2 cents to this wonderful dokuwiki community that has given me so much through the years. Regards, \\ Enrique M Sign update: "UnUZYQK2Yh4qWKI4U5rMjU9IdfGvDSWWQP+rVbQA/oo=" ==== Hyperlinks from Graphviz nodes ==== If you want links from the nodes, you can use this forked version: https://github.com/splitbrain/dokuwiki-plugin-graphviz/issues/12 Hopefully the fix will be merged soon in the official version.. Fabio ===== Compatibility ===== It seems to be compatible with "Rincewind", but I don't dare to list it as compatible based on only my test. > I use it in Rincewind, it seems to work fine for me! Thanks for this great plugin! [[info@drost-tenfelde.de|jdt]] ---- > I use it in Rincewind but it **did not work** as all my graphics disapeared (see [[https://github.com/splitbrain/dokuwiki-plugin-graphviz/issues/4|issue 4]]. But I seem to have found a workaround since my problem seemed to be a cache problem: > > syntax.php /** * Return path to the rendered image on our local system */ function _imgfile($data){ if($conf['debug']){ dbglog($cache, 'image file cache'); } $cache = $this->_cachename($data,'png'); // create the file if needed +++ /******************************************************* +++ **** CSJ added line ****/ +++ clearstatcache(); +++ /*******************************************************/ if(!file_exists($cache)){ $in = $this->_cachename($data,'txt'); if($this->getConf('path')){ $ok = $this->_run($data,$in,$cache); }else{ $ok = $this->_remote($data,$in,$cache); } if(!$ok) return false; clearstatcache(); } // resized version if($data['width']){ $cache = media_resize_image($cache,'png',$data['width'],$data['height']); } // something went wrong, we're missing the file if(!file_exists($cache)) return false; //print $cache; return $cache; } > >So there you go! > >Enjoy. > Claude ---- === Dokuwiki Farmer issue=== It did not work for our wiki which makes use of dokuwiki-farmer. Adding unset($data['animal']); in syntax.php in the function _cachename solved the problem.: function _cachename($data,$ext){ unset($data['width']); unset($data['height']); unset($data['align']); +++ unset($data['animal']); return getcachename(join('x',array_values($data)),'.graphviz.'.$ext); } When trying to debug I also realized that $conf['debug'] is never set but i guess it is $conf['allowdebug']. ===== FAQ ===== == How do I get anti-aliased images ? == Make sure you have a Graphviz version compiled against Cairo, this will cause it to use it by default, and results in anti-aliased images. == Does the server need an access to Internet ? == Default: Yes, it uses Google API to generate graphs.\\ However, it can be set up to point straight to a local install of graphiz. In that case no internet access is needed. == How to read external dot File? == How can i render an external (autogenerated) dot file? == How to include images in HTML-Labels? ==