Use relative scaling in the main table
[onis.git] / lib / Onis / Plugins / Core.pm
index ec6dc79..6babaed 100644 (file)
@@ -17,14 +17,14 @@ complicated plugin so far.
 
 =cut
 
-use Onis::Config qw/get_config/;
-use Onis::Html qw/html_escape get_filehandle/;
-use Onis::Language qw/translate/;
-use Onis::Users (qw(get_realname get_link get_image ident_to_name));
-use Onis::Data::Core qw#get_all_nicks nick_to_ident ident_to_nick get_main_nick register_plugin#;
-use Onis::Data::Persistent;
-
-@Onis::Plugins::Core::EXPORT_OK = (qw(get_core_nick_counters get_sorted_nicklist));
+use Onis::Config (qw(get_config));
+use Onis::Html (qw(html_escape get_filehandle));
+use Onis::Language (qw(translate));
+use Onis::Users (qw(get_realname get_link get_image chatter_to_name));
+use Onis::Data::Core (qw(get_all_nicks nick_to_ident ident_to_nick get_main_nick register_plugin));
+use Onis::Data::Persistent ();
+
+@Onis::Plugins::Core::EXPORT_OK = (qw(get_core_nick_counters get_sorted_nicklist nick_is_in_main_table));
 @Onis::Plugins::Core::ISA = ('Exporter');
 
 our $NickLinesCounter = Onis::Data::Persistent->new ('NickLinesCounter', 'nick',
@@ -53,6 +53,8 @@ our $QuoteData = {};  # Is generated before output. Nicks are merged according t
 our $NickData = {};  # Same as above, but for nicks rather than quotes.
 our $SortedNicklist = [];
 
+our $NicksInMainTable = {};
+
 our @H_IMAGES = qw#dark-theme/h-red.png dark-theme/h-blue.png dark-theme/h-yellow.png dark-theme/h-green.png#;
 our $QuoteCacheSize = 10;
 our $QuoteMin = 30;
@@ -591,14 +593,14 @@ sub activetimes
 
        my $header = translate ('When do we actually talk here?');
        print $fh "<h2>$header</h2>\n",
-       qq#<table class="hours_of_day">\n#,
-       qq#  <tr>\n#;
+       qq#<table class="hours">\n#,
+       qq#  <tr class="bars">\n#;
 
 # this for circles through the four colors. Each color represents six hours.
 # (4 * 6 hours = 24 hours)
        for (my $i = 0; $i <= 3; $i++)
        {
-               for (my $j = 0; $j <= 5; $j++)
+               for (my $j = 0; $j < 6; $j++)
                {
                        my $hour = (($i * 6) + $j);
                        if (!defined ($data[$hour]))
@@ -606,19 +608,22 @@ sub activetimes
                                $data[$hour] = 0;
                        }
 
-                       my $percent = 100 * ($data[$hour] / $total);
-                       my $height = int ($data[$hour] * $factor) + 1;
-                       my $img_url = $img_urls[$i];
+                       my $height  = sprintf ("%.2f", 95 * $data[$hour] / $max);
+                       my $img = $img_urls[$i];
                        
-                       print $fh '    <td>', sprintf ("%2.1f", $percent),
-                       qq#%<br /><img src="$img_url" style="height: $height#,
-                       qq#px;" alt="" /></td>\n#;
+                       print $fh qq#    <td class="bar vertical"><img src="$img" class="first last" style="height: $height\%;" alt="" /></td>\n#;
                }
        }
+       print $fh qq#  </tr>\n  <tr class="counter">\n#;
+       for (my $i = 0; $i < 24; $i++)
+       {
+               my $percent = sprintf ("%.1f", 100 * $data[$i] / $total);
+               print $fh qq#    <td class="counter">$percent\%</td>\n#;
+       }
 
        print $fh "  </tr>\n",
-       qq#  <tr class="hour_row">\n#;
-       print $fh map { "    <td>$_</td>\n" } (0 .. 23);
+       qq#  <tr class="numeration">\n#;
+       print $fh map { qq#    <td class="numeration">$_</td>\n# } (0 .. 23);
        print $fh "  </tr>\n",
        "</table>\n\n";
 }
@@ -688,18 +693,21 @@ EOF
        }
        if ($DISPLAY_LINES ne 'NONE')
        {
+               my $span = $DISPLAY_LINES eq 'BOTH' ? ' colspan="2"' : '';
                $trans = translate ('Number of Lines');
-               print $fh "    <th>$trans</th>\n";
+               print $fh "    <th$span>$trans</th>\n";
        }
        if ($DISPLAY_WORDS ne 'NONE')
        {
+               my $span = $DISPLAY_WORDS eq 'BOTH' ? ' colspan="2"' : '';
                $trans = translate ('Number of Words');
-               print $fh "    <th>$trans</th>\n";
+               print $fh "    <th$span>$trans</th>\n";
        }
        if ($DISPLAY_CHARS ne 'NONE')
        {
+               my $span = $DISPLAY_CHARS eq 'BOTH' ? ' colspan="2"' : '';
                $trans = translate ('Number of Characters');
-               print $fh "    <th>$trans</th>\n";
+               print $fh "    <th$span>$trans</th>\n";
        }
        if ($DISPLAY_TIMES)
        {
@@ -722,7 +730,7 @@ EOF
        {
                my $nick = $_;
                my $ident = nick_to_ident ($nick);
-               my $name  = ident_to_name ($ident);
+               my $name  = chatter_to_name ("$nick!$ident");
                my $print = $name || $nick;
 
                $linescount++;
@@ -732,6 +740,8 @@ EOF
                # our table..
                if ($linescount <= $LongLines)
                {
+                       $NicksInMainTable->{$nick} = $linescount;
+                       
                        my $quote = translate ('-- no quote available --');
 
                        if (@{$QuoteData->{$nick}})
@@ -801,50 +811,44 @@ EOF
                
                        if ($DISPLAY_LINES ne 'NONE')
                        {
-                               print $fh qq#    <td class="bar">#;
-                               if (($DISPLAY_LINES eq 'BOTH') or ($DISPLAY_LINES eq 'BAR'))
+                               if (($DISPLAY_LINES eq 'BOTH') or ($DISPLAY_LINES eq 'NUMBER'))
                                {
-                                       my $code = bar ($max_lines, $NickData->{$nick}{'lines'});
-                                       print $fh $code;
+                                       my $num = $NickData->{$nick}{'lines_total'};
+                                       print $fh qq(    <td class="counter">$num</td>\n);
                                }
-                               print $fh '&nbsp;' if ($DISPLAY_LINES eq 'BOTH');
-                               if (($DISPLAY_LINES eq 'BOTH') or ($DISPLAY_LINES eq 'NUMBER'))
+                               if (($DISPLAY_LINES eq 'BOTH') or ($DISPLAY_LINES eq 'BAR'))
                                {
-                                       print $fh $NickData->{$nick}{'lines_total'};
+                                       my $code = bar ($max_lines, $NickData->{$nick}{'lines'});
+                                       print $fh qq(    <td class="bar horizontal">$code</td>\n);
                                }
-                               print $fh "</td>\n";
                        }
 
                        if ($DISPLAY_WORDS ne 'NONE')
                        {
-                               print $fh qq#    <td class="bar">#;
-                               if (($DISPLAY_WORDS eq 'BOTH') or ($DISPLAY_WORDS eq 'BAR'))
+                               if (($DISPLAY_WORDS eq 'BOTH') or ($DISPLAY_WORDS eq 'NUMBER'))
                                {
-                                       my $code = bar ($max_words, $NickData->{$nick}{'words'});
-                                       print $fh $code;
+                                       my $num = $NickData->{$nick}{'words_total'};
+                                       print $fh qq(    <td class="counter">$num</td>\n);
                                }
-                               print $fh '&nbsp;' if ($DISPLAY_WORDS eq 'BOTH');
-                               if (($DISPLAY_WORDS eq 'BOTH') or ($DISPLAY_WORDS eq 'NUMBER'))
+                               if (($DISPLAY_WORDS eq 'BOTH') or ($DISPLAY_WORDS eq 'BAR'))
                                {
-                                       print $fh $NickData->{$nick}{'words_total'};
+                                       my $code = bar ($max_words, $NickData->{$nick}{'words'});
+                                       print $fh qq(    <td class="bar horizontal">$code</td>\n);
                                }
-                               print $fh "</td>\n";
                        }
 
                        if ($DISPLAY_CHARS ne 'NONE')
                        {
-                               print $fh qq#    <td class="bar">#;
-                               if (($DISPLAY_CHARS eq 'BOTH') or ($DISPLAY_CHARS eq 'BAR'))
+                               if (($DISPLAY_CHARS eq 'BOTH') or ($DISPLAY_CHARS eq 'NUMBER'))
                                {
-                                       my $code = bar ($max_chars, $NickData->{$nick}{'chars'});
-                                       print $fh $code;
+                                       my $num = $NickData->{$nick}{'chars_total'};
+                                       print $fh qq(    <td class="counter">$num</td>\n);
                                }
-                               print $fh '&nbsp;' if ($DISPLAY_CHARS eq 'BOTH');
-                               if (($DISPLAY_CHARS eq 'BOTH') or ($DISPLAY_CHARS eq 'NUMBER'))
+                               if (($DISPLAY_CHARS eq 'BOTH') or ($DISPLAY_CHARS eq 'BAR'))
                                {
-                                       print $fh $NickData->{$nick}{'chars_total'};
+                                       my $code = bar ($max_chars, $NickData->{$nick}{'chars'});
+                                       print $fh qq(    <td class="bar horizontal">$code</td>\n);
                                }
-                               print $fh "</td>\n";
                        }
 
                        if ($DISPLAY_TIMES)
@@ -951,21 +955,16 @@ sub bar
        confess () unless (ref ($source) eq 'ARRAY');
 
        # BAR_WIDTH is a least 10
-       my $max_width = $BAR_WIDTH - 4;
-       my $factor = 1;
        my $retval = '';
 
        my $i;
        my $j;
 
-       if (!$max_num) { return ($retval); }
-       $factor = $max_width / $max_num;
-
        for ($i = 0; $i < 4; $i++)
        {
                my $sum = 0;
-               my $width = 1;
                my $img = $H_IMAGES[$i];
+               my $width;
 
                for ($j = 0; $j < 6; $j++)
                {
@@ -973,9 +972,9 @@ sub bar
                        $sum += $source->[$hour];
                }
 
-               $width += int (0.5 + ($sum * $factor));
+               $width = sprintf ("%.2f", 95 * $sum / $max_num);
                
-               $retval .= qq#<img src="$img" style="width: # . $width . q#px"#;
+               $retval .= qq#<img src="$img" style="width: $width%;"#;
                if ($i == 0) { $retval .= qq# class="first"#; }
                elsif ($i == 3) { $retval .= qq# class="last"#; }
                $retval .= qq( alt="$sum" />);
@@ -1028,10 +1027,24 @@ sub get_sorted_nicklist
        return ($SortedNicklist);
 }
 
+=item B<nick_is_in_main_table> (I<$nick>)
+
+Returns the position of the nick in the main table or zero if it is not in the
+main table.
+
+=cut
+
+sub nick_is_in_main_table
+{
+       my $nick = shift;
+
+       return (defined ($NicksInMainTable->{$nick}) ? $NicksInMainTable->{$nick} : 0);
+}
+
 =back
 
 =head1 AUTHOR
 
-Florian octo Forster, E<lt>octo at verplant.orgE<gt>
+Florian octo Forster E<lt>octo at verplant.orgE<gt>
 
 =cut