X-Git-Url: http://git.shiar.nl/sheet.git/blobdiff_plain/92c23f29d582b9776292bb186f20c3f4dba4c9f3..fb9b9cbfd0f9077e208a8f00f4a675201fde62c3:/browser.plp
diff --git a/browser.plp b/browser.plp
index e82e69e..75605fd 100644
--- a/browser.plp
+++ b/browser.plp
@@ -1,5 +1,6 @@
<(common.inc.plp)><:
use 5.010;
+use utf8;
use List::Util qw(sum max);
Html({
@@ -8,8 +9,8 @@ Html({
description =>
"caniuse.",
keywords => [qw'html css browser feature'],
- stylesheet => [qw'light dark circus mono red'],
- data => ['caniuse.js'],
+ stylesheet => [qw'circus dark mono red light'],
+ data => ['browser-support.inc.pl'],
});
:>
@@ -19,48 +20,28 @@ Html({
with Wikimedia
browser usage statistics.
+
<:
-use JSON;
-use File::Slurp 'read_file';
-my $source = read_file('caniuse.js');
-for ($source) { # cleanup
- # convert seperate variables to hash keys
- s/\A/{/;
- s/^caniuse\.(\w+) = /"$1":/gm;
- s/;$/,/gm;
- s/,\s*\Z/\n}/;
- # fractions not supported by barekey
- s/(?<=[,{]) (\d*\.\d) (?=:')/"$1"/gx;
- # escapes not supported in singlequote
- s{'((?:[^\\']+|\\.)*)'}{
- my $_ = $1;
- s/"/\\"/g;
- s/\\'/'/g;
- qq("$_");
- }ge;
-}
-my $caniuse = from_json($source, {
-# allow_singlequote => 1,
- allow_barekey => 1,
-});
+my $caniuse = do 'browser-support.inc.pl' or die $! || $@;
my %CSTATS = (
- n => 'di-b',
- y => 'di-aa',
- a => 'di-d',
- 'a x' => 'di-d',
- j => 'di-prop',
- p => 'di-prop',
- 'p j' => 'di-prop',
- 'y x' => 'di-a',
+ 'n' => 'l0',
+ 'y' => 'l6',
+ 'y x' => 'l5',
+ 'a' => 'l4',
+ 'a x' => 'l4',
+ 'p j' => 'l2',
+ 'j' => 'l2',
+ 'p' => 'l2',
+ 'u' => 'l9',
);
my %CSTATUS = (
- unoff => 'di-rare', # unofficial
- wd => 'di-b', # draft
- pr => 'di-prop', # proposed
- cr => 'di-d', # candidate
- rec => 'di-a', # recommendation
- ietf => 'di-aa', # standard
+ unoff => 'l0', # unofficial
+ wd => 'l4', # draft
+ cr => 'l5', # candidate
+ pr => 'l5', # proposed
+ rec => 'l6', # recommendation
+ ietf => 'l6', # standard
);
my @browsers = qw(trident gecko webkit_saf webkit_chr presto);
my %versions;
@@ -70,9 +51,22 @@ if (my ($somerow) = values %{ $caniuse->{data} }) {
}
}
-my $canihas = do 'browser-usage.inc.pl' or do {
+my $canihas = do 'browser-usage.inc.pl' || do {
printf "
Browser usage data not found: %s.
\n", $_
for $! || $@;
+ +{
+ map {
+ $_ => +{
+ map {
+ ($_->[4] => 0 ), # future
+ ($_->[3] => .5), # next
+ ($_->[0] => 5 ), # past
+ ($_->[1] => 10 ), # previous
+ ($_->[2] => 30 ), # current
+ } $caniuse->{agents}->{$_}->{versions}
+ }
+ } @browsers
+ }; # fallback hash based on release semantics
};
my $scorediv = (max(map { sum(values %$_) } values %$canihas) // 1) / 100;
@@ -81,14 +75,31 @@ print '
' x 3;
printf '
', scalar @{ $versions{$_} } for @browsers;
print "\n";
-print '';
-print 'feature';
-printf ' | %s',
- scalar @{ $versions{$_} }, $caniuse->{agents}->{$_}->{browser}
- for @browsers;
+my $header = join('',
+ ' |
',
+ 'feature',
+ (map {
+ sprintf(' | %s',
+ scalar @{ $versions{$_} },
+ sum(values %{ $canihas->{$_} }),
+ do {
+ my $name = $caniuse->{agents}->{$_}->{browser};
+ length $name < 16 ? $name : $caniuse->{agents}->{$_}->{abbr};
+ },
+ )
+ } @browsers),
+ ' | %',
+);
+print '', $header;
# preceding row without any colspan to work around gecko bug
-print '';
-print '' x $_ for 3, (map { scalar @{ $versions{$_} } } @browsers), 1;
+print "\n | ";
+print '' x 3;
+for my $browser (@browsers) {
+ printf(' | %s',
+ $canihas->{$browser}->{$_}, showversions($_),
+ ) for @{ $versions{$browser} };
+}
+print ' | ' x 1;
print " | \n";
sub featurescore {
@@ -96,6 +107,15 @@ sub featurescore {
state $statspts = { y=>10, 'y x'=>9, a=>5, 'a x'=>5, j=>2, 'p j'=>2, p=>1 };
my $rank = 0;
if (my $row = shift) {
+ if ($canihas) {
+ while (my ($browser, $versions) = each %$row) {
+ while (my ($version, $_) = each %$versions) {
+ $rank += $canihas->{$browser}->{$version} * $statspts->{$_};
+ }
+ }
+ return $rank;
+ }
+
while (my ($browser, $vercols) = each %versions) {
my $div = 0; # multiplier exponent (decreased to lower value)
my @vers = map { $row->{$browser}->{$_} } @$vercols;
@@ -125,7 +145,14 @@ for my $id (sort {
my $cell = $_ ? lc $_->[0] : '-';
print ' | ', $cell;
}
- printf ' | %s', $row->{description}, $row->{title};
+ print ' | ', $row->{title};
+ print '';
+ s/\.?$/./, print " $_ " for map { ref $_ ? @$_ : $_ || () }
+ $row->{description}, $row->{notes};
+ printf 'Resources: %s.', join(', ',
+ map { qq( $_->{title}) } @$_
+ ) for $row->{links} // ();
+ print ' ';
for ($row->{status}) {
my $cell = $_ // '-';
$cell = sprintf '%s', $_, $cell for $row->{spec} // ();
@@ -140,12 +167,16 @@ for my $id (sort {
my $usage = sum(map { $canihas->{$browser}->{$_} } @span);
printf ' | %s',
join(' ',
- $CSTATS{ $data->{$browser}->{$prev} },
- sprintf('opacity%.0f', $usage / $scorediv),
+ X => $CSTATS{ $data->{$browser}->{$prev} },
+ !$usage ? ('p0') : ('p',
+ sprintf('p%01d', $usage / 10),
+ sprintf('p%02d', $usage),
+ ),
+ sprintf('pp%02d', $usage / $scorediv),
),
scalar @span,
$usage,
- showversions(\@span),
+ showversions(@span),
undef $prev;
@span = ();
}
@@ -158,36 +189,48 @@ for my $id (sort {
});
print ' | ', int featurescore($caniuse->{data}->{$id}->{stats}) / $maxscore * 100;
}
+print ' |
', $header;
print '';
sub paddedver {
# normalised version number comparable as string (cmp)
shift =~ /^(\d*)(.*)/;
- return sprintf('%02d', $1) . $2;
+ return sprintf('%02d', $1 || 0) . $2;
}
sub showversions {
- my ($span) = @_;
- splice @$span, 1, -1;
- for (@$span) {
+ my @span = ($_[0], @_>1 ? $_[-1] : ());
+ for (@span) {
s/^\./0./;
s/x$/.*/;
}
- return join('â', @$span);
+ return join('â', @span);
}
-:>
+:>
+
- supported
- | prefixed
- | partial
- | external (js/plugin)
- | missing
+ | supported
+ | prefixed
+ | partial
+ | external (js/plugin)
+ | missing
+ | unknown
|
+
+ Usage percentage:
+ 0 -
+ .01 -
+ 1-9 -
+ 10 -
+ 20 -
+ majority
+
+