X-Git-Url: http://git.shiar.net/sheet.git/blobdiff_plain/08b6414f6e36757737a9a796c697700e70af05c3..1f0b91c9e5d48128a3a62a1d75a0d047e66351fc:/browser.plp
diff --git a/browser.plp b/browser.plp
index 1158334..322fa36 100644
--- a/browser.plp
+++ b/browser.plp
@@ -23,12 +23,19 @@ say "
Browser compatibility
\n";
my $caniuse = do 'browser-support.inc.pl' or die $! || $@;
$_->{verrelease} = {
- # mark last two (future) versions as unreleased, ensure current isn't
- map { $_->[-1] => 0, $_->[-2] => 0, $_->[-3] => undef } $_->{versions}
+ # mark last three (future) versions as unreleased, ensure current isn't
+ map {
+ $_->[-1] => 0, $_->[-2] => 0, $_->[-3] => 0,
+ $_->[-4] => undef,
+ } $_->{versions}
} for values %{ $caniuse->{agents} };
my %CSTATS = (
'n' => 'l1',
+ 'n d' => 'l2',
+ 'n x d' => 'l2 ex',
+ 'p d' => 'l2',
+ 'a d' => 'l2',
'y' => 'l5',
'y x' => 'l5 ex',
'a' => 'l3',
@@ -46,6 +53,7 @@ my %DSTATS = (
j => 'javascript required',
a => 'partial',
y => 'supported',
+ d => 'disabled by default',
x => sub {
join(' ',
'requires prefix',
@@ -68,12 +76,12 @@ if (my ($somerow) = values %{ $caniuse->{data} }) {
$versions{$browser} = [ sort { paddedver($a) cmp paddedver($b) } keys %$row ];
}
}
-my @browsers = keys %versions;
print <<'';
Alternate rendition of Fyrd's when can I use... page
my ($canihas, $usage);
+my $minusage = $get{threshold} // .5;
given ($get{usage} // 'wm') {
when (!$_) {
# none
@@ -93,11 +101,18 @@ given ($get{usage} // 'wm') {
$ref .= " $_" for $canihas->{-date} || ();
print "\nwith $ref browser usage statistics";
}
+
+my @browsers;
if ($usage) { # first() does not work inside given >:(
# adapt version usage to actual support data
my %engineuse; # prefix => usage sum
- while (my ($browser, $row) = each %$canihas) {
+ for my $browser (keys %versions) {
+ my $row = $canihas->{$browser} // {};
my $verlist = $versions{$browser} or next;
+ if ($minusage and sum(values %$row) < $minusage) {
+ delete $versions{$browser};
+ next;
+ }
my %supported = map { $_ => 1 } @$verlist;
# cascade unknown versions
@@ -111,7 +126,7 @@ if ($usage) { # first() does not work inside given >:(
}
# build row list for each version
- if (my $minusage = .2) {
+ if ($minusage) {
my @vershown; # $verlist replacement
my ($rowusage, @verrow) = (0); # replacement row tracking
for (@$verlist) {
@@ -139,7 +154,7 @@ if ($usage) { # first() does not work inside given >:(
$engineuse{ $caniuse->{agents}->{$a}->{prefix} }
||
$canihas->{$b}->{-total} <=> $canihas->{$a}->{-total}
- } @browsers;
+ } keys %versions;
}
else {
# order browser columns by name grouped by engine
@@ -148,7 +163,7 @@ else {
$caniuse->{agents}->{$a}->{prefix}
||
$a cmp $b
- } @browsers;
+ } keys %versions;
}
:>.
@@ -225,7 +240,22 @@ for my $browser (@browsers) {
}
print '' x 1;
say '';
-say ' | ', $header, '';
+say '', $header;
+{
+ # prefix indicates browser family; count adjacent families
+ my (@families, %familycount);
+ for my $browser (@browsers) {
+ my $family = $caniuse->{agents}->{$browser}->{prefix};
+ push @families, $family unless $familycount{$family};
+ $familycount{$family} += @{ $versions{$browser} };
+ }
+
+ print "\n", '';
+ print '' x 3;
+ printf ' | %s', $familycount{$_}, $_ for @families;
+ print ' | ';
+}
+say ' |
';
sub featurescore {
# relative amount of support for given feature
@@ -306,7 +336,8 @@ sub saystatuscol {
sub saybrowsercols {
my ($id, $browser) = @_;
- my $data = $caniuse->{data}->{$id}->{stats}->{$browser};
+ my $feature = $caniuse->{data}->{$id};
+ my $data = $feature->{stats}->{$browser};
if (ref $data eq 'ARRAY') {
# special case for unsupported
my $release = $caniuse->{agents}->{$browser}->{verrelease};
@@ -327,7 +358,22 @@ sub saybrowsercols {
);
unless (!defined $prev or $prev ~~ $compare) {
my $usage = sum(@{ $canihas->{$browser} }{ map { @{$_} } @span });
- printf '%s',
+
+ # strip #\d note references from support class
+ my @notes;
+ push @notes, $feature->{notes_by_num}->{$1}
+ while $prev =~ s/\h \# (\d+) \b//x;
+
+ # prepare version hover details
+ my $title = sprintf('%.1f%% %s', $usage * $usagepct, join(', ',
+ map { ref $_ eq 'CODE' ? $_->($browser) : $_ }
+ map { $DSTATS{$_} // () }
+ map { split / /, $_ }
+ $prev
+ ));
+ $title .= "\n".EscapeHTML($_) for @notes;
+
+ printf(' | %s',
join(' ',
X => $CSTATS{$prev},
!$usage ? ('p0') : ('p',
@@ -337,13 +383,9 @@ sub saybrowsercols {
sprintf('pp%02d', $usage / $usagemax),
),
scalar @span,
- sprintf('%.1f%% %s', $usage * $usagepct, join(', ',
- map { ref $_ eq 'CODE' ? $_->($browser) : $_ }
- map { $DSTATS{$_} // () }
- map { split / /, $_ }
- $prev
- )),
+ $title,
showversions($span[0]->[0], @span > 1 ? ($span[-1]->[-1]) : ()),
+ );
undef $prev;
@span = ();
}
@@ -377,7 +419,7 @@ sub paddedver {
# normalised version number comparable as string (cmp)
shift =~ /(?:.*-|^)(\d*)(.*)/;
# matched (major)(.minor) of last value in range (a-B)
- return sprintf('%02d', $1 || 0) . $2;
+ return sprintf('%02d', $1 || 99) . $2;
}
sub showversions {
@@ -398,7 +440,7 @@ sub showversions {
supported
| partial
- | external (js/plugin)
+ | optional
| missing
| unknown
| prefixed
@@ -427,6 +469,8 @@ sub showversions {
<:= defined $get{style} && 'set to ' :><:= $style :>
usage source is
<:= !defined $get{usage} && 'default ' :><:= defined $usage ? "$usage" : 'not included (0)' :>
+ usage threshold is
+ <:= defined $get{threshold} && 'changed to ' :><:= $minusage :>%
|
|