9 print "Usage: git chart\n";
16 print "Gathering data ...\n";
18 my $day=$options->{from};
19 my $to =$options->{to};
20 my $step=$options->{step};
21 my $max=$options->{max} || 0;
24 my $next = $day + $step;
25 my $val = `git log --pretty=%s --since="$next days ago" --until="$day days ago" | wc -l`;
28 $max = $val if $max < $val;
32 $options->{max} = $max;
39 # functions to plot the datasets.
40 # each function can be called with either one or two parameters.
41 # when called with two parameters, the first is assumed to be the dataset, and the second the options
42 # (array and hash ref respectively).
43 # when called with a single parameter, it is assumed to be an options hash ref, and the dataset is
44 # created by calling gather_data with the passed options.
47 # TODO needs a lot of customization
48 sub google_chart($;$) {
51 if (! defined $options) {
53 $dataset = gather_data($options);
56 my $height=$options->{chart_height};
57 my $max = $options->{max};
58 my $from = $options->{from};
59 my $to = $options->{to};
60 my $step = $options->{step};
61 my $width=($step < 20 ? 20 : $step)*@$dataset;
63 my $url="https://chart.googleapis.com/chart?chs=${width}x${height}&cht=bvg&chd=t:%s&chds=0,$max&chbh=a&chxt=y,x&chxr=0,0,$max|1,$to,$from,-$step";
65 my $launch = sprintf $url, join(",",reverse @$dataset);
66 # print $launch, "\n";
67 `git web--browse "$launch"`
71 sub gnuplot_chart($;$) {
74 if (! defined $options) {
76 $dataset = gather_data($options);
79 my $max = $options->{max};
80 my $from = $options->{from};
81 my $to = $options->{to};
82 my $step = $options->{step};
84 # TODO allow customization
85 # in particular, detect (lack of) display and set term to dumb accordingly
86 my $termcmd = $options->{gnuplot_term};
87 my $plotsetup = $options->{gnuplot_setup};
88 $plotsetup .="\nset yrange [0:$max]\nset xrange [$from:$to]";
89 my $plotstyle = $options->{gnuplot_style};
90 my $plotoptions = $options->{gnuplot_plotwith};
91 my $data = join("\n", reverse @$dataset);
93 open my $gp, "|gnuplot -persist";
107 if ($from =~/^\d+$/) {
111 warn "non-numeric from not supported yet\n";
121 warn "non-numeric to not supported yet\n";
127 if ($step =~/^\d+$/) {
130 return 1 if $step eq 'daily';
131 return 7 if $step eq 'weekly';
132 return 30 if $step eq 'monthly';
141 # charting/plotting options
142 plotter => \&gnuplot_chart,
145 gnuplot_setup => "set nokey",
146 gnuplot_style => 'set style fill solid 1.0 border -1',
147 gnuplot_plotwith => 'with boxes',
161 monthly => \$monthly,
165 google => sub { $options{plotter} = \&google_chart },
166 gnuplot => sub { $options{plotter} = \&gnuplot_chart },
169 $options{from} = parse_from($from) if $from;
172 $options{to} = $options{from} + 365;
175 $options{to} = $options{from} + 6*30;
178 $options{to} = $options{from} + 31;
182 $options{to} = parse_to($to) if $to;
183 $options{step} = parse_step($step) if $step;
185 die "step must be strictly positive!" unless $options{step} > 0;
187 $options{plotter}->(\%options);