Added --log-y option to tsplot and a test case.

This commit is contained in:
hjp 2006-10-25 08:52:00 +00:00
parent b7cba90cc7
commit f3308007c0
2 changed files with 51 additions and 2 deletions

View File

@ -1,7 +1,7 @@
#!/usr/bin/perl #!/usr/bin/perl
use warnings; use warnings;
use strict; use strict;
use Test::More tests => 7; use Test::More tests => 11;
my $ps1=`./blib/script/tsplot --output_format ps t/1.data`; my $ps1=`./blib/script/tsplot --output_format ps t/1.data`;
ok($ps1, 'Postscript output of tsplot is not empty'); ok($ps1, 'Postscript output of tsplot is not empty');
@ -21,4 +21,14 @@ $ps2 =~ s/^%%Title: .*//m;
$ps2 =~ s/^%%CreationDate: .*//m; $ps2 =~ s/^%%CreationDate: .*//m;
ok($ps1 eq $ps2, 'output of tsplot and tsplotv are identical'); ok($ps1 eq $ps2, 'output of tsplot and tsplotv are identical');
my $ps3=`./blib/script/tsplot --output_format ps --log_y t/1.data`;
ok($ps3, 'Postscript output of tsplot is not empty');
ok($ps3 !~ m/\( 0\) Rshow/, 'Postscript output of tsplot doesn\'t contain marker "0"');
ok($ps3 =~ m/\( 1\) Rshow/, 'Postscript output of tsplot contains marker "1"');
ok($ps3 =~ m/\( 10\) Rshow/, 'Postscript output of tsplot contains marker "10"');
my $fh;
open($fh, ">", "t/$$.lin.ps"); print $fh $ps1; close($fh);
open($fh, ">", "t/$$.log.ps"); print $fh $ps3; close($fh);
#vim:tw=0 #vim:tw=0

41
tsplot
View File

@ -3,8 +3,46 @@ use strict;
use TimeSeries; use TimeSeries;
use Getopt::Long; use Getopt::Long;
=head1 NAME
tsplot - plot time series in column format
=head1 SYNOPSIS
tsplotv
[--legend-position pos]
[--output-format format ]
[--stacked]
[--style style]
[file ...]
=head1 DESCRIPTION
This program expects time series data in column format, I.e.,
each line contains a timestamp and the values for each series, except
the first one which contains the column headers, which are used for the
legend. Columns are separated by any amount of whitespace.
The default legend position is "top right", same as with gnuplot.
Another frequently useful position (especially if you have lots of series)
is "below. Note that positions which consist of several world (such as
"top right" need to be passed to tsplotv as a single argument, so the
space needs to be hidden from the shell by use of quotes or a backslash.
The default output format is "png", the default style is "lines".
See L<TimeSeries> for a description of possible legend positions,
output formats, and styles.
The --stacked option causes the time series to be stacked on top of each
other.
=cut
my $output_format ='png'; my $output_format ='png';
GetOptions('output_format|output-format=s' => \$output_format) my $log_y =0;
GetOptions('output_format|output-format=s' => \$output_format,
'log_y|log-y' => \$log_y,
)
or die "Usage: $0 [--output_format format] [files...]\n"; or die "Usage: $0 [--output_format format] [files...]\n";
@ -21,6 +59,7 @@ while (<>) {
my ($timestamp, @values) = split(); my ($timestamp, @values) = split();
$ts->add_timestring($timestamp, @values); $ts->add_timestring($timestamp, @values);
} }
$ts->log_y($log_y);
my $g = $ts->plot(); my $g = $ts->plot();
print $g print $g