Added method legend_position

This commit is contained in:
hjp 2005-11-27 11:16:55 +00:00
parent e231f5e307
commit 2bc741058c
2 changed files with 28 additions and 2 deletions

View File

@ -27,7 +27,7 @@ use Data::Dumper;
use HTTP::Date qw(parse_date);
use Time::Local qw(timegm_nocheck);
$VERSION = do { my @r=(q$Revision: 1.10 $=~/\d+/g);sprintf "%d."."%02d"x$#r,@r};
$VERSION = do { my @r=(q$Revision: 1.11 $=~/\d+/g);sprintf "%d."."%02d"x$#r,@r};
=head2 new(%opts)
@ -129,6 +129,21 @@ sub legend {
return $oldlegend ? @$oldlegend : ();
}
=head2 legend_position($position)
Set the position of the legend. Currently, this is simply a string passed
to gnuplot's "set key" command. Valid positions are left, right, top, bottom,
outside, below and everything else gnuplot understands.
=cut
sub legend_position {
my ($self, $legend_position) = @_;
my $oldlegend_position = $self->{legend_position};
$self->{legend_position} = $legend_position if ($legend_position);
return $oldlegend_position;
}
=head2 style([$style])
Sets a new style if $style is given. In any case the old style is
@ -310,6 +325,7 @@ sub plot {
print $ctlfh "set grid\n";
print $ctlfh "set log x\n" if ($self->{log_x});
print $ctlfh "set log y\n" if ($self->{log_y});
print $ctlfh "set key $self->{legend_position}\n" if ($self->{legend_position});
# compute ticks

View File

@ -6,7 +6,7 @@
# Change 1..1 below to 1..last_test_to_print .
# (It may become useful if the test is moved to ./t subdirectory.)
BEGIN { $| = 1; print "1..6\n"; }
BEGIN { $| = 1; print "1..7\n"; }
END {print "not ok 1\n" unless $loaded;}
use TimeSeries;
$loaded = 1;
@ -71,3 +71,13 @@ if (length($g) > 0 && substr($g, 0, 2) eq "%!") {
print "not ok $test\n";
}
$test = 7;
$ts->legend_position("below");
$g = $ts->plot();
# print STDERR "length \$g = ", length($g), "\n";
if (length($g) > 0 && substr($g, 0, 2) eq "%!") {
print "ok $test\n";
} else {
print "not ok $test\n";
}