Author: spadkins
Date: Tue Jan 16 09:25:10 2007
New Revision: 8593
Modified:
p5ee/trunk/App-Widget-ChartDirector/lib/App/Widget/ChartDirector.pm
Log:
Fixed pie chart, performance meter and clipped bars. Work may still need to be
done on various graphs.
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 Tue Jan
16 09:25:10 2007
@@ -310,6 +310,10 @@
my ($self, $spec) = @_;
require "perlchartdir.pm";
+ my $bgcolor = $self->get_theme_value("bgcolor", "0x3f65b8");
+ my $titlecolor = $self->get_theme_value("titlecolor", "0xfffcf0");
+ my $labelcolor = $self->get_theme_value("x_labelcolor", "0xfffcf0");
+
my $x = $self->get_x($spec);
my $width = $spec->{width} || 250;
my $height = $spec->{height} || 250;
@@ -330,13 +334,15 @@
if (!$left_margin) {
$left_margin = 20;
}
- my $c = new PieChart($width, $height);
+
+ my $c = new PieChart($width, $height, hex($bgcolor));
my $center_x = int($width/2);
my $center_y = int(($height - 20)/2);
my $radius = (($center_x > $center_y) ? $center_y : $center_x) - 40;
$c->setPieSize($center_x, $center_y, $radius);
- $c->addTitle($spec->{title}) if ($spec->{title});
+ $c->addTitle($spec->{title}, "arialbd.ttf", 12, hex($titlecolor)) if
($spec->{title});
+ $c->setLabelStyle("arial.ttf", 10, hex($labelcolor));
&App::sub_exit($c) if ($App::trace);
return($c);
@@ -347,6 +353,10 @@
my ($self, $spec) = @_;
require "perlchartdir.pm";
+ my $bgcolor = $self->get_theme_value("bgcolor", "0x3f65b8");
+ my $titlecolor = $self->get_theme_value("titlecolor", "0xfffcf0");
+ my $labelcolor = $self->get_theme_value("x_labelcolor", "0xfffcf0");
+
my $x = $self->get_x($spec);
my $width = $spec->{width} || 250;
my $height = $spec->{height} || 180;
@@ -367,7 +377,7 @@
$bottom_margin += 9 if (!$spec->{registered});
$bottom_margin += 15 if ($x);
}
- my $c = new AngularMeter($width, $height,
perlchartdir::metalColor(0xaaaaff), 0x0, 2);
+ my $c = new AngularMeter($width, $height, hex($bgcolor));
my $max_width_radius = int(($width - $left_margin - $right_margin)/2);
my $max_height_radius = $height - $top_margin - $bottom_margin;
my $radius = ($max_width_radius > $max_height_radius) ?
$max_height_radius : $max_width_radius;
@@ -377,8 +387,9 @@
$spec->{center_x} = $center_x;
$spec->{center_y} = $center_y;
$c->setMeter($center_x, $center_y, $radius, -90, 90);
+ #$c->setRoundedFrame();
- $c->addTitle($spec->{title}) if ($spec->{title});
+ $c->addTitle($spec->{title}, "arialbd.ttf", 12, hex($titlecolor)) if
($spec->{title});
&App::sub_exit($c) if ($App::trace);
return($c);
@@ -444,8 +455,8 @@
if ($x && $#$x > -1) {
my ($begin_datetime, $end_datetime, $begin_time, $end_time, $begin_yr,
$end_yr);
if ($x->[0] =~ /^[0-9]{4}-[0-9]{2}-[0-9]{2}$/) {
- #my $bar_offset = ($spec->{graphtype} =~ /bar/) ? 24*3600 : 0;
- my $bar_offset = 0;
+ my $bar_offset = ($spec->{graphtype} =~ /bar/) ? 24*3600 : 0;
+ #my $bar_offset = 0;
$begin_datetime = $bar_offset ? time2str("%Y-%m-%d",
str2time($x->[0]) - $bar_offset) : $x->[0];
if ($begin_datetime =~ /^([0-9]{4})-([0-9]{2})-([0-9]{2})$/) {
$begin_yr = $1;
@@ -593,12 +604,16 @@
my $c = $self->new_meter_chart($spec);
my $x = $self->get_x($spec);
my $yn = $self->get_y($spec) || [[]];
+
my $value = $yn->[0][0];
+
my $radius = $spec->{radius};
my $center_x = $spec->{center_x};
my $center_y = $spec->{center_y};
- my $y_max = $spec->{y_max} || 100;
+ #my $y_max = $spec->{y_max} || 100;
+ my $y_max = $value || 100;
+
my ($major_tick, $minor_tick, $micro_tick);
{
my $y_mantissa = $y_max;
@@ -625,18 +640,22 @@
$major_tick = $y_max/5;
}
- my $y_red = $spec->{y_red} || ($y_max * 0.80);
+ my $y_red = $spec->{y_red} || ($y_max * 0.80);
my $y_yellow = $spec->{y_yellow} || ($y_max * 0.60);
#Meter scale is 0 - 100, with major tick every 20 units, minor tick every
10
#units, and micro tick every 5 units
$c->setScale(0, $y_max, $major_tick, $minor_tick, $micro_tick);
+
#Set 0 - 60 as green (66FF66) zone
$c->addZone(0, $y_yellow, 0, $radius, 0x66ff66);
+
#Set 60 - 80 as yellow (FFFF33) zone
$c->addZone($y_yellow, $y_red, 0, $radius, 0xffff33);
+
#Set 80 - 100 as red (FF6666) zone
$c->addZone($y_red, $y_max, 0, $radius, 0xff6666);
+
#Add a text label centered at (100, 60) with 12 pts Arial Bold font
if ($spec->{y_title}) {
$c->addText($center_x, $center_y-int($radius * 0.35), $spec->{y_title},
@@ -674,7 +693,6 @@
$value = $y_max if ($value > $y_max);
$value = 0 if ($value < 0);
$c->addPointer($value, 0x40666699, 0x0);
- $c->xAxis()->setLabels($x);
$c->makeChart($spec->{image_path});
&App::sub_exit() if ($App::trace);
}
@@ -682,15 +700,27 @@
sub write_pie_graph_image {
&App::sub_entry if ($App::trace);
my ($self, $spec) = @_;
- my $c = $self->new_pie_chart($spec);
- my $x = $self->get_x($spec);
+
+ my $c = $self->new_pie_chart($spec);
+ my $x = $self->get_x($spec);
my $yn = $self->get_y($spec);
- my $y = $yn->[0];
- if ($#$yn > 0) {
+
+ my $data;
+ foreach my $y (@$yn) { push (@$data, @{$y}); }
+
+ if ($#$x > 0) {
+ $c->setData($data, $x);
+ }
+ else {
+ $c->setData($data, $spec->{y_labels});
}
- $c->setData($y, $x);
+
+ # The depths for the sectors
+ #my $depths = [30, 20, 10, 10];
+ #$c->set3D2($depths);
+ #$c->setStartAngle(225);
+
$c->set3D() if ($spec->{"3D"});
- $c->xAxis()->setLabels($x);
$c->makeChart($spec->{image_path});
&App::sub_exit() if ($App::trace);
}