Author: spadkins
Date: Mon Dec 3 08:34:39 2007
New Revision: 10350
Modified:
p5ee/trunk/App-Widget-ChartDirector/lib/App/Widget/ChartDirector.pm
Log:
Fix for scrunched labels
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 Mon Dec
3 08:34:39 2007
@@ -368,7 +368,13 @@
my $plot_area = $c->setPlotArea($left_margin , $top_margin_adjusted,
$width-$left_margin-$right_margin,
$bottom_margin_adjusted);
-
+
+ $spec->{plot_area_x} = $left_margin;
+ $spec->{plot_area_y} = $top_margin_adjusted;
+ $spec->{plot_area_width} = $width - $left_margin - $right_margin;
+ $spec->{plot_area_height} = $bottom_margin_adjusted;
+ $spec->{plot_bgcolor} = $plot_bgcolor;
+
$plot_area->setBackground(hex($plot_bgcolor), hex($plot_bgcolor));
$c->addTitle($spec->{title}, "arialbd.ttf", 12, hex($titlecolor)) if
($spec->{title});
@@ -566,6 +572,53 @@
return($c);
}
+sub modify_plot_area {
+ &App::sub_entry if ($App::trace);
+ my ($self, $spec, $x, $c) = @_;
+
+ my $PIX_PER_CHAR = 15.5;
+ my $MAX_LABEL_LENGTH = 3;
+ my $plot_area_x = $spec->{plot_area_x};
+ my $plot_area_y = $spec->{plot_area_y};
+ my $plot_area_width = $spec->{plot_area_width};
+ my $plot_area_height = $spec->{plot_area_height};
+
+ #print STDERR "plot_area_x = [$plot_area_x]\n";
+ #print STDERR "plot_area_y = [$plot_area_y]\n";
+ #print STDERR "plot_area_width = [$plot_area_width]\n";
+ #print STDERR "plot_area_height = [$plot_area_height]\n";
+
+ my $max_length_x = 0;
+ my $total_length_x = 0;
+ for (my $i = 0; $i <= $#$x; $i++) {
+ if (length($x->[$i]) > $max_length_x) {
+ $max_length_x = length($x->[$i]);
+ }
+ $total_length_x = $total_length_x + length($x->[$i]);
+ }
+
+ #print STDERR "max_length_x = [$max_length_x]\n";
+ #print STDERR "total_length_x = [$total_length_x]\n";
+ #print STDERR "tlx * $PIX_PER_CHAR = [",$total_length_x *
$PIX_PER_CHAR,"]\n";
+
+ if ($total_length_x * $PIX_PER_CHAR > $plot_area_width && $x->[0] !~
/^\d+-\d+/) {
+ if ($max_length_x > $MAX_LABEL_LENGTH) {
+
+ $c->xAxis()->setLabels($spec->{y_labels})->setFontAngle(45);
+
+ my $mod_plot_area_height = $plot_area_height - ceil($max_length_x
* 4.8);
+ #print STDERR "mod_plot_area_height = [$mod_plot_area_height]\n";
+
+ my $plot_area = $c->setPlotArea($plot_area_x, $plot_area_y,
+ $plot_area_width, $mod_plot_area_height);
+
+ $plot_area->setBackground(hex($spec->{plot_bgcolor}),
hex($spec->{plot_bgcolor}));
+ }
+ }
+
+ &App::sub_exit() if ($App::trace);
+}
+
sub write_bar_graph_image {
&App::sub_entry if ($App::trace);
my ($self, $spec) = @_;
@@ -575,6 +628,10 @@
my ($layer);
my $data_set_colors;
+ if ($spec->{module_cd} eq 'D') {
+ $self->modify_plot_area($spec, $x, $c);
+ }
+
if ($spec->{data_set_colors}) {
foreach my $color ( split(/,(?:\s+)?/, $spec->{data_set_colors}) ) {
$color =~ s/^#//;