From 99f7bdff4aa142fdbddfa5b95728aee3a9856019 Mon Sep 17 00:00:00 2001 From: hjp Date: Tue, 26 Sep 2006 09:15:55 +0000 Subject: [PATCH] Add new grid spacing for less than 6 hours. --- TimeSeries.pm | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/TimeSeries.pm b/TimeSeries.pm index e429a7e..5f317fd 100644 --- a/TimeSeries.pm +++ b/TimeSeries.pm @@ -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.14 $=~/\d+/g);sprintf "%d."."%02d"x$#r,@r}; +$VERSION = do { my @r=(q$Revision: 1.15 $=~/\d+/g);sprintf "%d."."%02d"x$#r,@r}; =head2 new(%opts) @@ -487,8 +487,8 @@ sub plot { } $lasttime = $time; print $ctlfh ")\n"; - } else { - # less than 2 days: 1 tick per hour. + } elsif ($lasttime - $firsttime > 6 * 3600) { + # 6 hours to 2 days: 1 tick per hour. my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($firsttime); $sec = $min = 0; @@ -509,6 +509,30 @@ sub plot { } $lasttime = $time; print $ctlfh ")\n"; + } else { + # less than 6 hours: 1 tick per minute. + # (ok, that's too much - need to find some intermediate steps, + # but for now I need graphs over a few minutes. + + my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($firsttime); + $sec = 0; + my $time = $firsttime = timelocal($sec,$min,$hour,$mday,$mon,$year); + print $ctlfh "set xtics rotate ("; + my $comma = 0; + for (;;) { + ($sec,$min,$hour,$mday,$mon,$year) = localtime($time); + if ($comma) { + print $ctlfh ", "; + } else { + $comma = 1; + } + printf $ctlfh qq|"%04d-%02d-%02d %02d:%02d" %d|, $year+1900, $mon+1, $mday, $hour, $min, $time; + if ($time > $lasttime) {last} + + $time += 60; + } + $lasttime = $time; + print $ctlfh ")\n"; } # what to plot