From 43d3fed8884613704759b6e5f3db5927745bdc07 Mon Sep 17 00:00:00 2001 From: hjp Date: Tue, 22 Apr 2008 19:04:02 +0000 Subject: [PATCH] added the --tsv and --stacked options. Use Pod::Usage to keep usage message in sync with pod. --- tsplot | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/tsplot b/tsplot index 37c4ae1..bd22c03 100755 --- a/tsplot +++ b/tsplot @@ -2,6 +2,7 @@ use strict; use TimeSeries; use Getopt::Long; +use Pod::Usage; =head1 NAME @@ -15,6 +16,7 @@ tsplotv [--stacked] [--style style] [--time_t] +[--tsv] [file ...] =head1 DESCRIPTION @@ -22,7 +24,8 @@ tsplotv 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. +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. Another frequently useful position (especially if you have lots of series) @@ -47,25 +50,32 @@ my $output_format ='png'; my $log_y =0; my $time_t =0; my $style = "lines"; +my $tsv = 0; +my $stacked = 0; GetOptions('output_format|output-format=s' => \$output_format, 'log_y|log-y' => \$log_y, 'time_t' => \$time_t, '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'; my $ts = TimeSeries->new(output_format => $output_format); while (<>) { - my @legend = split; + chomp; + my @legend = split($sep); shift @legend; # first must be for timestamp $ts->legend(@legend); last; } while (<>) { - my ($timestamp, @values) = split(); + chomp; + my ($timestamp, @values) = split($sep); if ($time_t) { $ts->add($timestamp, @values); } else { @@ -74,6 +84,7 @@ while (<>) { } $ts->log_y($log_y); $ts->style($style); +$ts->stacked($stacked); my $g = $ts->plot(); print $g