[Rt-commit] rt branch, 4.2/charts, updated. rt-4.1.8-493-g0c5b0d5

Ruslan Zakirov ruz at bestpractical.com
Wed Jun 26 09:04:01 EDT 2013


The branch, 4.2/charts has been updated
       via  0c5b0d5309250adf25ec01e0d0fecedb13bb26a6 (commit)
       via  c1ab6d8c93161511f13a599bc734f47b4cad6222 (commit)
       via  984bbf9bb4d18fb11d807326ea49092538f4309b (commit)
       via  94ad3d98e5ddb6e547f702b6fe096d301a050348 (commit)
      from  25f17dd25cc52430ff66270f1d81eaa56be47f97 (commit)

Summary of changes:
 lib/RT/Date.pm                   |  3 ++
 share/html/Search/Chart          | 82 ++++++++++++++++++++++++++++++++++++++--
 t/api/date.t                     | 22 +++++------
 t/charts/compound-sql-function.t |  1 -
 4 files changed, 93 insertions(+), 15 deletions(-)

- Log -----------------------------------------------------------------
commit 94ad3d98e5ddb6e547f702b6fe096d301a050348
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Jun 26 16:39:54 2013 +0400

    try to fit values in charts above bars
    
    * use the same font for y axis as for x
    * use the same or smaller font for values as for x axis' labels
    * try to fit values labels horizontally or vertically
    * if failed then hide
    * use feature in newer GD::Graph to avoid hiding all labels

diff --git a/share/html/Search/Chart b/share/html/Search/Chart
index 80f8671..e308372 100644
--- a/share/html/Search/Chart
+++ b/share/html/Search/Chart
@@ -310,14 +310,91 @@ if ($chart_class eq "GD::Graph::bars") {
         }
     }
 
+    # use the same size for y axis labels
+    {
+        $chart_options{'y_axis_font'} = $chart_options{'x_axis_font'};
+    }
+
+    # try to fit in values above bars
+    {
+        my $found_solution = 0;
+
+        # 0.8 is guess, labels for ticks on Y axis can be wider
+        # 1.5 for paddings around bars that GD::Graph adds
+        my $x_space_for_label = $Width*0.8/($count*(@data - 1)+1.5);
+        foreach my $font_size ( grep $_ >= $chart_options{'x_axis_font'}[1], 12, 11, 10, 9 ) {
+            my $font_handle = GD::Text::Align->new(
+                $chart->get('graph'), valign => 'top', 'halign' => 'center',
+            );
+            $font_handle->set_font($font, $font_size);
+
+            $font_handle->set_text('Q');
+            my $line_height = $font_handle->get('height');
+
+            # if horizontal space doesn't allow us to fit one vertical line,
+            # then we need smaller font
+            next if $line_height > $x_space_for_label;
+
+            my %can = (
+                'horizontal, one line' => 1,
+                'vertical, one line' => 1,
+            );
+
+            my %seen;
+            foreach my $raw ( map {@$_} @data[1..(@data-1)] ) {
+                my $value = $raw;
+                $value = $chart_options{'values_format'}->($value)
+                    if $chart_options{'values_format'};
+                next if $seen{$value}++;
+
+                $font_handle->set_text( $value );
+                my $width = $font_handle->get('width');
+                if ( $width > $x_space_for_label ) {
+                    $can{'horizontal, one line'} = 0;
+                }
+                my $y_space_for_label = $Height * 0.6
+                    *( 1 - ($raw-$min_value)/($max_value-$min_value) );
+                if ( $width > $y_space_for_label ) {
+                    $can{'vertical, one line'} = 0;
+                }
+
+                last unless grep $_, values %can;
+            }
+            next unless grep $_, values %can;
+
+            $found_solution = 1;
+
+            $chart_options{'values_font'} = [ $font, $font_size ],
+            $chart_options{'show_values'} = 1;
+            $chart_options{'values_space'} = 2;
+
+            if ( $can{'horizontal, one line'} ) {
+                $chart_options{'values_vertical'} = 0;
+            }
+            else {
+                $chart_options{'values_vertical'} = 1;
+            }
+            last;
+        }
+        unless ( $found_solution ) {
+            $chart_options{'show_values'} = 0;
+
+            if ( do { local $@; eval { GD::Graph->VERSION("1.47") } } ) {
+                $chart_options{'values_font'} = [ $font, 9 ],
+                $chart_options{'show_values'} = 1;
+                $chart_options{'values_space'} = 2;
+                $chart_options{'values_vertical'} = 1;
+                $chart_options{'hide_overlapping_values'} = 1;
+            }
+        }
+    }
+
     %chart_options = (
         %chart_options,
         x_label => join( ' - ', map $report->Label( $_ ), @{ $columns{'Groups'} } ),
         x_label_position => 0.6,
         y_label => $report->Label( $columns{'Functions'}[0] ),
         y_label_position => 0.6,
-        show_values => 1,
-        values_space => 2,
 # use a top margin enough to display values over the top line if needed
         t_margin => 18,
 # the following line to make sure there's enough space for values to show
@@ -348,7 +425,6 @@ if ($chart->get('width') != $Width || $chart->get('height') != $Height ) {
     label_font   => [ $font, 14 ],
     y_axis_font  => [ $font, 12 ],
     values_font  => [ $font, 12 ],
-    value_font   => [ $font, 12 ],
     %chart_options,
 );
 

commit 984bbf9bb4d18fb11d807326ea49092538f4309b
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Jun 26 16:59:05 2013 +0400

    drop shebang from t/ file

diff --git a/t/charts/compound-sql-function.t b/t/charts/compound-sql-function.t
index 2a8c3c3..97408cf 100644
--- a/t/charts/compound-sql-function.t
+++ b/t/charts/compound-sql-function.t
@@ -1,4 +1,3 @@
-#!/usr/bin/perl -w
 
 use strict;
 use warnings;

commit c1ab6d8c93161511f13a599bc734f47b4cad6222
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Jun 26 17:01:05 2013 +0400

    return '0 seconds' for ->DurationAsString(0)
    
    This is backwards compatible value that was broken by recent changes.
    I don't know better value to suit most use cases, so stick to what
    we had before.

diff --git a/lib/RT/Date.pm b/lib/RT/Date.pm
index de80bd1..306ab14 100644
--- a/lib/RT/Date.pm
+++ b/lib/RT/Date.pm
@@ -372,6 +372,9 @@ sub DurationAsString {
     my $duration = int shift;
     my %args = ( Show => 1, Short => 0, @_ );
 
+    return $self->loc("0 seconds")
+        unless $duration;
+
     my $negative;
     $negative = 1 if $duration < 0;
     $duration = abs $duration;

commit 0c5b0d5309250adf25ec01e0d0fecedb13bb26a6
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Jun 26 17:03:15 2013 +0400

    adjust test to recent changes in Date.pm

diff --git a/t/api/date.t b/t/api/date.t
index bce61bf..5b4a9ff 100644
--- a/t/api/date.t
+++ b/t/api/date.t
@@ -499,11 +499,11 @@ my $year = (localtime(time))[5] + 1900;
 { # DurationAsString
     my $date = RT::Date->new(RT->SystemUser);
 
-    is($date->DurationAsString(1), '1 sec', '1 sec');
-    is($date->DurationAsString(59), '59 sec', '59 sec');
-    is($date->DurationAsString(60), '1 min', '1 min');
-    is($date->DurationAsString(60*119), '119 min', '119 min');
-    is($date->DurationAsString(60*60*2-1), '120 min', '120 min');
+    is($date->DurationAsString(1), '1 second', '1 sec');
+    is($date->DurationAsString(59), '59 seconds', '59 sec');
+    is($date->DurationAsString(60), '1 minute', '1 min');
+    is($date->DurationAsString(60*119), '119 minutes', '119 min');
+    is($date->DurationAsString(60*60*2-1), '120 minutes', '120 min');
     is($date->DurationAsString(60*60*2), '2 hours', '2 hours');
     is($date->DurationAsString(60*60*48-1), '48 hours', '48 hours');
     is($date->DurationAsString(60*60*48), '2 days', '2 days');
@@ -512,9 +512,9 @@ my $year = (localtime(time))[5] + 1900;
     is($date->DurationAsString(60*60*24*7*8-1), '8 weeks', '8 weeks');
     is($date->DurationAsString(60*60*24*61), '2 months', '2 months');
     is($date->DurationAsString(60*60*24*365-1), '12 months', '12 months');
-    is($date->DurationAsString(60*60*24*366), '1 years', '1 years');
+    is($date->DurationAsString(60*60*24*366), '1 year', '1 year');
 
-    is($date->DurationAsString(-1), '1 sec ago', '1 sec ago');
+    is($date->DurationAsString(-1), '1 second ago', '1 sec ago');
 }
 
 { # DiffAsString
@@ -526,13 +526,13 @@ my $year = (localtime(time))[5] + 1900;
     $date->Unix(2);
     is($date->DiffAsString(-1), '', 'no diff, wrong input');
 
-    is($date->DiffAsString(3), '1 sec ago', 'diff: 1 sec ago');
-    is($date->DiffAsString(1), '1 sec', 'diff: 1 sec');
+    is($date->DiffAsString(3), '1 second ago', 'diff: 1 sec ago');
+    is($date->DiffAsString(1), '1 second', 'diff: 1 sec');
 
     my $ndate = RT::Date->new(RT->SystemUser);
     is($date->DiffAsString($ndate), '', 'no diff, wrong input');
     $ndate->Unix(3);
-    is($date->DiffAsString($ndate), '1 sec ago', 'diff: 1 sec ago');
+    is($date->DiffAsString($ndate), '1 second ago', 'diff: 1 sec ago');
 }
 
 { # Diff
@@ -547,7 +547,7 @@ my $year = (localtime(time))[5] + 1900;
     my $date = RT::Date->new(RT->SystemUser);
     $date->SetToNow;
     my $diff = $date->AgeAsString;
-    like($diff, qr/^(0 sec|[1-5] sec ago)$/, 'close enought');
+    like($diff, qr/^(0 seconds|(1 second|[2-5] seconds) ago)$/, 'close enought');
 }
 
 { # GetWeekday

-----------------------------------------------------------------------


More information about the Rt-commit mailing list