Handle missing values.

This commit is contained in:
hjp 2006-09-08 10:26:36 +00:00
parent 690629d95f
commit 22da4bd59d
2 changed files with 45 additions and 3 deletions

View File

@ -27,7 +27,7 @@ use Data::Dumper;
use HTTP::Date qw(parse_date); use HTTP::Date qw(parse_date);
use Time::Local qw(timegm_nocheck); use Time::Local qw(timegm_nocheck);
$VERSION = do { my @r=(q$Revision: 1.13 $=~/\d+/g);sprintf "%d."."%02d"x$#r,@r}; $VERSION = do { my @r=(q$Revision: 1.14 $=~/\d+/g);sprintf "%d."."%02d"x$#r,@r};
=head2 new(%opts) =head2 new(%opts)
@ -330,7 +330,7 @@ sub plot {
} }
} else { } else {
for my $j (@$data) { for my $j (@$data) {
print $datafh "\t", ($j || 0) + 0; print $datafh "\t", (defined $j ? $j : '?');
} }
} }
print $datafh "\n"; print $datafh "\n";
@ -349,6 +349,7 @@ sub plot {
print $ctlfh "set log x\n" if ($self->{log_x}); print $ctlfh "set log x\n" if ($self->{log_x});
print $ctlfh "set log y\n" if ($self->{log_y}); print $ctlfh "set log y\n" if ($self->{log_y});
print $ctlfh "set key $self->{legend_position}\n" if ($self->{legend_position}); print $ctlfh "set key $self->{legend_position}\n" if ($self->{legend_position});
print $ctlfh "set datafile missing '?'\n";
# compute ticks # compute ticks
@ -522,7 +523,7 @@ sub plot {
} else { } else {
$comma = 1; $comma = 1;
} }
print $ctlfh "'$datafn' using 1:", $col++, " title '$i'"; print $ctlfh "'$datafn' using 1:(\$", $col++, ") title '$i'";
} }
print $ctlfh "\n"; print $ctlfh "\n";

41
t/3missing.t Normal file
View File

@ -0,0 +1,41 @@
#!/usr/bin/perl
use warnings;
use strict;
use Test::More tests => 3;
BEGIN { use_ok( 'TimeSeries' ); }
my $ts = TimeSeries->new(output_format => 'ps');
ok($ts, 'create timeseries');
$ts->add(0, 100);
$ts->add(1000, 200);
$ts->add(2000, 100);
$ts->add(3000, undef);
$ts->add(4000, 100);
$ts->add(5000, 200);
$ts->add(6000, 100);
$ts->legend('missing');
my $p = $ts->plot();
my $t = "LT0
6395 4739 M
399 0 V
574 1344 M
1639 4872 L
2703 1344 L
2130 0 R
5897 4872 L
6962 1344 L
1.000 UL
LTb
574 1344 M
6388 0 V
0 3528 V
-6388 0 V
0 -3528 V
1.000 UP
stroke";
ok(index($p, $t) != -1, 'postscript output looks ok');
#vim:tw=0