X-Git-Url: https://sipb.mit.edu/gitweb.cgi/ikiwiki.git/blobdiff_plain/ffec6806087981420eaf83c8d83cc4523a46d0de..44863ea2346eea32b3bc8b9b700101bf7ea3b32f:/IkiWiki/Plugin/graphviz.pm diff --git a/IkiWiki/Plugin/graphviz.pm b/IkiWiki/Plugin/graphviz.pm index b43e96a73..f01fdca85 100644 --- a/IkiWiki/Plugin/graphviz.pm +++ b/IkiWiki/Plugin/graphviz.pm @@ -18,6 +18,7 @@ sub getsetup () { plugin => { safe => 1, rebuild => undef, + section => "widget", }, } @@ -25,10 +26,13 @@ my %graphviz_programs = ( "dot" => 1, "neato" => 1, "fdp" => 1, "twopi" => 1, "circo" => 1 ); +my $graphnum=0; + sub render_graph (\%) { my %params = %{(shift)}; - my $src = "$params{type} g {\n"; + $graphnum++; + my $src = "$params{type} graph$graphnum {\n"; $src .= "charset=\"utf-8\";\n"; $src .= "ratio=compress;\nsize=\"".($params{width}+0).", ".($params{height}+0)."\";\n" if defined $params{width} and defined $params{height}; @@ -36,54 +40,52 @@ sub render_graph (\%) { $src .= "}\n"; # Use the sha1 of the graphviz code as part of its filename. - eval q{use Digest::SHA1}; + eval q{use Digest::SHA}; error($@) if $@; - my $dest=$params{page}."/graph-". - IkiWiki::possibly_foolish_untaint(Digest::SHA1::sha1_hex($src)). - ".png"; + my $base=$params{page}."/graph-". + IkiWiki::possibly_foolish_untaint(Digest::SHA::sha1_hex($src)); + my $dest=$base.".png"; will_render($params{page}, $dest); - if (! -e "$config{destdir}/$dest") { + # The imagemap data is stored as a separate file. + my $imagemap=$base.".imagemap"; + will_render($params{page}, $imagemap); + + my $map; + if (! -e "$config{destdir}/$dest" || ! -e "$config{destdir}/$imagemap") { + # Use ikiwiki's function to create the image file, this makes + # sure needed subdirs are there and does some sanity checking. + writefile($dest, $config{destdir}, ""); + my $pid; - my $sigpipe=0;; + my $sigpipe=0; $SIG{PIPE}=sub { $sigpipe=1 }; - $pid=open2(*IN, *OUT, "$params{prog} -Tpng"); + $pid=open2(*IN, *OUT, "$params{prog} -Tpng -o '$config{destdir}/$dest' -Tcmapx"); # open2 doesn't respect "use open ':utf8'" + binmode (IN, ':utf8'); binmode (OUT, ':utf8'); print OUT $src; close OUT; - my $png; - { - local $/ = undef; - $png = ; - } + local $/ = undef; + $map=; close IN; + writefile($imagemap, $config{destdir}, $map); waitpid $pid, 0; $SIG{PIPE}="DEFAULT"; - error gettext("failed to run graphviz") if $sigpipe; - - if (! $params{preview}) { - writefile($dest, $config{destdir}, $png, 1); - } - else { - # can't write the file, so embed it in a data uri - eval q{use MIME::Base64}; - error($@) if $@; - return ""; - } - } + error gettext("failed to run graphviz") if ($sigpipe || $?); - if ($params{preview}) { - return "\n"; } else { - return "\n"; + $map=readfile("$config{destdir}/$imagemap"); } + + return "\n". + $map; } sub graph (@) {