From 7fc7cb46a99249e6f8fc4af50bd6c4396e2d6bdc Mon Sep 17 00:00:00 2001 From: "Peter J. Holzer" Date: Sat, 15 Feb 2020 12:52:00 +0100 Subject: [PATCH] Suppress repeated prefixes in timestamps Always printing the full timestamp makes the graph look cluttered. So we print only the first in full format and then only the part suffix that changed since the previous one. This gives us a nice major/minor pattern. --- TimeSeries.pm | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/TimeSeries.pm b/TimeSeries.pm index 68087b0..c70e9a0 100644 --- a/TimeSeries.pm +++ b/TimeSeries.pm @@ -616,11 +616,27 @@ sub get_ticks { $nexttime = sub { return $_[0] + 60 }; } - my $time = $firsttime; + my $time = $nexttime->($firsttime); + my $llb; for (;;) { - push @ticks, [$time, strftime($label, localtime($time))]; + my $lb = strftime($label, localtime($time)); + my $dlb = $lb; + if ($llb) { + my @lc = split(/(\d+)/, $llb); + my @c = split(/(\d+)/, $lb); + for my $i (0 .. $#c) { + if ($c[$i] eq $lc[$i]) { + $c[$i] = " " x length($c[$i]); + } else { + last; + } + } + $dlb = join("", @c); + } + push @ticks, [$time, $dlb]; if ($time > $lasttime) {last} $time = $nexttime->($time); + $llb = $lb; } return @ticks;