keyboard/altgr/index: class inventory count graphs
authorMischa POSLAWSKY <perl@shiar.org>
Fri, 16 Feb 2024 21:01:10 +0000 (22:01 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Wed, 28 Feb 2024 23:40:02 +0000 (00:40 +0100)
Complete comparison grown out of separate numbers for select classes.

keyboard/altgr/index.inc.plp

index ccb7fb63fc3388bacad4d944102fda5cc2e28906..0bb7774112193b414cab1a65531cf966ccc66a9b 100644 (file)
@@ -6,7 +6,7 @@ my @incs = glob 'keyboard/altgr/*.eng.inc.pl';
 
 Html({
        title => "altgr keyboard cheat sheets",
-       version => '1.1',
+       version => '1.2',
        description => [
                "Overview of alternate keyboard modes,",
                "offering extended Unicode characters if a modifier key",
@@ -46,6 +46,37 @@ Html({
        text-align: right;
 }
 
+.graph {
+       display: block;
+       line-height: 1ex;
+       height: 1.2ex;
+       margin-top: .4ex;
+}
+.graph ~ .graph {
+       /* subsequent graphs */
+       height: .7ex;
+}
+.graph > * {
+       display: inline-block;
+       height: 100%;
+       vertical-align: top;
+}
+.graph > label {
+       font-size: 75%;
+       margin-right: .2em;
+}
+.graph > span {
+       border: 1px solid #000;
+       border-right-width: 0;
+       font-size: 0;
+}
+.graph > :last-of-type {
+       border-right-width: 1px;
+}
+.graph > .ext {
+       border-left: 0; /* assume following unext */
+}
+
 img {
        object-fit: cover;
        height: 100%;
@@ -63,6 +94,7 @@ img {
 <:
 my @sample = split /(?<!\+)/, $get{sample} // 'asSci1!+1';
 require Shiar_Sheet::Keyboard;
+use List::Util qw( uniq max );
 
 printf '<section class="%s">', @sample ? 'section' : 'gallery';
 if (@sample) {
@@ -72,6 +104,7 @@ if (@sample) {
        say '</tr></thead>';
 }
 my %idx = map {s/\Q.inc.pl\E$//; ($_ => eval{ Data($_) })} @incs;
+my $most = max(map { scalar keys %{$_->{def}{''}} } values %idx);
 for my $inc (sort {
        $idx{$a}{category} cmp $idx{$b}{category} || $a cmp $b
 } keys %idx) {
@@ -90,10 +123,23 @@ for my $inc (sort {
        }
        else {
                print $title;
-               print '</a>';
+               print '</a>', "\n\t";
                my $keys = Shiar_Sheet::Keyboard->new($table);
-               print '<br>', join(' ', map { $keys->{key}{$_} =~ s/\s.*//r } grep {$_} keys %{$_})
-                       for $keys->{mode} || ();
+               for my $mode ($keys->{mode} ? sort keys %{ $keys->{mode} } : '') {
+                       my %inventory;
+                       $inventory{ s/ (?!ext).*//r }++ for values %{ $keys->{def}{$mode} };
+                       print '<span class=graph>';
+                       print "<label>$_</label>" for $keys->{key}{$mode} =~ s/\s.*//r || ();
+                       for my $g (sort keys %inventory) {
+                               printf '<span class="%s" style="width:%.0f%%" title="%3$d %4$s"> %s</span>',
+                                       $g, $_/$most*100, $_,
+                                       join(' ', map {
+                                               $keys->{flag}{$_}[0] || 'extra'  # legend label of each class
+                                       } reverse split / /, $g)
+                                       for $inventory{$g};
+                       }
+                       say '</span>';
+               }
                $keys->print_key('', $_, $keys->{def}{''}{$_} // 'ni') for @sample;
                say '</tr>';
        }