aboutsummaryrefslogtreecommitdiff
path: root/IkiWiki
diff options
context:
space:
mode:
authorJoey Hess <joey@kitenet.net>2011-11-30 14:40:27 -0400
committerJoey Hess <joey@kitenet.net>2011-11-30 15:47:12 -0400
commit44863ea2346eea32b3bc8b9b700101bf7ea3b32f (patch)
tree531b244f157343b56bf84a26d5f5d03c9eb9b62c /IkiWiki
parent9936c3ec32094baa2bbbb6cd57a2e942b6b06f3b (diff)
downloadikiwiki-44863ea2346eea32b3bc8b9b700101bf7ea3b32f.tar
ikiwiki-44863ea2346eea32b3bc8b9b700101bf7ea3b32f.tar.gz
graphviz: Support urls embedded in the graph, by having graphviz generate an imagemap.
Also, I let preview mode write real files, rather than using data: uri. Which is ok these days, since ikiwiki tracks files created during previewing, and cleans them up later.
Diffstat (limited to 'IkiWiki')
-rw-r--r--IkiWiki/Plugin/graphviz.pm55
1 files changed, 30 insertions, 25 deletions
diff --git a/IkiWiki/Plugin/graphviz.pm b/IkiWiki/Plugin/graphviz.pm
index 4ed8b89f1..f01fdca85 100644
--- a/IkiWiki/Plugin/graphviz.pm
+++ b/IkiWiki/Plugin/graphviz.pm
@@ -26,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};
@@ -39,48 +42,50 @@ sub render_graph (\%) {
# Use the sha1 of the graphviz code as part of its filename.
eval q{use Digest::SHA};
error($@) if $@;
- my $dest=$params{page}."/graph-".
- IkiWiki::possibly_foolish_untaint(Digest::SHA::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;
$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 = <IN>;
- }
+ local $/ = undef;
+ $map=<IN>;
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 {
- # in preview mode, embed the image in a data uri
- # to avoid temp file clutter
- eval q{use MIME::Base64};
- error($@) if $@;
- return "<img src=\"data:image/png;base64,".
- encode_base64($png)."\" />";
- }
+ error gettext("failed to run graphviz") if ($sigpipe || $?);
+
+ }
+ else {
+ $map=readfile("$config{destdir}/$imagemap");
}
- return "<img src=\"".urlto($dest, $params{destpage})."\" />\n";
+ return "<img src=\"".urlto($dest, $params{destpage}).
+ "\" usemap=\"#graph$graphnum\" />\n".
+ $map;
}
sub graph (@) {