Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Perl Cvs P5ee > [svn:p5ee] r957...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 529 of 720
Post > Topic >>

[svn:p5ee] r9575 - p5ee/trunk/App-Widget-ChartDirector/lib/App/Widget

by spadkins@[EMAIL PROTECTED] May 18, 2007 at 08:53 AM

Author: spadkins
Date: Fri May 18 08:53:26 2007
New Revision: 9575

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

Log:
add {legend_pos} options [default,top,bottom]

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	Fri
May 18 08:53:26 2007
@[EMAIL PROTECTED]
 -6,12 +6,12 @[EMAIL PROTECTED]
 package App::Widget::ChartDirector;
 $VERSION = (q$Revision$ =~ /(\d[\d\.]*)/)[0];  # VERSION numbers
generated by svn
 
-use App;
+use App; 
 use App::Widget::Graph;
 @[EMAIL PROTECTED]
 = ( "App::Widget::Graph" );
 
 use Date::Format;
-use Date::Parse;
+use Date::Parse;  
 #use Data::Dumper;
 use strict;
 
@[EMAIL PROTECTED]
 -51,7 +51,6 @[EMAIL PROTECTED]
     my $self = ****ft;
     my $name = $self->{name};
     my $spec = $self->create_graph_spec();
-
     my ($html);
     if ($self->{defer_images}) {   # write out the graph spec. produce
graph image later.
         my $spec_path = $spec->{spec_path};
@[EMAIL PROTECTED]
 -233,7 +232,6 @[EMAIL PROTECTED]
     &App::sub_entry if ($App::trace);
     my ($self, $spec) = @[EMAIL PROTECTED]
     require "perlchartdir.pm";
-
     my $x = $self->get_x($spec);                                        #
print STDERR Dumper $x;
     my $width  = $spec->{width}  || 250;
     my $height = $spec->{height} || 250;
@[EMAIL PROTECTED]
 -270,12 +268,64 @[EMAIL PROTECTED]
         $left_margin = 20 + $y_label_len * 6;
         $left_margin += 20 if ($spec->{y_title});
     }
+    
+    my $legend_pos = $spec->{legend_pos} || "default"; # Any one from
default, top or bottom
+    my ($count, $count_uc, @[EMAIL PROTECTED]
 $max_legend_length,
$num_legend_columns, $legend_width, $margin, $textsize, $number_legend_row
);
+    
+    if ($legend_pos eq "top" || $legend_pos eq "bottom") {
+        $count = 0;
+        $count_uc = 0;
+        $max_legend_length = 75;      # This is a nearyby approximation
of number of characters inside a row in the legends
+        $num_legend_columns = $spec->{num_legend_columns} || 2; 
+        $legend_width = $width - 2 * $right_margin; 
+        ($margin,$textsize) = (6,10);  
+        
+        foreach my $y_value (@[EMAIL PROTECTED]
>{y_labels}}) {
+            push( @[EMAIL PROTECTED]
 length($y_value) );
+            $count++; 
+            $count_uc++ if ($y_value !~ /[a-z]/);
+        }
+        @[EMAIL PROTECTED]
 = sort { $a <=> $b } @[EMAIL PROTECTED]
        $max_legend_length = 40 if ($count == $count_uc); # This is a
nearyby approximation of number of characters inside a row in the legends
+
+        for (my $cols = 2;$cols <= 8; $cols++) { # Taking min 2 and max.
8 colums
+            $num_legend_columns  = $cols if ($length_y_value[-1] <
$max_legend_length / $cols);
+        }
+
+        $num_legend_columns  = 2 if ($#{$spec->{y_labels}} < 2);
+        $num_legend_columns  = 3 if ($length_y_value[-1] >
$max_legend_length / 2 && $#{$spec->{y_labels}} > 20); 
+
+        $number_legend_row = int ($count / $num_legend_columns);
+        if ($count % $num_legend_columns != 0 )  {
+            $number_legend_row += 1;
+        }
 
-    my $c = new XYChart($width, $height);
+        $height += (($margin + $textsize) * $number_legend_row) + (4 *
$margin);  
 
-    my $plot_area = $c->setPlotArea($left_margin, $top_margin,
+        if ($#{$spec->{y_labels}} <= 0) {
+            $height = $spec->{height};  
+        }
+    }
+    my $c = new XYChart($width, $height);
+    
+    my $graph_adjusted_height = $height - $spec->{height};
+    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;
+    }
+    elsif ($legend_pos eq "bottom") {
+        $top_margin_adjusted    = $top_margin;
+        $bottom_margin_adjusted =
$height-$top_margin-$bottom_margin-$graph_adjusted_height;
+    }
+    else {
+        $top_margin_adjusted    = $top_margin;
+        $bottom_margin_adjusted = $height-$top_margin-$bottom_margin;
+    }
+    my $plot_area = $c->setPlotArea($left_margin , $top_margin_adjusted,
         $width-$left_margin-$right_margin,
-        $height-$top_margin-$bottom_margin);
+        $bottom_margin_adjusted);
 
     $plot_area->setBackground(hex($plot_bgcolor), hex($plot_bgcolor));
 
@[EMAIL PROTECTED]
 -283,6 +333,7 @[EMAIL PROTECTED]
 
     #Add a legend box at (55, 22) using horizontal layout, with
transparent
     #background
+    my $legend;
     if ($spec->{y_labels}) {
         my $x_adj = 0;
         my $y_adj = -2;
@[EMAIL PROTECTED]
 -290,11 +341,33 @[EMAIL PROTECTED]
             $x_adj += 5;
             $y_adj += -5;
         }
-        my $legend = $c->addLegend($left_margin+$x_adj,
$top_margin+$y_adj, 0);
-        $legend->setBackground($perlchartdir::Transparent);
-        $legend->setMargin(5);
+        
+        if (($#{$spec->{y_labels}} > 0) && ($legend_pos eq "top" ||
$legend_pos eq "bottom")) { 
+            if ($legend_pos eq "top" ) {
+                $legend = $c->addLegend($left_margin/4 + $x_adj,
$top_margin + $y_adj, 0,"arial.ttf",10);
+            }
+            elsif ($legend_pos eq "bottom" ) {
+                $legend = $c->addLegend($left_margin/4 + $x_adj, $height
- $graph_adjusted_height - $top_margin/4 , 0,"arial.ttf",10);
+            }
+            $legend->setBackground(hex($plot_bgcolor)); 
+            $legend->setMargin(5);
+            $legend->setWidth($legend_width);
+            $legend->setCols($num_legend_columns);
+            $legend->setTruncate("",1); 
+        }
+        else {
+            $legend = $c->addLegend($left_margin+$x_adj,
$top_margin+$y_adj, 0);
+            $legend->setBackground($perlchartdir::Transparent);
+            $legend->setMargin(5);
+        }
     }
-
+        
+    # To handle the situation when the graph wrapping happens.
+    if ($legend_pos eq "top" || $legend_pos eq "bottom") {
+        my $graph_count = $spec->{graph_count} || 1; 
+        $spec->{height} = $height if ($graph_count == 1);
+    }
+    
     $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));
 




 1 Posts in Topic:
[svn:p5ee] r9575 - p5ee/trunk/App-Widget-ChartDirector/lib/App/W
spadkins@[EMAIL PROTECTED  2007-05-18 08:53:31 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Oct 13 4:09:58 CDT 2008.