Author: Kore Nordmann
Date: 2006-06-14 15:36:54 +0200 (Wed, 14 Jun 2006)
New Revision: 3131

Log:
- Made line thickness for line charts adjustable

Added:
   trunk/Graph/src/options/line_chart.php
Modified:
   trunk/Graph/src/charts/line.php
   trunk/Graph/src/graph_autoload.php
   trunk/Graph/src/interfaces/renderer.php
   trunk/Graph/src/options/pie_chart.php
   trunk/Graph/src/renderer/2d.php
   trunk/Graph/tests/line_test.php

Modified: trunk/Graph/src/charts/line.php
===================================================================
--- trunk/Graph/src/charts/line.php     2006-06-14 13:12:24 UTC (rev 3130)
+++ trunk/Graph/src/charts/line.php     2006-06-14 13:36:54 UTC (rev 3131)
@@ -17,7 +17,7 @@
  
     public function __construct( array $options = array() )
     {
-        $this->options = new ezcGraphChartOptions( $options );
+        $this->options = new ezcGraphLineChartOptions( $options );
 
         parent::__construct();
 
@@ -88,7 +88,7 @@
                         $data->color->default,
                         $lastPoint,
                         $point,
-                        true
+                        $this->options->lineThickness
                     );
                 }
 

Modified: trunk/Graph/src/graph_autoload.php
===================================================================
--- trunk/Graph/src/graph_autoload.php  2006-06-14 13:12:24 UTC (rev 3130)
+++ trunk/Graph/src/graph_autoload.php  2006-06-14 13:36:54 UTC (rev 3131)
@@ -18,6 +18,7 @@
     'ezcGraphLineChart'                         => 'Graph/charts/line.php',
     'ezcGraphChartOptions'                      => 'Graph/options/chart.php',
     'ezcGraphPieChartOptions'                   => 
'Graph/options/pie_chart.php',
+    'ezcGraphLineChartOptions'                  => 
'Graph/options/line_chart.php',
     'ezcGraphInvalidImageFileException'         => 
'Graph/exceptions/invalid_image_file.php',
 
     'ezcGraphColor'                             => 'Graph/structs/color.php',

Modified: trunk/Graph/src/interfaces/renderer.php
===================================================================
--- trunk/Graph/src/interfaces/renderer.php     2006-06-14 13:12:24 UTC (rev 
3130)
+++ trunk/Graph/src/interfaces/renderer.php     2006-06-14 13:36:54 UTC (rev 
3131)
@@ -46,7 +46,7 @@
      * @param mixed $filled 
      * @return void
      */
-    abstract public function drawLine( ezcGraphColor $color, 
ezcGraphCoordinate $position, ezcGraphCoordinate $end, $filled = true );
+    abstract public function drawLine( ezcGraphColor $color, 
ezcGraphCoordinate $position, ezcGraphCoordinate $end, $thickness = 1 );
     
     /**
      * Draws a text box

Added: trunk/Graph/src/options/line_chart.php
===================================================================
--- trunk/Graph/src/options/line_chart.php      2006-06-14 13:12:24 UTC (rev 
3130)
+++ trunk/Graph/src/options/line_chart.php      2006-06-14 13:36:54 UTC (rev 
3131)
@@ -0,0 +1,66 @@
+<?php
+/**
+ * File containing the ezcGraphLineChartOption 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 line charts
+ *
+ * @package Graph
+ */
+class ezcGraphLineChartOptions extends ezcGraphChartOptions
+{
+    /**
+     * Theickness of chart lines
+     * 
+     * @var float
+     * @access protected
+     */
+    protected $lineThickness = 2;
+
+    /**
+     * Status wheather the space between line and axis should get filled.
+     *  - FALSE to not fill the space at all
+     *  - (int) Opacity used to fill up the space with the lines color
+     *
+     * @var mixed
+     */
+    protected $fillLines = false;
+
+    /**
+     * 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 'lineThickness':
+                $this->lineThickness = max( 1, (int) $propertyValue );
+                break;
+            case 'fillLines':
+                if ( $propertyValue === false )
+                {
+                    $this->fillLines = false;
+                }
+                else
+                {
+                    $this->fillLines = min( 255, max( 0, (int) $propertyValue 
) );
+                }
+                break;
+            default:
+                return parent::__set( $propertyName, $propertyValue );
+        }
+    }
+}
+
+?>


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

Modified: trunk/Graph/src/options/pie_chart.php
===================================================================
--- trunk/Graph/src/options/pie_chart.php       2006-06-14 13:12:24 UTC (rev 
3130)
+++ trunk/Graph/src/options/pie_chart.php       2006-06-14 13:36:54 UTC (rev 
3131)
@@ -8,7 +8,7 @@
  * @license http://ez.no/licenses/new_bsd New BSD License
  */
 /**
- * Class containing the basic options for charts
+ * Class containing the basic options for pie charts
  *
  * @package Graph
  */

Modified: trunk/Graph/src/renderer/2d.php
===================================================================
--- trunk/Graph/src/renderer/2d.php     2006-06-14 13:12:24 UTC (rev 3130)
+++ trunk/Graph/src/renderer/2d.php     2006-06-14 13:36:54 UTC (rev 3131)
@@ -72,13 +72,13 @@
      * @param mixed $filled 
      * @return void
      */
-    public function drawLine( ezcGraphColor $color, ezcGraphCoordinate 
$position, ezcGraphCoordinate $end, $filled = true )
+    public function drawLine( ezcGraphColor $color, ezcGraphCoordinate 
$position, ezcGraphCoordinate $end, $thickness = 1 )
     {
         $this->driver->drawLine(
             $position,
             $end,
             $color,
-            1 + $filled
+            max( 1, $thickness )
         );
     }
     

Modified: trunk/Graph/tests/line_test.php
===================================================================
--- trunk/Graph/tests/line_test.php     2006-06-14 13:12:24 UTC (rev 3130)
+++ trunk/Graph/tests/line_test.php     2006-06-14 13:36:54 UTC (rev 3131)
@@ -46,7 +46,7 @@
      */
     public function tearDown()
     {
-        $this->removeTempDir();
+    //    $this->removeTempDir();
     }
 
     protected function addSampleData( ezcGraphChart $chart )
@@ -114,7 +114,7 @@
                 $this->equalTo( ezcGraphColor::fromHex( '#CC0000' ) ),
                 $this->equalTo( new ezcGraphCoordinate( 120, 85 ) ),
                 $this->equalTo( new ezcGraphCoordinate( 210, 181 ) ),
-                $this->equalTo( true )
+                $this->equalTo( 2 )
             );
         $mockedRenderer
             ->expects( $this->at( 29 ) )
@@ -123,7 +123,7 @@
                 $this->equalTo( ezcGraphColor::fromHex( '#CC0000' ) ),
                 $this->equalTo( new ezcGraphCoordinate( 210, 181 ) ),
                 $this->equalTo( new ezcGraphCoordinate( 300, 44 ) ),
-                $this->equalTo( true )
+                $this->equalTo( 2 )
             );
         $mockedRenderer
             ->expects( $this->at( 30 ) )
@@ -132,7 +132,7 @@
                 $this->equalTo( ezcGraphColor::fromHex( '#CC0000' ) ),
                 $this->equalTo( new ezcGraphCoordinate( 300, 44 ) ),
                 $this->equalTo( new ezcGraphCoordinate( 390, 136 ) ),
-                $this->equalTo( true )
+                $this->equalTo( 2 )
             );
         $mockedRenderer
             ->expects( $this->at( 31 ) )
@@ -141,7 +141,7 @@
                 $this->equalTo( ezcGraphColor::fromHex( '#CC0000' ) ),
                 $this->equalTo( new ezcGraphCoordinate( 390, 136 ) ),
                 $this->equalTo( new ezcGraphCoordinate( 480, 190 ) ),
-                $this->equalTo( true )
+                $this->equalTo( 2 )
             );
 
         $chart->renderer = $mockedRenderer;
@@ -149,6 +149,60 @@
         $chart->render( 500, 200 );
     }
 
+    public function testRenderChartLinesModifiedThickness()
+    {
+        $chart = ezcGraph::create( 'Line' );
+        $chart->sampleData = array( 'sample 1' => 234, 'sample 2' => 21, 
'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 1);
+        $chart->sampleData->color = '#CC0000';
+        $chart->sampleData->symbol = ezcGraph::DIAMOND;
+        $chart->options->lineThickness = 1;
+
+        $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array(
+            'drawLine',
+        ) );
+
+        $mockedRenderer
+            ->expects( $this->at( 28 ) )
+            ->method( 'drawLine' )
+            ->with(
+                $this->equalTo( ezcGraphColor::fromHex( '#CC0000' ) ),
+                $this->equalTo( new ezcGraphCoordinate( 120, 85 ) ),
+                $this->equalTo( new ezcGraphCoordinate( 210, 181 ) ),
+                $this->equalTo( 1 )
+            );
+        $mockedRenderer
+            ->expects( $this->at( 29 ) )
+            ->method( 'drawLine' )
+            ->with(
+                $this->equalTo( ezcGraphColor::fromHex( '#CC0000' ) ),
+                $this->equalTo( new ezcGraphCoordinate( 210, 181 ) ),
+                $this->equalTo( new ezcGraphCoordinate( 300, 44 ) ),
+                $this->equalTo( 1 )
+            );
+        $mockedRenderer
+            ->expects( $this->at( 30 ) )
+            ->method( 'drawLine' )
+            ->with(
+                $this->equalTo( ezcGraphColor::fromHex( '#CC0000' ) ),
+                $this->equalTo( new ezcGraphCoordinate( 300, 44 ) ),
+                $this->equalTo( new ezcGraphCoordinate( 390, 136 ) ),
+                $this->equalTo( 1 )
+            );
+        $mockedRenderer
+            ->expects( $this->at( 31 ) )
+            ->method( 'drawLine' )
+            ->with(
+                $this->equalTo( ezcGraphColor::fromHex( '#CC0000' ) ),
+                $this->equalTo( new ezcGraphCoordinate( 390, 136 ) ),
+                $this->equalTo( new ezcGraphCoordinate( 480, 190 ) ),
+                $this->equalTo( 1 )
+            );
+
+        $chart->renderer = $mockedRenderer;
+
+        $chart->render( 500, 200 );
+    }
+
     public function testRenderChartSymbols()
     {
         $chart = ezcGraph::create( 'Line' );
@@ -250,6 +304,7 @@
         $chart = ezcGraph::create( 'Line' );
         $chart->title = 'Test graph';
         $chart->palette = 'Black';
+        $chart->options->lineThickness = 1;
 
         $this->addSampleData( $chart );
         $chart->legend = false;

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

Reply via email to