diff --git a/tsplotv b/tsplotv index f87fd7f..6f28d1a 100755 --- a/tsplotv +++ b/tsplotv @@ -13,6 +13,9 @@ tsplotv [--output-format format ] [--stacked] [--style style] +[--time_t] +[--colors rgb-list] +[--configfile yaml] [file ...] =head1 DESCRIPTION @@ -40,6 +43,7 @@ use strict; use TimeSeries; use Getopt::Long; use Pod::Usage; +use YAML qw(LoadFile); my $help; my $legend_position = 'top right'; @@ -50,6 +54,7 @@ my $log_y = 0; my $finalresolution; my $time_t = 0; my $colors; +my $configfile; GetOptions('help|?' => \$help, 'legend_position|legend-position=s' => \$legend_position, @@ -60,33 +65,46 @@ GetOptions('help|?' => \$help, 'finalresolution' => \$finalresolution, 'time_t' => \$time_t, 'colors=s' => \$colors, + 'configfile=s' => \$configfile, ) or pod2usage(2); pod2usage(1) if $help; +my $config = LoadFile($configfile) if $configfile; binmode STDOUT, ':raw'; -my %series; -my $ns; +my $ns = 0; my %data; -my $ts = TimeSeries->new(output_format => $output_format); +$config->{timeseries} //= {}; +for (keys $config->{timeseries}) { + $ns = $config->{timeseries}{$_}{order} if ($config->{timeseries}{$_}{order} // 0) > $ns; +} + while (<>) { chomp; my ($timestamp, $series, $value) = split(/\t/); - $series{$series} = ++$ns unless ($series{$series}); + $config->{timeseries}{$series}{order} = ++$ns unless ($config->{timeseries}{$series}{order}); $data{$timestamp}{$series} = $value; } -my @series = sort { $series{$a} <=> $series{$b} } keys %series; +my @series = sort { $config->{timeseries}{$a}{order} <=> $config->{timeseries}{$b}{order} } + keys $config->{timeseries}; +if ($colors) { + my @colors = split(/,/, $colors); + while (my ($i, $c) = each(@colors)) { + $config->{timeseries}{$series[$i]}{color} = $c; + } +} + + +my $ts = TimeSeries->new(output_format => $output_format); $ts->legend(@series); $ts->legend_position($legend_position); $ts->stacked($stacked); $ts->style($style); $ts->log_y($log_y); $ts->finalresolution($finalresolution) if $finalresolution; -if ($colors) { - $ts->colors(split(/,/, $colors)); -} +$ts->colors(map $config->{timeseries}{$_}{color}, @series); for my $timestamp (sort keys %data) { my %d = %{$data{$timestamp}};