added the --tsv and --stacked options.

Use Pod::Usage to keep usage message in sync with pod.
This commit is contained in:
hjp 2008-04-22 19:04:02 +00:00
parent 2a5e204878
commit 43d3fed888
1 changed files with 15 additions and 4 deletions

19
tsplot
View File

@ -2,6 +2,7 @@
use strict; use strict;
use TimeSeries; use TimeSeries;
use Getopt::Long; use Getopt::Long;
use Pod::Usage;
=head1 NAME =head1 NAME
@ -15,6 +16,7 @@ tsplotv
[--stacked] [--stacked]
[--style style] [--style style]
[--time_t] [--time_t]
[--tsv]
[file ...] [file ...]
=head1 DESCRIPTION =head1 DESCRIPTION
@ -22,7 +24,8 @@ tsplotv
This program expects time series data in column format, I.e., This program expects time series data in column format, I.e.,
each line contains a timestamp and the values for each series, except 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 the first one which contains the column headers, which are used for the
legend. Columns are separated by any amount of whitespace. legend. Columns are separated by any amount of whitespace unless the
--tsv option is given which enables tab-separated columns.
The default legend position is "top right", same as with gnuplot. The default legend position is "top right", same as with gnuplot.
Another frequently useful position (especially if you have lots of series) Another frequently useful position (especially if you have lots of series)
@ -47,25 +50,32 @@ my $output_format ='png';
my $log_y =0; my $log_y =0;
my $time_t =0; my $time_t =0;
my $style = "lines"; my $style = "lines";
my $tsv = 0;
my $stacked = 0;
GetOptions('output_format|output-format=s' => \$output_format, GetOptions('output_format|output-format=s' => \$output_format,
'log_y|log-y' => \$log_y, 'log_y|log-y' => \$log_y,
'time_t' => \$time_t, 'time_t' => \$time_t,
'style:s' => \$style, 'style:s' => \$style,
'tsv' => \$tsv,
'stacked' => \$stacked,
) )
or die "Usage: $0 [--output_format format] [files...]\n"; or pod2usage(verbose => 0);
my $sep = $tsv ? qr/\t/ : ' ';
binmode STDOUT, ':raw'; binmode STDOUT, ':raw';
my $ts = TimeSeries->new(output_format => $output_format); my $ts = TimeSeries->new(output_format => $output_format);
while (<>) { while (<>) {
my @legend = split; chomp;
my @legend = split($sep);
shift @legend; # first must be for timestamp shift @legend; # first must be for timestamp
$ts->legend(@legend); $ts->legend(@legend);
last; last;
} }
while (<>) { while (<>) {
my ($timestamp, @values) = split(); chomp;
my ($timestamp, @values) = split($sep);
if ($time_t) { if ($time_t) {
$ts->add($timestamp, @values); $ts->add($timestamp, @values);
} else { } else {
@ -74,6 +84,7 @@ while (<>) {
} }
$ts->log_y($log_y); $ts->log_y($log_y);
$ts->style($style); $ts->style($style);
$ts->stacked($stacked);
my $g = $ts->plot(); my $g = $ts->plot();
print $g print $g