X-Git-Url: http://git.shiar.nl/sheet.git/blobdiff_plain/4e46e11f48bd75bb78cc5b310166287789efdd53..f73ec42018bd7c627db8742c92636074033f19e4:/browser.plp diff --git a/browser.plp b/browser.plp index 55d5e65..a101d74 100644 --- a/browser.plp +++ b/browser.plp @@ -1,11 +1,10 @@ <(common.inc.plp)><: -use 5.010; -use utf8; use List::Util qw(sum max first); +no if $] >= 5.018, warnings => 'experimental::smartmatch'; Html({ title => 'browser compatibility cheat sheet', - version => 'v1.1', + version => '1.4', description => [ "Compatibility table of new web features (HTML5, CSS3, SVG, Javascript)", "comparing support and usage share for all popular browser versions.", @@ -16,12 +15,12 @@ Html({ ie internet explorer firefox chrome safari webkit opera '], stylesheet => [qw'circus dark mono red light'], - data => ['browser-support.inc.pl'], + data => ['data/browser/support.inc.pl'], }); say "
Alternate rendition of Fyrd's when can I use... page my ($canihas, $usage); -my $minusage = $get{threshold} // .7; +my $minusage = $get{threshold} // 1; given ($get{usage} // 'wm') { when (!$_) { # none } - when (!/^[a-z][\w-]+$/) { - printf "
Invalid browser usage data request: %s",
- 'identifier must be alphanumeric name or 0
';
+ when (!m{ \A [a-z]\w+ (?:/\d[\d-]*\d)? \z }x) {
+ Alert([
+ 'Invalid browser usage data request',
+ 'Identifier must be alphanumeric name or 0
.',
+ ]);
}
- $canihas = do "browser-usage-$_.inc.pl" or do {
- printf "
Browser usage data not found: %s", $! || $@; + $canihas = do "data/browser/usage-$_.inc.pl" or do { + Alert('Browser usage data not found', $@ || $!); break; }; $usage = $_; my $ref = $canihas->{-title} || 'unknown'; - $ref = sprintf '%s', $_, $ref + $ref = showlink($ref, $_) for $canihas->{-site} || $canihas->{-source} || (); $ref .= " $_" for $canihas->{-date} || (); print "\nwith $ref browser usage statistics"; @@ -159,6 +170,7 @@ if ($usage) { # first() does not work inside given >:( } else { # order browser columns by name grouped by engine + @{$_} = map { [$_] } @{$_} for values %versions; @browsers = sort { $caniuse->{agents}->{$b}->{prefix} cmp $caniuse->{agents}->{$a}->{prefix} @@ -184,13 +196,14 @@ $canihas ||= { } } @browsers }; # fallback hash based on release semantics -my $usagemax = (max(map { ref $_ eq 'HASH' && sum(values %$_) } values %$canihas) // 1) / 100; my $usagepct = 1; # score multiplier for 0..100 result # normalise usage percentage to only include shown browsers $usagepct = 100.01 / featurescore({ # yes for every possible version map { $_ => { map {$_ => 'y'} map { @{$_} } @{$versions{$_}} } } keys %versions }); +$_->{usage} = featurescore($_->{stats}) * $usagepct + for values %{ $caniuse->{data} }; print '
%s', $caniuse->{statuses}->{$_}, $CSTATUS{$_} // '', $cell; } @@ -363,12 +402,12 @@ sub saybrowsercols { # prepare version hover details my $title = sprintf('%.1f%% %s', $usage * $usagepct, join(', ', - map { ref $_ eq 'CODE' ? $_->($browser) : $_ } + map { ref $_ eq 'CODE' ? $_->($browser, $span[0]->[0]) : $_ } map { $DSTATS{$_} // () } map { split / /, $_ } $prev )); - $title .= "\n".EscapeHTML($_) for @notes; + $title .= "\n$_" for notestotitle(@notes); printf(' | %s', join(' ', @@ -377,7 +416,6 @@ sub saybrowsercols { sprintf('p%01d', $usage * ($usagepct - .0001) / 10), sprintf('p%02d', $usage * ($usagepct - .0001)), ), - sprintf('pp%02d', $usage / $usagemax), ), scalar @span, $title, @@ -393,13 +431,12 @@ sub saybrowsercols { sub sayusagecol { my ($id) = @_; - print ' | ', int featurescore($caniuse->{data}->{$id}->{stats}) * $usagepct; + print ' | ', int $caniuse->{data}->{$id}->{usage}; } say ' | '; for my $id (sort { - featurescore($caniuse->{data}->{$b}->{stats}) - <=> featurescore($caniuse->{data}->{$a}->{stats}) + $caniuse->{data}->{$b}->{usage} <=> $caniuse->{data}->{$a}->{usage} } keys %{ $caniuse->{data} }) { $caniuse->{data}->{$id}->{stats} or next; # skip metadata [summary] printf '