/[Sack]/trunk/lib/Sack/Server/Gnuplot.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/lib/Sack/Server/Gnuplot.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 220 by dpavlin, Sun Nov 22 21:55:52 2009 UTC revision 229 by dpavlin, Mon Nov 23 20:46:30 2009 UTC
# Line 3  package Sack::Server::Gnuplot; Line 3  package Sack::Server::Gnuplot;
3  use warnings;  use warnings;
4  use strict;  use strict;
5    
 use Chart::Gnuplot;  
6  use Data::Dump qw(dump);  use Data::Dump qw(dump);
7    
8  sub date {  sub date {
         my ( $x, $y, $path ) = @_;  
9    
10          $path ||= '/tmp/date.png';          my @plot;
11            my $uid = '';
12    
13          # Create the chart object          foreach my $datafile ( @_ ) {
14          my $chart = Chart::Gnuplot->new(                  my $name = $datafile;
15                  output   => $path,                  $name =~ s/^.+date,// || next;
16                  xlabel   => 'Date axis',                  $name =~ s/\.txt$//;
                 timeaxis => "x",            # declare that x-axis uses time format  
         );  
   
         # Data set object  
         my $data = Chart::Gnuplot::DataSet->new(  
                 xdata   => $x,  
                 ydata   => $y,  
                 style   => 'linespoints',  
                 timefmt => '%Y-%m-%d',      # input time format  
         );  
17    
18          # Plot the graph                  push @plot, qq|"$datafile" using 1:2 title "$name" with linespoints|;
19          $chart->plot2d($data);                  $uid .= $name;
20            }
21    
22            my $path = "/tmp/sack.gnuplot.$uid.png";
23    
24            open(my $gnuplot, '|-', 'gnuplot') || die "gnuplot $!";
25            print $gnuplot qq|
26    
27    set terminal png
28    set output '$path'
29    
30    set xdata time
31    set timefmt "%Y-%m-%d"
32    set format x "%d.%m."
33    #set xrange [ "2009-01-01":"2010-01-01" ]
34    #set yrange [ 0 : ]
35    
36    plot |, join(',', @plot);
37    
38            close($gnuplot);
39    
40          warn "gnuplot $path ", -s $path, " bytes\n";          warn "gnuplot $path ", -s $path, " bytes\n";
41    

Legend:
Removed from v.220  
changed lines
  Added in v.229

  ViewVC Help
Powered by ViewVC 1.1.26