From 8f8955978d6e17217d81af2c53a6690463f6e800 Mon Sep 17 00:00:00 2001 From: hjp Date: Thu, 18 Sep 2014 12:38:57 +0000 Subject: [PATCH] Option --colors. --- TimeSeries.pm | 27 +++++++++++++++++++++++---- tsplotv | 11 ++++++++--- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/TimeSeries.pm b/TimeSeries.pm index bae3f9e..691b6c1 100644 --- a/TimeSeries.pm +++ b/TimeSeries.pm @@ -33,7 +33,7 @@ use HTTP::Date qw(parse_date); use Time::Local qw(timegm_nocheck); use POSIX qw(strftime); -our $VERSION = do { my @r=(q$Revision: 1.23 $=~/\d+/g);sprintf "%d."."%02d"x$#r,@r}; +our $VERSION = do { my @r=(q$Revision: 1.24 $=~/\d+/g);sprintf "%d."."%02d"x$#r,@r}; our $debug; @@ -292,6 +292,21 @@ sub yrange { } +=head2 colors(@colors) + +Get or set the color palette. + +=cut + +sub colors { + my ($self, @colors) = @_; + + if (@colors) { + $self->{colors} = [@colors]; + } + return @colors; +} + =head2 dstcorr $time [, $period] @@ -399,16 +414,20 @@ sub plot { my $comma = 0; my $col = 2; - for my $i (@{$self->{legend}}) { + for my $i (0 .. $#{$self->{legend}}) { if ($comma) { print $ctlfh ", "; } else { $comma = 1; } + my $legend = $self->{legend}[$i]; if ($self->{style} eq 'filledcurves') { - print $ctlfh "'$datafn' using 1:(\$", $col++, "):(0) title '$i'"; + print $ctlfh "'$datafn' using 1:(\$", $col++, "):(0) title '$legend'"; } else { - print $ctlfh "'$datafn' using 1:(\$", $col++, ") title '$i'"; + print $ctlfh "'$datafn' using 1:(\$", $col++, ") title '$legend'"; + } + if (my $color = $self->{colors}[$i]) { + print $ctlfh " linecolor rgbcolor '$color'"; } } diff --git a/tsplotv b/tsplotv index 25803c3..f87fd7f 100755 --- a/tsplotv +++ b/tsplotv @@ -43,12 +43,13 @@ use Pod::Usage; my $help; my $legend_position = 'top right'; -my $output_format ='png'; +my $output_format = 'png'; my $stacked = 0; my $style = "lines"; -my $log_y =0; +my $log_y = 0; my $finalresolution; -my $time_t =0; +my $time_t = 0; +my $colors; GetOptions('help|?' => \$help, 'legend_position|legend-position=s' => \$legend_position, @@ -58,6 +59,7 @@ GetOptions('help|?' => \$help, 'log_y|log-y' => \$log_y, 'finalresolution' => \$finalresolution, 'time_t' => \$time_t, + 'colors=s' => \$colors, ) or pod2usage(2); pod2usage(1) if $help; @@ -82,6 +84,9 @@ $ts->stacked($stacked); $ts->style($style); $ts->log_y($log_y); $ts->finalresolution($finalresolution) if $finalresolution; +if ($colors) { + $ts->colors(split(/,/, $colors)); +} for my $timestamp (sort keys %data) { my %d = %{$data{$timestamp}};