Author: Kore Nordmann
Date: 2006-06-12 13:44:21 +0200 (Mon, 12 Jun 2006)
New Revision: 3119

Log:
- Moved pie chart options to own option class

Added:
   trunk/Graph/src/options/pie_chart.php
Modified:
   trunk/Graph/src/charts/pie.php
   trunk/Graph/src/graph_autoload.php

Modified: trunk/Graph/src/charts/pie.php
===================================================================
--- trunk/Graph/src/charts/pie.php      2006-06-12 11:09:21 UTC (rev 3118)
+++ trunk/Graph/src/charts/pie.php      2006-06-12 11:44:21 UTC (rev 3119)
@@ -15,13 +15,9 @@
 class ezcGraphPieChart extends ezcGraphChart
 {
     
-    protected $maxLabelHeight = .15;
-
-    protected $label = '%1$s: %2$d (%3$.1f%%)';
-
     public function __construct( array $options = array() )
     {
-        $this->options = new ezcGraphChartOptions( $options );
+        $this->options = new ezcGraphPieChartOptions( $options );
 
         parent::__construct( $options );
     }
@@ -106,7 +102,7 @@
                     (int) round( cos( deg2rad( $middle ) ) * $radius * 2 / 3 + 
$center->x ),
                     (int) round( sin( deg2rad( $middle ) ) * $radius * 2 / 3 + 
$center->y )
                 ),
-                sprintf( $this->label, $label, $value, $value * 100 / $sum )
+                sprintf( $this->options->label, $label, $value, $value * 100 / 
$sum )
             );
             $angle = $endAngle;
         }
@@ -114,10 +110,10 @@
         $labelHeight = (int) round( min(
             ( $boundings->y1 - $boundings->y0 ) / count( $labels[0] ),
             ( $boundings->y1 - $boundings->y0 ) / count( $labels[1] ),
-            ( $boundings->y1 - $boundings->y0 ) * $this->maxLabelHeight
+            ( $boundings->y1 - $boundings->y0 ) * 
$this->options->maxLabelHeight
         ) );
         
-        $symbolSize = 6;
+        $symbolSize = $this->options->symbolSize;
 
         // Finally draw labels
         foreach ( $labels as $side => $labelPart )

Modified: trunk/Graph/src/graph_autoload.php
===================================================================
--- trunk/Graph/src/graph_autoload.php  2006-06-12 11:09:21 UTC (rev 3118)
+++ trunk/Graph/src/graph_autoload.php  2006-06-12 11:44:21 UTC (rev 3119)
@@ -17,6 +17,7 @@
     'ezcGraphPieChart'                          => 'Graph/charts/pie.php',
     'ezcGraphLineChart'                         => 'Graph/charts/line.php',
     'ezcGraphChartOptions'                      => 'Graph/options/chart.php',
+    'ezcGraphPieChartOptions'                   => 
'Graph/options/pie_chart.php',
     'ezcGraphInvalidImageFileException'         => 
'Graph/exceptions/invalid_image_file.php',
 
     'ezcGraphColor'                             => 'Graph/structs/color.php',

Added: trunk/Graph/src/options/pie_chart.php
===================================================================
--- trunk/Graph/src/options/pie_chart.php       2006-06-12 11:09:21 UTC (rev 
3118)
+++ trunk/Graph/src/options/pie_chart.php       2006-06-12 11:44:21 UTC (rev 
3119)
@@ -0,0 +1,72 @@
+<?php
+/**
+ * File containing the ezcGraphPieChartOption class
+ *
+ * @package Graph
+ * @version //autogentag//
+ * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+/**
+ * Class containing the basic options for charts
+ *
+ * @package Graph
+ */
+class ezcGraphPieChartOptions extends ezcGraphChartOptions
+{
+    /**
+     * Percent of chart height used as maximum height for pie chart labels
+     * 
+     * @var float
+     * @access protected
+     */
+    protected $maxLabelHeight = .15;
+
+    /**
+     * String used to label pies
+     *      %$1s    Name of pie
+     *      %2$d    Value of pie
+     *      %3$.1f  Percentage
+     * 
+     * @var string
+     * @access protected
+     */
+    protected $label = '%1$s: %2$d (%3$.1f%%)';
+
+    /**
+     * Size of symbols used concat a label with a pie
+     * 
+     * @var float
+     * @access protected
+     */
+    protected $symbolSize = 6;
+
+    /**
+     * Set an option value
+     * 
+     * @param string $propertyName 
+     * @param mixed $propertyValue 
+     * @throws ezcBasePropertyNotFoundException
+     *          If a property is not defined in this class
+     * @return void
+     */
+    public function __set( $propertyName, $propertyValue )
+    {
+        switch ( $propertyName )
+        {
+            case 'maxLabelHeight':
+                $this->maxLabelHeight = min( 1, max( 0, (float) $propertyValue 
) );
+                break;
+            case 'label':
+                $this->label = (string) $propertyValue;
+                break;
+            case 'symbolSize':
+                $this->symbolSize = (int) $propertyValue;
+                break;
+            default:
+                return parent::__set( $propertyName, $propertyValue );
+        }
+    }
+}
+
+?>


Property changes on: trunk/Graph/src/options/pie_chart.php
___________________________________________________________________
Name: svn:eol-style
   + native

-- 
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components

Reply via email to