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

[email protected]
Newsgroups perl.cvs.p5ee
Message-ID <[email protected]>
Author: spadkins
Date: Wed May 30 15:20:37 2007
New Revision: 9622

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

Log:
Added custom data set colors, Mark value and color and Plot area zones

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	Wed May 30 15:20:37 2007
@@ -373,6 +373,40 @@
     $c->yAxis()->setLabelStyle("arial.ttf", 10, hex($y_labelcolor));
     $c->xAxis()->setLabelStyle("arial.ttf", 10, hex($x_labelcolor));
 
+    if ($spec->{add_mark} ne "") {
+        my $value_color;
+        if ($spec->{add_mark_color}) {
+            $value_color = "$spec->{add_mark},$spec->{add_mark_color}";
+        } else {
+            $value_color = $spec->{add_mark};
+        }
+        my ($value, $color) = split(/,/, $value_color );
+        $color = "000000" if (!$color);
+        if ($value =~ /(?:^-)?\d+(?:\.)?(?:\d+)?$/ && length($color) == 6) {
+            $color = hex($color); 
+            $c->yAxis()->addMark($value, $c->dashLineColor($color, $perlchartdir::DashLine));
+        }
+    }
+
+    if (defined $spec->{add_zone}) {
+        my @values = split(",", $spec->{add_zone});
+
+        foreach my $val (@values) {
+            my ($zone1, $zone2, $color) = split(":", $val);
+            
+            if ($zone1 =~ /((?:^-)?\d+(?:\.)?(?:\d+)?)/) {
+                $zone1 = $1;
+            }
+            if ($zone2 =~ /((?:^-)?\d+(?:\.)?(?:\d+)?)/) {
+                $zone2 = $1;
+            } 
+            if (length($color) == 6 && $zone1 ne "" && $zone2 ne "") {
+                $color = hex($color);
+                $c->yAxis()->addZone($zone1, $zone2, $color);
+            }
+        }
+    }
+
     &App::sub_exit($c) if ($App::trace); #  print STDERR Dumper $c;
     return($c);
 }
@@ -474,13 +508,25 @@
     my $x  = $self->get_x($spec);
     my $yn = $self->get_y($spec);
     my ($layer);
+    my $data_set_colors;
+
+    if ($spec->{data_set_colors}) {
+       foreach my $color ( split(/,(?:\s+)?/, $spec->{data_set_colors}) ) {
+           push (@$data_set_colors, hex($color));
+       }
+    }
+
     if ($#$yn > 0) {
         if ($spec->{stacked}) {
             my $three_d_depth = $spec->{"3D"} ? 8 : 0;
             $layer = $c->addBarLayer2($perlchartdir::Stack, $three_d_depth);
             my $y_labels = $spec->{y_labels} || [];
             for (my $i = 0; $i <= $#$yn; $i++) {
-                $layer->addDataSet($yn->[$i], -1, $y_labels->[$i]);
+                if ($#$data_set_colors != -1) {
+                    $layer->addDataSet($yn->[$i], $data_set_colors->[$i], $y_labels->[$i]);
+                } else {
+                    $layer->addDataSet($yn->[$i],-1, $y_labels->[$i]);
+                }
             }
             #Enable bar label for the whole bar
             #$layer->setAggregateLabelStyle();
@@ -491,7 +537,11 @@
             $layer = $c->addBarLayer2($perlchartdir::Side, $#$yn + 1);
             my $y_labels = $spec->{y_labels} || [];
             for (my $i = 0; $i <= $#$yn; $i++) {
-                $layer->addDataSet($yn->[$i], -1, $y_labels->[$i]);
+                if ($#$data_set_colors != -1) {
+                    $layer->addDataSet($yn->[$i], $data_set_colors->[$i], $y_labels->[$i]);
+                } else {
+                    $layer->addDataSet($yn->[$i], -1, $y_labels->[$i]);
+                }
             }
             #Enable bar label for the whole bar
             #$layer->setAggregateLabelStyle()->setFontAngle(90);
@@ -511,7 +561,11 @@
         }
     }
     elsif ($#$yn > -1) {
-        $layer = $c->addBarLayer($yn->[0]);
+        if ($#$data_set_colors != -1) {
+            $layer = $c->addBarLayer($yn->[0], $data_set_colors->[0]);
+        } else {
+            $layer = $c->addBarLayer($yn->[0]);
+        }
         $layer->set3D() if ($spec->{"3D"});
     }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.