#!/usr/local/bin/perl -w
###########################################
# graph-discharge - Fancy XY Plots 
#                   with Google Charts 
# Mike Schilli, 2009 (m@perlmeister.com)
###########################################
use strict;
use Google::Chart;
use Google::Chart::Marker;

my $data = {};

open PIPE, "./data-normalize |" or die;
while(<PIPE>) {
    chomp;
    my($symbol, $x, $y) = split ' ', $_;
    next unless $y;
    push @{ $data->{ $symbol }->{x} }, $x;
    push @{ $data->{ $symbol }->{y} }, $y;
}
close PIPE or die;

my $graph = Google::Chart->new(
  type => 'XY',

  data => [$data->{"0.5gb"}->{x}, 
           $data->{"0.5gb"}->{y},
           $data->{"2gb"}->{x},
           $data->{"2gb"}->{y},
          ],

  size => '750x400',

  title => {
    text => "Dell Mini Standby Discharge"
  },

  fill => {
    module => "LinearGradient",
    args   => {
      target  => "c",
      angle   => 45,
      color1  => "abbaab",
      offset1 => 1,
      color2  => "FFFFFF",
      offset2 => 0,
    }
  },

  grid => {
    x_step_size => 33,
    y_step_size => 20,
  },

  axis => [ 
    { location => 'x',
      labels => [1..36],
    },
    { location => 'y',
      labels => [0,25,50,75,100],
    },
  ],

  color => ['E6E9FD', '4D89F9'],

  legend => ['0.5gb', '2gb'],

  margin => [50, 50, 50, 50, 100, 100],

  marker =>  Google::Chart::Marker->new(
    markerset => [ 
      { marker_type => 'x',
        color => 'FFCC33',
        dataset   => 0,
        datapoint => -1,
        size => 15,
        priority => 1,
      },
      { marker_type => 'x',
        color => 'FF0000',
        dataset   => 1,
        datapoint => -1,
        size => 15,
        priority => 1,
      },
      { marker_type => 'D',
        color => 'E6E9FD', # light blue
        dataset   => 0,
        datapoint => -1,
        size => 4,
        priority => -1,
      },
      { marker_type => 'D',
        color => '4D89F9', # blue
        dataset   => 1,
        datapoint => -1,
        size => 4,
        priority => -1,
      },
    ]),
);

$graph->render_to_file(filename => 
                       "chart.png");
system("xv chart.png");

