doclist: background width to end line at last item
authorMischa POSLAWSKY <perl@shiar.org>
Fri, 29 Nov 2019 22:09:15 +0000 (23:09 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Sat, 30 Nov 2019 00:18:30 +0000 (01:18 +0100)
Assuming stylesheet draws a line by background-image, calculate its size to
target the earliest item.

widget/doclist.php

index 5c11c6867bace1d99f0c605eda64b5efa4c3709f..589c8d6afcb5a05ccc494d74fc39a70ad5bf4127 100644 (file)
@@ -16,14 +16,17 @@ foreach (glob("$Page$Args/2*") as $url) {
 }
 
 $year = 3600 * 24 * 365;  # seconds per year
-$scale = 8;  # em width per year
-$mindate = strtotime($date) + ($year / $scale * 3);  # first point plus about 3em for centered text
+$scale = 7;  # em width per year
+$mindate = max(time(), strtotime($date) + ($year / $scale * 3));  # at least last entry plus 3em for centered text
+$length = ($mindate - strtotime(key(current($cal)))) / $year * $scale;  # earliest entry position
 
-print '<ul class="timeline">'."\n";
+printf('<ul class="timeline" style="background-size:%.1fem">'."\n", $length);
 foreach (array_reverse($cal, TRUE) as $group => $rows) {
        if (count($rows) > 1) {
                $time = ($mindate - strtotime("$group-12-31T23:59")) / $year * $scale;
-               printf('<li class="range" style="left:%.1fem; width:%sem">', $time, $scale);
+               printf('<li class="range" style="left:%.1fem; width:%.1fem">',
+                       $time, $time + $scale > $length ? $length - $time + 2 : $scale
+               );
                print "<strong>$group</strong><ul>\n";
        }
        else {