browser: deallocate columns for unused browser versions
authorMischa POSLAWSKY <perl@shiar.org>
Tue, 15 Feb 2011 22:14:49 +0000 (23:14 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Tue, 10 Apr 2012 01:03:24 +0000 (03:03 +0200)
browser.plp

index da50b2d..1158334 100644 (file)
@@ -110,6 +110,24 @@ if ($usage) { # first() does not work inside given >:(
                        $row->{$version} = 0;  # balance browser total
                }
 
+               # build row list for each version
+               if (my $minusage = .2) {
+                       my @vershown;  # $verlist replacement
+                       my ($rowusage, @verrow) = (0);  # replacement row tracking
+                       for (@$verlist) {
+                               push @verrow, $_;  # queue each version
+                               if (($rowusage += $row->{$_}) >= $minusage) {
+                                       push @vershown, [@verrow];   # add row
+                                       ($rowusage, @verrow) = (0);  # reset row tracking
+                               }
+                       }
+                       push @vershown, \@verrow if @verrow;  # always add latest
+                       @$verlist = @vershown;
+               }
+               else {
+                       @$verlist = map { [$_] } @$verlist;
+               }
+
                # reusable aggregates (grouped by prefix (engine) and browser)
                $engineuse{ $caniuse->{agents}->{$browser}->{prefix} } +=
                $row->{-total} = sum(values %$row);
@@ -155,7 +173,7 @@ my $usagemax = (max(map { ref $_ eq 'HASH' && sum(values %$_) } values %$canihas
 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'} @{$versions{$_}} } } keys %versions
+       map { $_ => { map {$_ => 'y'} map { @{$_} } @{$versions{$_}} } } keys %versions
 });
 
 print '<table class="mapped">';
@@ -190,17 +208,18 @@ print '<thead>', $header;
 print "\n<tr>";
 print '<td>' x 3;
 for my $browser (@browsers) {
-       for my $_ (@{ $versions{$browser} }) {
-               my $release = $caniuse->{agents}->{$browser}->{verrelease}->{$_};
+       for (@{ $versions{$browser} }) {
+               my $lastver = $_->[-1];
+               my $release = $caniuse->{agents}->{$browser}->{verrelease}->{$lastver};
                my $future = defined $release;
                printf('<td title="%s"%s>%s',
                        join(' ',
-                               sprintf('%.1f%%', $canihas->{$browser}->{$_} * $usagepct),
+                               sprintf('%.1f%%', sum(@{ $canihas->{$browser} }{@$_}) * $usagepct),
                                $future ? 'development' : (),
-                               "version $_",
+                               'version ' . join(', ', @{$_}),
                        ),
                        $future && ' class="ex"',
-                       showversions($_),
+                       showversions($lastver),
                );
        }
 }
@@ -301,13 +320,13 @@ sub saybrowsercols {
                my $compare = (
                        !defined $ver ? undef :      # last column if nameless
                        ref $data ne 'HASH' ? '' :   # unclassified if no support hash
-                       $data->{$ver} // $prev       # known or inherit from predecessor
-                       // (grep { defined } @{$data}{ @{ $versions{$browser} } })[0]
+                       $data->{ $ver->[-1] } // $prev  # known or inherit from predecessor
+                       // (grep { defined } @{$data}{ map { $_->[0] } @{ $versions{$browser} } })[0]
                           ~~ 'n' && 'n'             # first known version is unsupported
                        || 'u'                       # unsure
                );
                unless (!defined $prev or $prev ~~ $compare) {
-                       my $usage = sum(map { $canihas->{$browser}->{$_} } @span);
+                       my $usage = sum(@{ $canihas->{$browser} }{ map { @{$_} } @span });
                        printf '<td class="%s" colspan="%d" title="%s">%s',
                                join(' ',
                                        X => $CSTATS{$prev},
@@ -324,11 +343,11 @@ sub saybrowsercols {
                                        map { split / /, $_ }
                                        $prev
                                )),
-                               showversions(@span),
+                               showversions($span[0]->[0], @span > 1 ? ($span[-1]->[-1]) : ()),
                        undef $prev;
                        @span = ();
                }
-               push @span, $ver;
+               push @span, $ver && [ grep { $data->{ $_ } eq $data->{ $ver->[-1] } } @{$ver} ];
                $prev = $compare;
        }
 }