Author: spadkins
Date: Thu Nov  1 13:15:40 2007
New Revision: 10149

Modified:
   p5ee/trunk/App-Widget-ChartDirector/lib/App/Widget/ChartDirector.pm

Log:
new changes from Cybage to fix labels that overlap by putting them at 45 degrees

Modified: p5ee/trunk/App-Widget-ChartDirector/lib/App/Widget/ChartDirector.pm
==============================================================================
--- p5ee/trunk/App-Widget-ChartDirector/lib/App/Widget/ChartDirector.pm 
(original)
+++ p5ee/trunk/App-Widget-ChartDirector/lib/App/Widget/ChartDirector.pm Thu Nov 
 1 13:15:40 2007
@@ -269,7 +269,19 @@
         $left_margin = 20 + $y_label_len * 6;
         $left_margin += 20 if ($spec->{y_title});
     }
-    
+    my ($total_x_length, @x_values);
+    if ($spec->{x_label_pos}) {
+        foreach (@$x){
+            $total_x_length += length($_) + 2; #Taking 2 as the gap value  
+            push (@x_values, length($_));
+        }
+        @x_values = sort { $a <=> $b} @x_values;
+        $self->{total_x_length} = $total_x_length;
+        $self->{width} = $width;   
+        if ($total_x_length > $width/8 && $x->[0] !~ 
/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/) {
+            $width += ($#$x) * ceil (3 * $#$x / 100 ) + 0.5 if ($#$x > 50);
+        }
+    }
     my $legend_pos = $spec->{legend_pos} || "default"; # Any one from default, 
top or bottom
     my (@length_y_value, $max_legend_length, $num_legend_columns, 
$legend_width, $margin, $textsize, $number_legend_rows, $length_labels, 
$length_labels_avg);
     my (@length_all_labels, $diff_largest_and_avg, $gap_legends);
@@ -316,23 +328,42 @@
         if ($#{$spec->{y_labels}} <= 0) {
             $height = $spec->{height};  
         }
-    }   
+    }
+
+   
+    my $graph_height_increment = 0; 
+    my $fontsize = 10;
+    if ($spec->{x_label_pos}) {
+        if ($#$x > 30 && $total_x_length > $width/8 && $x->[0] !~ 
/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/) {
+            for (my $i = 30; $i <= $#$x; $i++ ) {
+                $fontsize = $fontsize - 0.1;
+                $fontsize = 1 if ($fontsize < 1);
+            }  
+            $fontsize += ceil(($width - $spec->{width})/$#$x) - 1 if ($#$x > 
50);
+        }
+        $self->{fontsize} = $fontsize;
+        if ($total_x_length > $width/8  && $x->[0] !~ 
/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/) {
+            $graph_height_increment = 1/2 * $x_values[-1] * floor ($fontsize); 
+            $height += $graph_height_increment;   
+        }
+    }
+   
     my $c = new XYChart($width, $height);
-    
-    my $graph_adjusted_height = $height - $spec->{height};
+
+    my $graph_adjusted_height = $height - 
$spec->{height}-$graph_height_increment;
     my ($top_margin_adjusted,$bottom_margin_adjusted);
 
     if ($legend_pos eq "top" ) {
         $top_margin_adjusted    = $top_margin+$graph_adjusted_height;
-        $bottom_margin_adjusted = 
$height-$top_margin-$bottom_margin-$graph_adjusted_height;
+        $bottom_margin_adjusted = 
$height-$top_margin-$bottom_margin-$graph_adjusted_height-$graph_height_increment;
     }
     elsif ($legend_pos eq "bottom") {
         $top_margin_adjusted    = $top_margin;
-        $bottom_margin_adjusted = 
$height-$top_margin-$bottom_margin-$graph_adjusted_height;
+        $bottom_margin_adjusted = 
$height-$top_margin-$bottom_margin-$graph_adjusted_height-$graph_height_increment;
     }
     else {
         $top_margin_adjusted    = $top_margin;
-        $bottom_margin_adjusted = $height-$top_margin-$bottom_margin;
+        $bottom_margin_adjusted = 
$height-$top_margin-$bottom_margin-$graph_height_increment;
     }
     my $plot_area = $c->setPlotArea($left_margin , $top_margin_adjusted,
         $width-$left_margin-$right_margin,
@@ -378,7 +409,12 @@
         my $graph_count = $spec->{graph_count} || 1; 
         $spec->{height} = $height if ($graph_count == 1);
     }
-    
+
+    if ($spec->{x_label_pos} && $total_x_length > $width/8  && $x->[0] !~ 
/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/) {
+        $spec->{height} = $height;
+        $spec->{width} = $width;
+    }
+        
     $c->yAxis()->setTitle($spec->{y_title}, "arial.ttf", 10, 
hex($y_titlecolor)) if ($spec->{y_title});
     $c->setBackground(hex($bgcolor));
     $c->yAxis()->setLabelStyle("arial.ttf", 10, hex($y_labelcolor));
@@ -670,6 +706,10 @@
             }
             else {
                 $chart->xAxis()->setLabels($x);
+                if ($spec->{x_label_pos}) {
+                    $chart->xAxis()->setLabels($x)->setFontAngle(45) if ( 
$self->{total_x_length} > $self->{width}/8 );
+                    
$chart->xAxis()->setLabels($x)->setFontSize($self->{fontsize}, 0) if ($#$x > 
30);
+                }
             } 
         }
     }

Reply via email to