2 package IkiWiki
::Plugin
::postsparkline
;
9 IkiWiki
::loadplugin
('sparkline');
10 hook
(type
=> "getsetup", id
=> "postsparkline", call
=> \
&getsetup
);
11 hook
(type
=> "preprocess", id
=> "postsparkline", call
=> \
&preprocess
);
26 if (! exists $params{max
}) {
30 if (! exists $params{pages
}) {
35 if (! exists $params{time} || $params{time} ne 'mtime') {
36 $params{timehash
} = \
%IkiWiki::pagectime
;
37 # need to update when pages are added or removed
38 $deptype = deptype
("presence");
41 $params{timehash
} = \
%IkiWiki::pagemtime
;
42 # need to update when pages are changed
43 $deptype = deptype
("content");
46 if (! exists $params{formula
}) {
47 error gettext
("missing formula")
49 my $formula=$params{formula
};
50 $formula=~s/[^a-zA-Z0-9]*//g;
51 $formula=IkiWiki
::possibly_foolish_untaint
($formula);
52 if (! length $formula ||
53 ! IkiWiki
::Plugin
::postsparkline
::formula
->can($formula)) {
54 error gettext
("unknown formula");
57 my @list=sort { $params{timehash
}->{$b} <=> $params{timehash
}->{$a} }
58 pagespec_match_list
($params{page
}, $params{pages
},
60 filter
=> sub { $_[0] eq $params{page
} },
63 my @data=eval qq{IkiWiki
::Plugin
::postsparkline
::formula
::$formula(\\\
%params, \
@list)};
69 # generate an empty graph
70 push @data, 0 foreach 1..($params{max
} / 2);
73 my $color=exists $params{color
} ?
"($params{color})" : "";
75 delete $params{pages
};
76 delete $params{formula
};
77 delete $params{ftime
};
78 delete $params{color
};
79 return IkiWiki
::Plugin
::sparkline
::preprocess
(%params,
80 map { $_.$color => "" } reverse @data);
87 my $max=$params->{max
};
88 my ($first, $prev, $cur);
92 $cur=$sub->($params->{timehash
}->{$_});
95 push @data, "$prev,$count";
99 for ($cur+1 .. $prev-1) {
115 package IkiWiki
::Plugin
::postsparkline
::formula
;
118 return IkiWiki
::Plugin
::postsparkline
::perfoo
(sub {
119 return (localtime $_[0])[5];
124 return IkiWiki
::Plugin
::postsparkline
::perfoo
(sub {
125 my ($month, $year)=(localtime $_[0])[4,5];
126 return $year*12+$month;
131 return IkiWiki
::Plugin
::postsparkline
::perfoo
(sub {
132 my ($year, $yday)=(localtime $_[0])[5,7];
133 return $year*365+$yday;
140 my $max=$params->{max
};
142 for (my $i=1; $i < @_; $i++) {
143 push @data, $params->{timehash
}->{$_[$i-1]} - $params->{timehash
}->{$_[$i]};