browser: adjust legend without usage data
[sheet.git] / browser.plp
index e4e0b2851783581101aed96a39b0d56ec25047ee..198b2781a4a7d120986c18c4e7a5d29517a01ea6 100644 (file)
@@ -16,18 +16,27 @@ Html({
 :>
 <h1>Browser compatibility</h1>
 
-<p>Alternate view of Fyrd's <a href="http://caniuse.com/">when can I use...</a> page
-<:
-my $canihas = do 'browser-usage.inc.pl'
-       or printf "<p>Browser usage data not found: <em>%s</em>.</p>\n", $! || $@;
-
-print "with $_ browser usage statistics." for map {
-       my $ref = $_->{-source} || 'unknown';
-       $ref = sprintf '<a href="%s">%s</a>', $_, $ref for $_->{-url} || ();
-       $ref .= " $_" for $_->{-date} || ();
-       $ref
-} $canihas || ();
-:>
+<p>Alternate view of Fyrd's <a href="http://caniuse.com/">when can I use...</a> page<:
+my ($canihas, $usage);
+given ($get{usage} // 'wm') {
+       when (!$_) {
+               # none
+       }
+       when (!/^\w+$/) {
+               printf "<p>Invalid browser usage data request: <em>%s</em>",
+                       'identifier must be alphanumeric name or <q>0</q>';
+       }
+       $canihas = do "browser-usage-$_.inc.pl" or do {
+               printf "<p>Browser usage data not found: <em>%s</em>", $! || $@;
+               break;
+       };
+       $usage = $_;
+       my $ref = $canihas->{-source} || 'unknown';
+       $ref = sprintf '<a href="%s">%s</a>', $_, $ref for $canihas->{-url} || ();
+       $ref .= " $_" for $canihas->{-date} || ();
+       print "\nwith $ref browser usage statistics";
+}
+:>.
 </p>
 
 <div id="browser">
@@ -243,7 +252,7 @@ sub showversions {
        <td class="X l0">unknown
        </table>
 
-       <div>
+       <p><: if ($usage) { :>
                Usage percentage:
                <span class="  p0">0</span> -
                <span class="p p0 p00">.01</span> -
@@ -251,12 +260,21 @@ sub showversions {
                <span class="p p1">10</span> -
                <span class="p p2">20</span> -
                <span class="p p5">majority</span>
-       </div>
+<: } else { :>
+               <table class="glyphs"><tr>
+                       <td class="p p1">previous version</td>
+                       <td class="p p3">current</td>
+                       <td class="p p0 p00">upcoming (within months)</td>
+                       <td class="  p0">future (within a year)</td>
+               </table>
+<: } :>        </p>
 
        <div class="right">
                <ul class="legend legend-set">
                <li>default <strong>style</strong> is
                        <:= defined $get{style} && 'set to ' :><em><:= $style :></em>
+               <li><strong>usage</strong> source is
+                       <:= !defined $get{usage} && 'default ' :><:= defined $usage ? "<em>$usage</em>" : 'not included (<em>0</em>)' :>
                </ul>
        </div>
 </div>