/[simile]/sparklines/create.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /sparklines/create.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 19 - (hide annotations)
Fri Oct 17 10:59:47 2008 UTC (15 years, 6 months ago) by dpavlin
File MIME type: text/plain
File size: 1076 byte(s)
experimental sparklines creator using GD::Graph::sparklines
1 dpavlin 19 #!/usr/bin/perl
2    
3     use warnings;
4     use strict;
5    
6     # create.pl
7     #
8     # 10/17/08 12:29:51 CEST Dobrica Pavlinusic <dpavlin@rot13.org>
9    
10     use GD::Graph::sparklines;
11     use Data::Dump qw/dump/;
12     use File::Slurp;
13    
14     my $data;
15    
16     my $max_month = 0;
17    
18     foreach my $file ( @ARGV ) {
19    
20     open(my $fh, '<', $file) or die "$file: $!";
21    
22     my $type = $1 if ($file =~ /monthly-([^\.]+)/);
23    
24     while(<$fh>) {
25     chomp;
26     my ( $instance, $count, $month, $from, $to ) = split(/\t/,$_);
27    
28     if ( ! defined $data->{$instance} ) {
29     $data->{$instance} = [];
30     }
31    
32     $max_month = $month if $month > $max_month;
33    
34     $data->{$instance}->[ $month ] = $count;
35     }
36    
37     warn dump( $data ), "\nmax_month: $max_month";
38    
39     foreach my $instance ( keys %$data ) {
40    
41     my $graph = GD::Graph::sparklines->new(128, 16);
42     my ( @x, @y );
43     foreach my $month ( 1 .. $max_month ) {
44     push @x, $month;
45     my $y = $data->{$instance}->[$month] || 0;
46     push @y, $y;
47     }
48     warn "x = ",dump( @x ), "\ny = ", dump( @y );
49     my $gd = $graph->plot( [ \@x, \@y ] ) or die $graph->error;
50     write_file( "s/$instance-$type.png", $gd->png );
51     }
52    
53     close($fh);
54     }

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26