From 03cb462f75380d9690505e2a8a25f2d8b9b5353e Mon Sep 17 00:00:00 2001 From: hjp Date: Thu, 24 Apr 2003 14:39:01 +0000 Subject: [PATCH] Added new scaling (1 tick/3 months) for series longer than 3 years. --- TimeSeries.pm | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/TimeSeries.pm b/TimeSeries.pm index af9311c..66a66d0 100644 --- a/TimeSeries.pm +++ b/TimeSeries.pm @@ -4,7 +4,7 @@ use File::Temp qw(tempfile); use Time::Local; use Data::Dumper; -$VERSION = do { my @r=(q$Revision: 1.3 $=~/\d+/g);sprintf "%d."."%02d"x$#r,@r}; +$VERSION = do { my @r=(q$Revision: 1.4 $=~/\d+/g);sprintf "%d."."%02d"x$#r,@r}; sub new { my ($class, %opts) = @_; @@ -117,7 +117,32 @@ sub plot { my $firsttime = $self->{data}[0][0]; my $lasttime = $self->{data}[$#{$self->{data}}][0]; - if ($lasttime - $firsttime > 3 * 30 * 24 * 3600) { + if ($lasttime - $firsttime > 3 * 365 * 24 * 3600) { + my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($firsttime); + $sec = $min = $hour = 0; + $mday = 1; + $mon = int($mon/3) * 3; + $firsttime = timelocal($sec,$min,$hour,$mday,$mon,$year); + print $ctlfh "set xtics rotate ("; + my $comma = 0; + my $time; + for (;;) { + $time = timelocal($sec,$min,$hour,$mday,$mon,$year); + if ($comma) { + print $ctlfh ", "; + } else { + $comma = 1; + } + printf $ctlfh qq|"%04d-%02d-%02d" %d|, $year+1900, $mon+1, $mday, $time; + $mon += 3; + if ($mon >= 12) { + $mon -= 12; $year++; + } + if ($time > $lasttime) {last} + } + $lasttime = $time; + print $ctlfh ")\n"; + } elsif ($lasttime - $firsttime > 3 * 30 * 24 * 3600) { my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($firsttime); $sec = $min = $hour = 0; $mday = 1;