Author: Kore Nordmann
Date: 2007-03-29 14:20:03 +0200 (Thu, 29 Mar 2007)
New Revision: 4783

Log:
- Started implementing feature request #9404 (Rotated labels on axis)
  # Works only with SVG driver now.
  # Angle needs to be set manually, no automatic optimal angle detection yet.

Added:
   trunk/Graph/src/renderer/axis_label_rotated.php
   trunk/Graph/tests/axis_rotated_renderer_test.php
   
trunk/Graph/tests/data/compare/ezcGraphAxisRotatedRendererTest_testRenderCompleteLineChart.svg
   
trunk/Graph/tests/data/compare/ezcGraphAxisRotatedRendererTest_testRenderCompleteLineChartReverseRotated.svg
   
trunk/Graph/tests/data/compare/ezcGraphAxisRotatedRendererTest_testRenderRotatedAxisWithLotsOfLabels.svg
   
trunk/Graph/tests/data/compare/ezcGraphSvgDriverTest_testDrawRotatedTextWithMinimizedBorderAndBackgroundTopLeft.svg
   
trunk/Graph/tests/data/compare/ezcGraphSvgDriverTest_testDrawTextBoxShortStringRotated10Degrees.svg
   
trunk/Graph/tests/data/compare/ezcGraphSvgDriverTest_testDrawTextBoxShortStringRotated340Degrees.svg
   
trunk/Graph/tests/data/compare/ezcGraphSvgDriverTest_testDrawTextBoxShortStringRotated45Degrees.svg
Modified:
   trunk/Graph/src/driver/flash.php
   trunk/Graph/src/driver/gd.php
   trunk/Graph/src/driver/svg.php
   trunk/Graph/src/driver/verbose.php
   trunk/Graph/src/interfaces/driver.php
   trunk/Graph/src/interfaces/renderer.php
   trunk/Graph/src/math/rotation.php
   trunk/Graph/src/renderer/2d.php
   trunk/Graph/src/renderer/3d.php
   trunk/Graph/tests/driver_svg_test.php
   trunk/Graph/tests/suite.php
   trunk/Graph/tests/transformation_test.php

Modified: trunk/Graph/src/driver/flash.php
===================================================================
--- trunk/Graph/src/driver/flash.php    2007-03-29 11:52:13 UTC (rev 4782)
+++ trunk/Graph/src/driver/flash.php    2007-03-29 12:20:03 UTC (rev 4783)
@@ -268,9 +268,10 @@
      * @param float $width Width of text box
      * @param float $height Height of text box
      * @param int $align Alignement of text
+     * @param ezcGraphRotation $rotation
      * @return void
      */
-    public function drawTextBox( $string, ezcGraphCoordinate $position, 
$width, $height, $align )
+    public function drawTextBox( $string, ezcGraphCoordinate $position, 
$width, $height, $align, ezcGraphRotation $rotation = null )
     {
         if ( $this->options->font->type !== ezcGraph::PALM_FONT )
         {

Modified: trunk/Graph/src/driver/gd.php
===================================================================
--- trunk/Graph/src/driver/gd.php       2007-03-29 11:52:13 UTC (rev 4782)
+++ trunk/Graph/src/driver/gd.php       2007-03-29 12:20:03 UTC (rev 4783)
@@ -377,9 +377,10 @@
      * @param float $width Width of text box
      * @param float $height Height of text box
      * @param int $align Alignement of text
+     * @param ezcGraphRotation $rotation
      * @return void
      */
-    public function drawTextBox( $string, ezcGraphCoordinate $position, 
$width, $height, $align )
+    public function drawTextBox( $string, ezcGraphCoordinate $position, 
$width, $height, $align, ezcGraphRotation $rotation = null )
     {
         $padding = $this->options->font->padding + ( 
$this->options->font->border !== false ? $this->options->font->borderWidth : 0 
);
 

Modified: trunk/Graph/src/driver/svg.php
===================================================================
--- trunk/Graph/src/driver/svg.php      2007-03-29 11:52:13 UTC (rev 4782)
+++ trunk/Graph/src/driver/svg.php      2007-03-29 12:20:03 UTC (rev 4783)
@@ -422,9 +422,10 @@
      * @param float $width Width of text box
      * @param float $height Height of text box
      * @param int $align Alignement of text
+     * @param ezcGraphRotation $rotation
      * @return void
      */
-    public function drawTextBox( $string, ezcGraphCoordinate $position, 
$width, $height, $align )
+    public function drawTextBox( $string, ezcGraphCoordinate $position, 
$width, $height, $align, ezcGraphRotation $rotation = null )
     {
         $padding = $this->options->font->padding + ( 
$this->options->font->border !== false ? $this->options->font->borderWidth : 0 
);
 
@@ -462,6 +463,7 @@
             'height' => $height,
             'align' => $align,
             'font' => $this->options->font,
+            'rotation' => $rotation,
         );
 
         return $id;
@@ -559,10 +561,20 @@
         foreach ( $this->strings as $text )
         {
             // Add all text elements into one group
-            $this->elements = $this->dom->createElement( 'g' );
-            $this->elements->setAttribute( 'id', $text['id'] );
-            $this->elements = $elementsRoot->appendChild( $this->elements );
+            $group = $this->dom->createElement( 'g' );
+            $group->setAttribute( 'id', $text['id'] );
 
+            if ( $text['rotation'] !== null )
+            {
+                $group->setAttribute( 'transform', sprintf( 'rotate( %.2f %.4f 
%.4f )',
+                    $text['rotation']->getRotation(),
+                    $text['rotation']->getCenter()->x,
+                    $text['rotation']->getCenter()->y
+                ) );
+            }
+
+            $group = $elementsRoot->appendChild( $group );
+
             $size = $text['font']->minimalUsedFont;
             $font = $text['font']->name;
 
@@ -651,6 +663,9 @@
                 );
             }
 
+            // Set elements root temporary to local text group to ensure 
+            // background and border beeing elements of text group
+            $this->elements = $group;
             if ( $text['font']->background !== false )
             {
                 $this->drawPolygon( 
@@ -680,6 +695,7 @@
                     $text['font']->borderWidth
                 );
             }
+            $this->elements = $elementsRoot;
 
             // Bottom line for SVG fonts is lifted a bit
             $text['position']->y += $size * .85;
@@ -731,7 +747,7 @@
                             1 - ( $text['font']->textShadowColor->alpha / 255 )
                         )
                     );
-                    $this->elements->appendChild( $textNode );
+                    $group->appendChild( $textNode );
                 }
                 
                 // Finally draw text
@@ -752,13 +768,11 @@
                         1 - ( $text['font']->color->alpha / 255 )
                     )
                 );
-                $this->elements->appendChild( $textNode );
+                $group->appendChild( $textNode );
 
                 $text['position']->y += $size + $size * 
$this->options->lineSpacing;
             }
         }
-
-        $this->elements = $elementsRoot;
     }
 
     /**

Modified: trunk/Graph/src/driver/verbose.php
===================================================================
--- trunk/Graph/src/driver/verbose.php  2007-03-29 11:52:13 UTC (rev 4782)
+++ trunk/Graph/src/driver/verbose.php  2007-03-29 12:20:03 UTC (rev 4783)
@@ -89,9 +89,10 @@
      * @param mixed $width 
      * @param mixed $height 
      * @param ezcGraphColor $color 
+     * @param ezcGraphRotation $rotation
      * @return void
      */
-    public function drawTextBox( $string, ezcGraphCoordinate $position, 
$width, $height, $align )
+    public function drawTextBox( $string, ezcGraphCoordinate $position, 
$width, $height, $align, ezcGraphRotation $rotation = null )
     {
         printf( "% 4d: Draw text '%s' at ( %.2f, %.2f ) with dimensions ( %d, 
%d ) and alignement %d.\n",
             $this->call++,

Modified: trunk/Graph/src/interfaces/driver.php
===================================================================
--- trunk/Graph/src/interfaces/driver.php       2007-03-29 11:52:13 UTC (rev 
4782)
+++ trunk/Graph/src/interfaces/driver.php       2007-03-29 12:20:03 UTC (rev 
4783)
@@ -424,9 +424,10 @@
      * @param float $width Width of text box
      * @param float $height Height of text box
      * @param int $align Alignement of text
+     * @param ezcGraphRotation $rotation
      * @return void
      */
-    abstract public function drawTextBox( $string, ezcGraphCoordinate 
$position, $width, $height, $align );
+    abstract public function drawTextBox( $string, ezcGraphCoordinate 
$position, $width, $height, $align, ezcGraphRotation $rotation = null );
     
     /**
      * Draws a sector of cirlce

Modified: trunk/Graph/src/interfaces/renderer.php
===================================================================
--- trunk/Graph/src/interfaces/renderer.php     2007-03-29 11:52:13 UTC (rev 
4782)
+++ trunk/Graph/src/interfaces/renderer.php     2007-03-29 12:20:03 UTC (rev 
4783)
@@ -271,13 +271,14 @@
      * @param ezcGraphBoundings $boundings Boundings of text
      * @param string $text Text
      * @param int $align Alignement of text
-     * @param int $align Alignement of text
+     * @param ezcGraphRotation $rotation
      * @return void
      */
     abstract public function drawText(
         ezcGraphBoundings $boundings,
         $text,
-        $align = ezcGraph::LEFT
+        $align = ezcGraph::LEFT,
+        ezcGraphRotation $rotation = null
     );
 
     /**

Modified: trunk/Graph/src/math/rotation.php
===================================================================
--- trunk/Graph/src/math/rotation.php   2007-03-29 11:52:13 UTC (rev 4782)
+++ trunk/Graph/src/math/rotation.php   2007-03-29 12:20:03 UTC (rev 4783)
@@ -44,6 +44,8 @@
 
         if ( $center === null )
         {
+            $this->center = new ezcGraphCoordinate( 0, 0 );
+
             $clockwiseRotation = deg2rad( $rotation );
             $rotationMatrixArray = array( 
                 array( cos( $clockwiseRotation ), -sin( $clockwiseRotation ), 
0 ),
@@ -62,6 +64,26 @@
         $this->multiply( new ezcGraphRotation( $rotation ) );
         $this->multiply( new ezcGraphTranslation( -$center->x, -$center->y ) );
     }
+
+    /**
+     * Return rotaion angle in degrees
+     * 
+     * @return float
+     */
+    public function getRotation()
+    {
+        return $this->rotation;
+    }
+
+    /**
+     * Return the center point of the current rotation
+     * 
+     * @return ezcGraphCoordinate
+     */
+    public function getCenter()
+    {
+        return $this->center;
+    }
 }
 
 ?>

Modified: trunk/Graph/src/renderer/2d.php
===================================================================
--- trunk/Graph/src/renderer/2d.php     2007-03-29 11:52:13 UTC (rev 4782)
+++ trunk/Graph/src/renderer/2d.php     2007-03-29 12:20:03 UTC (rev 4783)
@@ -940,19 +940,22 @@
      * @param ezcGraphBoundings $boundings Boundings of text
      * @param string $text Text
      * @param int $align Alignement of text
+     * @param ezcGraphRotation $rotation
      * @return void
      */
     public function drawText(
         ezcGraphBoundings $boundings,
         $text,
-        $align = ezcGraph::LEFT )
+        $align = ezcGraph::LEFT,
+        ezcGraphRotation $rotation = null )
     {
         $this->driver->drawTextBox(
             $text,
             new ezcGraphCoordinate( $boundings->x0, $boundings->y0 ),
             $boundings->width,
             $boundings->height,
-            $align
+            $align,
+            $rotation
         );
     }
 

Modified: trunk/Graph/src/renderer/3d.php
===================================================================
--- trunk/Graph/src/renderer/3d.php     2007-03-29 11:52:13 UTC (rev 4782)
+++ trunk/Graph/src/renderer/3d.php     2007-03-29 12:20:03 UTC (rev 4783)
@@ -1569,12 +1569,14 @@
      * @param ezcGraphBoundings $boundings Boundings of text
      * @param string $text Text
      * @param int $align Alignement of text
+     * @param ezcGraphRotation $rotation
      * @return void
      */
     public function drawText(
         ezcGraphBoundings $boundings,
         $text,
-        $align = ezcGraph::LEFT )
+        $align = ezcGraph::LEFT,
+        ezcGraphRotation $rotation = null )
     {
         if ( $this->depth === false )
         {
@@ -1611,7 +1613,8 @@
             $topleft,
             $bottomright->x - $topleft->x,
             $bottomright->y - $topleft->y,
-            $align
+            $align,
+            $rotation
         );
     }
 

Added: trunk/Graph/src/renderer/axis_label_rotated.php
===================================================================
--- trunk/Graph/src/renderer/axis_label_rotated.php     2007-03-29 11:52:13 UTC 
(rev 4782)
+++ trunk/Graph/src/renderer/axis_label_rotated.php     2007-03-29 12:20:03 UTC 
(rev 4783)
@@ -0,0 +1,317 @@
+<?php
+/**
+ * File containing the ezcGraphAxisRotatedLabelRenderer class
+ *
+ * @package Graph
+ * @version //autogentag//
+ * @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved.
+        2006 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+/**
+ * Renders axis labels centered between two axis steps like normally used for 
+ * bar charts.
+ *
+ * @property float $angle
+ *           Angle of labels on axis in degrees.
+ *
+ * @package Graph
+ * @mainclass
+ */
+class ezcGraphAxisRotatedLabelRenderer extends ezcGraphAxisLabelRenderer
+{
+    /**
+     * Store step array for later coordinate modifications
+     * 
+     * @var array( ezcGraphStep )
+     */
+    protected $steps;
+
+    /**
+     * Store direction for later coordinate modifications
+     * 
+     * @var ezcGraphVector
+     */
+    protected $direction;
+
+    /**
+     * Store coordinate width modifier for later coordinate modifications
+     * 
+     * @var float
+     */
+    protected $widthModifier;
+    
+    /**
+     * Store coordinate offset for later coordinate modifications
+     * 
+     * @var float
+     */
+    protected $offset;
+    
+    /**
+     * Constructor
+     * 
+     * @param array $options Default option array
+     * @return void
+     * @ignore
+     */
+    public function __construct( array $options = array() )
+    {
+        parent::__construct( $options );
+        $this->properties['angle'] = 45.;
+    }
+
+    /**
+     * __set 
+     * 
+     * @param mixed $propertyName 
+     * @param mixed $propertyValue 
+     * @throws ezcBaseValueException
+     *          If a submitted parameter was out of range or type.
+     * @throws ezcBasePropertyNotFoundException
+     *          If a the value for the property options is not an instance of
+     * @return void
+     * @ignore
+     */
+    public function __set( $propertyName, $propertyValue )
+    {
+        switch ( $propertyName )
+        {
+            case 'angle':
+                if ( !is_numeric( $propertyValue ) )
+                {
+                    throw new ezcBaseValueException( $propertyName, 
$propertyValue, '0 <= float < 360' );
+                }
+
+                $reducement = (int) ( $propertyValue - $propertyValue % 360 );
+                $this->properties['angle'] = (float) $propertyValue - 
$reducement;
+                break;
+            default:
+                return parent::__set( $propertyName, $propertyValue );
+        }
+    }
+
+    /**
+     * Render Axis labels
+     *
+     * Render labels for an axis.
+     *
+     * @param ezcGraphRenderer $renderer Renderer used to draw the chart
+     * @param ezcGraphBoundings $boundings Boundings of the axis
+     * @param ezcGraphCoordinate $start Axis starting point
+     * @param ezcGraphCoordinate $end Axis ending point
+     * @param ezcGraphChartElementAxis $axis Axis instance
+     * @return void
+     */
+    public function renderLabels(
+        ezcGraphRenderer $renderer,
+        ezcGraphBoundings $boundings,
+        ezcGraphCoordinate $start,
+        ezcGraphCoordinate $end,
+        ezcGraphChartElementAxis $axis )
+    {
+        // receive rendering parameters from axis
+        $steps = $axis->getSteps();
+        $this->steps = $steps;
+
+        $axisBoundings = new ezcGraphBoundings(
+            $start->x, $start->y,
+            $end->x, $end->y
+        );
+
+        // Determine normalized axis direction
+        $this->direction = new ezcGraphVector(
+            $end->x - $start->x,
+            $end->y - $start->y
+        );
+        $this->direction->unify();
+        $axisAngle = -$this->direction->angle( new ezcGraphVector( 1, 0 ) );
+
+        if ( $this->outerGrid )
+        {
+            $gridBoundings = $boundings;
+        }
+        else
+        {
+            $gridBoundings = new ezcGraphBoundings(
+                $boundings->x0 + $renderer->xAxisSpace,
+                $boundings->y0 + $renderer->yAxisSpace,
+                $boundings->x1 - $renderer->xAxisSpace,
+                $boundings->y1 - $renderer->yAxisSpace
+            );
+        }
+
+        // Determine additional required axis space by boxes
+        $firstStep = reset( $steps );
+        $lastStep = end( $steps );
+
+        $textAngle = $axisAngle + 
+            deg2rad( $this->angle ) + 
+            ( $axis->position & ( ezcGraph::TOP | ezcGraph::BOTTOM ) ? 
deg2rad( 270 ) : $ninety = deg2rad( 90 ) );
+        $degTextAngle = rad2deg( $textAngle );
+
+        $this->offset = min( 1, -cos( $textAngle ) / sin( $textAngle ) );
+
+        $axisSpaceFactor = abs(
+            ( $this->direction->x == 0 ? 0 :
+                $this->direction->x * $renderer->yAxisSpace / 
$axisBoundings->width ) +
+            ( $this->direction->y == 0 ? 0 :
+                $this->direction->y * $renderer->xAxisSpace / 
$axisBoundings->height )
+        );
+
+        $start = new ezcGraphCoordinate(
+            $start->x + max( 0., $axisSpaceFactor * $this->offset ) * ( 
$end->x - $start->x ),
+            $start->y + max( 0., $axisSpaceFactor * $this->offset ) * ( 
$end->y - $start->y )
+        );
+        $end = new ezcGraphCoordinate(
+            $end->x + min( 0., $axisSpaceFactor * $this->offset ) * ( $end->x 
- $start->x ),
+            $end->y + min( 0., $axisSpaceFactor * $this->offset ) * ( $end->y 
- $start->y )
+        );
+
+        $labelLength = sqrt(
+            pow(
+                $renderer->xAxisSpace * $this->direction->y +
+                $axisSpaceFactor * $this->offset * ( $end->x - $start->x ),
+                2 ) +
+            pow(
+                $renderer->yAxisSpace * $this->direction->x +
+                $axisSpaceFactor * $this->offset * ( $end->y - $start->y ),
+                2 )
+        );
+
+        $this->offset *= $axisSpaceFactor;
+
+        // Draw steps and grid
+        foreach ( $steps as $nr => $step )
+        {
+            $position = new ezcGraphCoordinate(
+                $start->x + ( $end->x - $start->x ) * $step->position,
+                $start->y + ( $end->y - $start->y ) * $step->position
+            );
+    
+            $stepSize = new ezcGraphCoordinate(
+                ( $end->x - $start->x ) * $step->width,
+                ( $end->y - $start->y ) * $step->width
+            );
+
+            // Calculate label boundings
+            switch ( true )
+            {
+                case ( $nr === 0 ):
+                    $labelSize = min(
+                        abs( 
+                            $renderer->xAxisSpace * 2 * $this->direction->x +
+                            $renderer->yAxisSpace * 2 * $this->direction->y ),
+                        abs( 
+                            $step->width * $axisBoundings->width * 
$this->direction->x +
+                            $step->width * $axisBoundings->height * 
$this->direction->y )
+                    );
+                    break;
+                case ( $step->isLast ):
+                    $labelSize = min(
+                        abs( 
+                            $renderer->xAxisSpace * 2 * $this->direction->x +
+                            $renderer->yAxisSpace * 2 * $this->direction->y ),
+                        abs( 
+                            $steps[$nr - 1]->width * $axisBoundings->width * 
$this->direction->x +
+                            $steps[$nr - 1]->width * $axisBoundings->height * 
$this->direction->y )
+                    );
+                    break;
+                default:
+                    $labelSize = min(
+                        abs( 
+                            $step->width * $axisBoundings->width * 
$this->direction->x +
+                            $step->width * $axisBoundings->height * 
$this->direction->y ),
+                        abs( 
+                            $steps[$nr - 1]->width * $axisBoundings->width * 
$this->direction->x +
+                            $steps[$nr - 1]->width * $axisBoundings->height * 
$this->direction->y )
+                    );
+                    break;
+            }
+
+            $labelSize -= $labelSize * cos( deg2rad( $this->angle ) ) / 2;
+
+            if ( $degTextAngle >= 90 && $degTextAngle < 270 )
+            {
+                $renderer->drawText(
+                    new ezcGraphBoundings(
+                        $position->x - abs( $labelLength ),
+                        $position->y - $labelSize / 2,
+                        $position->x,
+                        $position->y + $labelSize / 2
+                    ),
+                    $step->label . ' ',
+                    ezcGraph::RIGHT | ezcGraph::MIDDLE,
+                    new ezcGraphRotation(
+                        $degTextAngle - 180,
+                        new ezcGraphCoordinate(
+                            $position->x,
+                            $position->y
+                        )
+                    )
+                );
+            }
+            else
+            {
+                $renderer->drawText(
+                    new ezcGraphBoundings(
+                        $position->x,
+                        $position->y - $labelSize / 2,
+                        $position->x + abs( $labelLength ),
+                        $position->y + $labelSize / 2
+                    ),
+                    ' ' . $step->label, 
+                    ezcGraph::LEFT | ezcGraph::MIDDLE,
+                    new ezcGraphRotation(
+                        $degTextAngle,
+                        new ezcGraphCoordinate(
+                            $position->x,
+                            $position->y
+                        )
+                    )
+                );
+            }
+
+            // major grid
+            if ( $axis->majorGrid )
+            {
+                $this->drawGrid( 
+                    $renderer, 
+                    $gridBoundings, 
+                    $position,
+                    $stepSize,
+                    $axis->majorGrid
+                );
+            }
+            
+            // major step
+            $this->drawStep( 
+                $renderer, 
+                $position,
+                $this->direction, 
+                $axis->position, 
+                $this->majorStepSize, 
+                $axis->border
+            );
+        }
+    }
+    
+    /**
+     * Modify chart data position
+     *
+     * Optionally additionally modify the coodinate of a data point
+     * 
+     * @param ezcGraphCoordinate $coordinate Data point coordinate
+     * @return ezcGraphCoordinate Modified coordinate
+     */
+    public function modifyChartDataPosition( ezcGraphCoordinate $coordinate )
+    {
+        return new ezcGraphCoordinate(
+            $coordinate->x * abs( $this->direction->y ) +
+                ( $coordinate->x * ( 1 - abs( $this->offset ) ) + max( 0, 
$this->offset ) ) * abs( $this->direction->x ),
+            $coordinate->y * abs( $this->direction->x ) +
+                ( $coordinate->y * ( 1 - abs( $this->offset ) ) + max( 0, 
$this->offset ) ) * abs( $this->direction->y )
+        );
+    }
+}
+?>


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

Added: trunk/Graph/tests/axis_rotated_renderer_test.php
===================================================================
--- trunk/Graph/tests/axis_rotated_renderer_test.php    2007-03-29 11:52:13 UTC 
(rev 4782)
+++ trunk/Graph/tests/axis_rotated_renderer_test.php    2007-03-29 12:20:03 UTC 
(rev 4783)
@@ -0,0 +1,213 @@
+<?php
+/**
+ * ezcGraphAxisRotatedRendererTest 
+ * 
+ * @package Graph
+ * @version //autogen//
+ * @subpackage Tests
+ * @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+
+require_once dirname( __FILE__ ) . '/test_case.php';
+
+/**
+ * Tests for ezcGraph class.
+ * 
+ * @package ImageAnalysis
+ * @subpackage Tests
+ */
+class ezcGraphAxisRotatedRendererTest extends ezcGraphTestCase
+{
+    protected $basePath;
+
+    protected $tempDir;
+
+    protected $renderer;
+
+    protected $driver;
+
+       public static function suite()
+       {
+               return new PHPUnit_Framework_TestSuite( 
"ezcGraphAxisRotatedRendererTest" );
+       }
+
+    protected function setUp()
+    {
+        static $i = 0;
+
+        if ( version_compare( phpversion(), '5.1.3', '<' ) )
+        {
+            $this->markTestSkipped( "This test requires PHP 5.1.3 or later." );
+        }
+
+        $this->tempDir = $this->createTempDir( __CLASS__ . sprintf( '_%03d_', 
++$i ) ) . '/';
+        $this->basePath = dirname( __FILE__ ) . '/data/';
+    }
+    
+    protected function tearDown()
+    {
+        if ( !$this->hasFailed() )
+        {
+            $this->removeTempDir();
+        }
+    }
+
+    public function testRenderTextBoxes()
+    {
+        $chart = new ezcGraphLineChart();
+        $chart->palette = new ezcGraphPaletteBlack();
+        $chart->xAxis->axisLabelRenderer = new 
ezcGraphAxisRotatedLabelRenderer();
+        $chart->yAxis->axisLabelRenderer = new ezcGraphAxisNoLabelRenderer();
+        $chart->data['sampleData'] = new ezcGraphArrayDataSet( array( 'sample 
1' => 234, 'sample 2' => 21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' 
=> 1) );
+        
+        $mockedRenderer = $this->getMock( 'ezcGraphRenderer2d', array(
+            'drawText',
+        ) );
+
+        $mockedRenderer
+            ->expects( $this->at( 0 ) )
+            ->method( 'drawText' )
+            ->with(
+                $this->equalTo( new ezcGraphBoundings( 132.5, 154., 160., 206. 
), 1. ),
+                $this->equalTo( 'sample 1 ' ),
+                $this->equalTo( ezcGraph::MIDDLE | ezcGraph::RIGHT ),
+                $this->equalTo( new ezcGraphRotation( -45, new 
ezcGraphCoordinate( 160, 180 ) ) )
+            );
+        $mockedRenderer
+            ->expects( $this->at( 1 ) )
+            ->method( 'drawText' )
+            ->with(
+                $this->equalTo( new ezcGraphBoundings( 207.5, 154., 235., 206. 
), 1. ),
+                $this->equalTo( 'sample 2 ' ),
+                $this->equalTo( ezcGraph::MIDDLE | ezcGraph::RIGHT ),
+                $this->equalTo( new ezcGraphRotation( -45, new 
ezcGraphCoordinate( 235, 180 ) ) )
+            );
+        $mockedRenderer
+            ->expects( $this->at( 4 ) )
+            ->method( 'drawText' )
+            ->with(
+                $this->equalTo( new ezcGraphBoundings( 432.5, 154., 460., 206. 
), 1. ),
+                $this->equalTo( 'sample 5 ' ),
+                $this->equalTo( ezcGraph::MIDDLE | ezcGraph::RIGHT ),
+                $this->equalTo( new ezcGraphRotation( -45, new 
ezcGraphCoordinate( 460, 180 ) ) )
+            );
+
+        $chart->renderer = $mockedRenderer;
+
+        $chart->render( 500, 200 );
+    }
+
+    public function testAxisRotatedLabelRendererPropertyAngle()
+    {
+        $options = new ezcGraphAxisRotatedLabelRenderer();
+
+        $this->assertSame(
+            45.,
+            $options->angle,
+            'Wrong default value for property angle in class 
ezcGraphAxisRotatedLabelRenderer'
+        );
+
+        $options->angle = 89.5;
+        $this->assertSame(
+            89.5,
+            $options->angle,
+            'Setting property value did not work for property angle in class 
ezcGraphAxisRotatedLabelRenderer'
+        );
+
+        $options->angle = 410.5;
+        $this->assertSame(
+            50.5,
+            $options->angle,
+            'Setting property value did not work for property angle in class 
ezcGraphAxisRotatedLabelRenderer'
+        );
+
+        try
+        {
+            $options->angle = false;
+        }
+        catch ( ezcBaseValueException $e )
+        {
+            return true;
+        }
+
+        $this->fail( 'Expected ezcBaseValueException.' );
+    }
+
+    public function testRenderCompleteLineChart()
+    {
+        $filename = $this->tempDir . __FUNCTION__ . '.svg';
+
+        $chart = new ezcGraphLineChart();
+
+        $chart->data['Line 1'] = new ezcGraphArrayDataSet( array( 'sample 1' 
=> 234, 'sample 2' => 21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 
1) );
+        $chart->data['Line 2'] = new ezcGraphArrayDataSet( array( 'sample 1' 
=> 543, 'sample 2' => 234, 'sample 3' => 298, 'sample 4' => 5, 'sample 5' => 
613) );
+
+        $chart->xAxis->axisLabelRenderer = new 
ezcGraphAxisRotatedLabelRenderer();
+        $chart->xAxis->axisSpace = .25;
+        $chart->yAxis->axisLabelRenderer = new 
ezcGraphAxisRotatedLabelRenderer();
+
+        $chart->render( 500, 200, $filename );
+
+        $this->compare(
+            $filename,
+            $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . 
'.svg'
+        );
+    }
+
+    public function testRenderCompleteLineChartReverseRotated()
+    {
+        $filename = $this->tempDir . __FUNCTION__ . '.svg';
+
+        $chart = new ezcGraphLineChart();
+
+        $chart->data['Line 1'] = new ezcGraphArrayDataSet( array( 'sample 1' 
=> 234, 'sample 2' => 21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 
1) );
+        $chart->data['Line 2'] = new ezcGraphArrayDataSet( array( 'sample 1' 
=> 543, 'sample 2' => 234, 'sample 3' => 298, 'sample 4' => 5, 'sample 5' => 
613) );
+
+        $chart->xAxis->axisLabelRenderer = new 
ezcGraphAxisRotatedLabelRenderer();
+        $chart->xAxis->axisSpace = .25;
+        $chart->xAxis->axisLabelRenderer->angle = -45;
+
+        $chart->yAxis->axisLabelRenderer = new 
ezcGraphAxisRotatedLabelRenderer();
+        $chart->yAxis->axisLabelRenderer->angle = -45;
+
+        $chart->render( 500, 200, $filename );
+
+        $this->compare(
+            $filename,
+            $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . 
'.svg'
+        );
+    }
+
+    public function testRenderRotatedAxisWithLotsOfLabels()
+    {
+        $filename = $this->tempDir . __FUNCTION__ . '.svg';
+
+        $labelCount = 30;
+
+        // Make this reproducible
+        mt_srand( 23 );
+
+        for ( $i = 0; $i < $labelCount; ++$i )
+        {
+            $data[(string) ( 2000 + $i )] = mt_rand( 500, 2000 );
+        }
+
+        $chart = new ezcGraphLineChart();
+        $chart->data['sample'] = new ezcGraphArrayDataSet( $data );
+
+        // Set manual label count
+        $chart->xAxis->labelCount = 31;
+
+        $chart->xAxis->axisLabelRenderer = new 
ezcGraphAxisRotatedLabelRenderer();
+
+        $chart->render( 500, 200, $filename );
+
+        $this->compare(
+            $filename,
+            $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . 
'.svg'
+        );
+    }
+}
+
+?>


Property changes on: trunk/Graph/tests/axis_rotated_renderer_test.php
___________________________________________________________________
Name: svn:eol-style
   + native

Added: 
trunk/Graph/tests/data/compare/ezcGraphAxisRotatedRendererTest_testRenderCompleteLineChart.svg
===================================================================
(Binary files differ)


Property changes on: 
trunk/Graph/tests/data/compare/ezcGraphAxisRotatedRendererTest_testRenderCompleteLineChart.svg
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream
Name: svn:eol-style
   + native

Added: 
trunk/Graph/tests/data/compare/ezcGraphAxisRotatedRendererTest_testRenderCompleteLineChartReverseRotated.svg
===================================================================
(Binary files differ)


Property changes on: 
trunk/Graph/tests/data/compare/ezcGraphAxisRotatedRendererTest_testRenderCompleteLineChartReverseRotated.svg
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream
Name: svn:eol-style
   + native

Added: 
trunk/Graph/tests/data/compare/ezcGraphAxisRotatedRendererTest_testRenderRotatedAxisWithLotsOfLabels.svg
===================================================================
(Binary files differ)


Property changes on: 
trunk/Graph/tests/data/compare/ezcGraphAxisRotatedRendererTest_testRenderRotatedAxisWithLotsOfLabels.svg
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream
Name: svn:eol-style
   + native

Added: 
trunk/Graph/tests/data/compare/ezcGraphSvgDriverTest_testDrawRotatedTextWithMinimizedBorderAndBackgroundTopLeft.svg
===================================================================
(Binary files differ)


Property changes on: 
trunk/Graph/tests/data/compare/ezcGraphSvgDriverTest_testDrawRotatedTextWithMinimizedBorderAndBackgroundTopLeft.svg
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream
Name: svn:eol-style
   + native

Added: 
trunk/Graph/tests/data/compare/ezcGraphSvgDriverTest_testDrawTextBoxShortStringRotated10Degrees.svg
===================================================================
(Binary files differ)


Property changes on: 
trunk/Graph/tests/data/compare/ezcGraphSvgDriverTest_testDrawTextBoxShortStringRotated10Degrees.svg
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream
Name: svn:eol-style
   + native

Added: 
trunk/Graph/tests/data/compare/ezcGraphSvgDriverTest_testDrawTextBoxShortStringRotated340Degrees.svg
===================================================================
(Binary files differ)


Property changes on: 
trunk/Graph/tests/data/compare/ezcGraphSvgDriverTest_testDrawTextBoxShortStringRotated340Degrees.svg
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream
Name: svn:eol-style
   + native

Added: 
trunk/Graph/tests/data/compare/ezcGraphSvgDriverTest_testDrawTextBoxShortStringRotated45Degrees.svg
===================================================================
(Binary files differ)


Property changes on: 
trunk/Graph/tests/data/compare/ezcGraphSvgDriverTest_testDrawTextBoxShortStringRotated45Degrees.svg
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream
Name: svn:eol-style
   + native

Modified: trunk/Graph/tests/driver_svg_test.php
===================================================================
--- trunk/Graph/tests/driver_svg_test.php       2007-03-29 11:52:13 UTC (rev 
4782)
+++ trunk/Graph/tests/driver_svg_test.php       2007-03-29 12:20:03 UTC (rev 
4783)
@@ -586,6 +586,69 @@
         );
     }
 
+    public function testDrawTextBoxShortStringRotated10Degrees()
+    {
+        $filename = $this->tempDir . __FUNCTION__ . '.svg';
+
+        $return = $this->driver->drawTextBox(
+            'Short',
+            new ezcGraphCoordinate( 10, 10 ),
+            150,
+            70,
+            ezcGraph::LEFT,
+            new ezcGraphRotation( 10 )
+        );
+
+        $this->driver->render( $filename );
+
+        $this->compare( 
+            $filename,
+            $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . 
'.svg'
+        );
+    }
+
+    public function testDrawTextBoxShortStringRotated45Degrees()
+    {
+        $filename = $this->tempDir . __FUNCTION__ . '.svg';
+
+        $return = $this->driver->drawTextBox(
+            'Short',
+            new ezcGraphCoordinate( 10, 10 ),
+            150,
+            70,
+            ezcGraph::LEFT,
+            new ezcGraphRotation( 45, new ezcGraphCoordinate( 100, 50 ) )
+        );
+
+        $this->driver->render( $filename );
+
+        $this->compare( 
+            $filename,
+            $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . 
'.svg'
+        );
+    }
+
+    public function testDrawTextBoxShortStringRotated340Degrees()
+    {
+        $filename = $this->tempDir . __FUNCTION__ . '.svg';
+
+        $return = $this->driver->drawTextBox(
+            'Short',
+            new ezcGraphCoordinate( 10, 10 ),
+            150,
+            70,
+            ezcGraph::LEFT,
+            new ezcGraphRotation( 340, new ezcGraphCoordinate( 200, 100 ) )
+        );
+
+        $this->driver->render( $filename );
+
+        $this->compare( 
+            $filename,
+            $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . 
'.svg'
+        );
+    }
+
     public function testDrawTextBoxLongString()
     {
         $filename = $this->tempDir . __FUNCTION__ . '.svg';
@@ -1171,6 +1234,32 @@
         );
     }
 
+    public function 
testDrawRotatedTextWithMinimizedBorderAndBackgroundTopLeft()
+    {
+        $filename = $this->tempDir . __FUNCTION__ . '.svg';
+
+        $this->driver->options->font->border = ezcGraphColor::fromHex( 
'#555555' );
+        $this->driver->options->font->background = ezcGraphColor::fromHex( 
'#DDDDDD' );
+        $this->driver->options->font->minimizeBorder = true;
+        $this->driver->options->font->padding = 2;
+
+        $this->driver->drawTextBox(
+            'Some test string',
+            new ezcGraphCoordinate( 10, 10 ),
+            150,
+            70,
+            ezcGraph::LEFT | ezcGraph::TOP,
+            new ezcGraphRotation( 15 )
+        );
+
+        $this->driver->render( $filename );
+
+        $this->compare( 
+            $filename,
+            $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . 
'.svg'
+        );
+    }
+
     public function testDrawTextWithMinimizedBorderAndBackgroundMiddleCenter()
     {
         $filename = $this->tempDir . __FUNCTION__ . '.svg';

Modified: trunk/Graph/tests/suite.php
===================================================================
--- trunk/Graph/tests/suite.php 2007-03-29 11:52:13 UTC (rev 4782)
+++ trunk/Graph/tests/suite.php 2007-03-29 12:20:03 UTC (rev 4783)
@@ -14,6 +14,7 @@
 */
 require_once 'axis_centered_renderer_test.php';
 require_once 'axis_exact_renderer_test.php';
+require_once 'axis_rotated_renderer_test.php';
 require_once 'background_test.php';
 require_once 'boundings_test.php';
 require_once 'chart_test.php';
@@ -62,6 +63,7 @@
 
         $this->addTest( ezcGraphAxisCenteredRendererTest::suite() );
         $this->addTest( ezcGraphAxisExactRendererTest::suite() );
+        $this->addTest( ezcGraphAxisRotatedRendererTest::suite() );
         $this->addTest( ezcGraphBackgroundTest::suite() );
         $this->addTest( ezcGraphBoundingsTest::suite() );
         $this->addTest( ezcGraphChartTest::suite() );

Modified: trunk/Graph/tests/transformation_test.php
===================================================================
--- trunk/Graph/tests/transformation_test.php   2007-03-29 11:52:13 UTC (rev 
4782)
+++ trunk/Graph/tests/transformation_test.php   2007-03-29 12:20:03 UTC (rev 
4783)
@@ -116,6 +116,26 @@
         );
     }
 
+    public function testRotationGetCenter()
+    {
+        $transformation = new ezcGraphRotation( 90 );
+
+        $this->assertEquals(
+            new ezcGraphCoordinate( 0, 0 ),
+            $transformation->getCenter()
+        );
+    }
+
+    public function testRotationGetRotation()
+    {
+        $transformation = new ezcGraphRotation( 17 );
+
+        $this->assertEquals(
+            17.,
+            $transformation->getRotation()
+        );
+    }
+
     public function testCreateTranslatedRotation()
     {
         $transformation = new ezcGraphRotation( 90, new ezcGraphCoordinate( 
10, 10 ) );

-- 
svn-components mailing list
svn-components@lists.ez.no
http://lists.ez.no/mailman/listinfo/svn-components

Reply via email to