diff --git a/t/1.data b/t/1.data new file mode 100644 index 0000000..3bbc7d5 --- /dev/null +++ b/t/1.data @@ -0,0 +1,4 @@ +date val1 val2 +2006-06-01 1 4 +2006-07-01 2 1 +2006-08-01 4 0 diff --git a/t/1.vdata b/t/1.vdata new file mode 100644 index 0000000..2783f26 --- /dev/null +++ b/t/1.vdata @@ -0,0 +1,6 @@ +2006-06-01 val1 1 +2006-06-01 val2 4 +2006-07-01 val1 2 +2006-07-01 val2 1 +2006-08-01 val1 4 +2006-08-01 val2 0 diff --git a/t/2scripts.t b/t/2scripts.t new file mode 100755 index 0000000..638f61f --- /dev/null +++ b/t/2scripts.t @@ -0,0 +1,24 @@ +#!/usr/bin/perl +use warnings; +use strict; +use Test::More tests => 7; + +my $ps1=`./blib/script/tsplot --output_format ps t/1.data`; +ok($ps1, 'Postscript output of tsplot is not empty'); +ok($ps1 =~ m/\(2006-06-04\) Rshow/, 'Postscript output of tsplot contains a date'); +ok($ps1 =~ m/\(val1\) Rshow/, 'Postscript output of tsplot contains a column name'); + +my $ps2=`./blib/script/tsplotv --output_format ps t/1.vdata`; +ok($ps2, 'Postscript output of tsplot is not empty'); +ok($ps2 =~ m/\(2006-06-04\) Rshow/, 'Postscript output of tsplot contains a date'); +ok($ps2 =~ m/\(val1\) Rshow/, 'Postscript output of tsplot contains a column name'); + +# title and creation date will be different, but the rest should be +# identical: +$ps1 =~ s/^%%Title: .*//m; +$ps1 =~ s/^%%CreationDate: .*//m; +$ps2 =~ s/^%%Title: .*//m; +$ps2 =~ s/^%%CreationDate: .*//m; +ok($ps1 eq $ps2, 'output of tsplot and tsplotv are identical'); + +#vim:tw=0 diff --git a/tsplot b/tsplot index b7fe042..0135625 100755 --- a/tsplot +++ b/tsplot @@ -1,10 +1,16 @@ #!/usr/bin/perl -w use strict; use TimeSeries; +use Getopt::Long; + +my $output_format ='png'; +GetOptions('output_format|output-format=s' => \$output_format) + or die "Usage: $0 [--output_format format] [files...]\n"; + binmode STDOUT, ':raw'; -my $ts = TimeSeries->new(); +my $ts = TimeSeries->new(output_format => $output_format); while (<>) { my @legend = split; shift @legend; # first must be for timestamp diff --git a/tsplotv b/tsplotv index 80fa693..8964212 100755 --- a/tsplotv +++ b/tsplotv @@ -13,6 +13,16 @@ each line contains a tripel . use strict; use TimeSeries; +use Getopt::Long; + +my $output_format ='png'; +my $stacked = 0; +my $legend_position = 'top right'; +GetOptions('output_format|output-format=s' => \$output_format, + 'stacked' => \$stacked, + 'legend_position|legend-position=s' => \$legend_position, +) or die "Usage: $0 [--output_format format] [files...]\n"; + binmode STDOUT, ':raw'; @@ -20,7 +30,7 @@ my %series; my $ns; my %data; -my $ts = TimeSeries->new(); +my $ts = TimeSeries->new(output_format => $output_format); while (<>) { chomp; my ($timestamp, $series, $value) = split(/\t/); @@ -29,8 +39,8 @@ while (<>) { } my @series = sort { $series{$a} <=> $series{$b} } keys %series; $ts->legend(@series); -$ts->legend_position("below"); -$ts->stacked(1); +$ts->legend_position($legend_position); +$ts->stacked($stacked); for my $timestamp (sort keys %data) { my %d = %{$data{$timestamp}}; my @values = @d{@series};