[ Index ]

PHP Cross Reference of MantisBT

title

Body

[close]

/library/ezc/Graph/src/renderer/ -> axis_label_rotated_boxed.php (source)

   1  <?php
   2  /**
   3   * File containing the ezcGraphAxisRotatedLabelRenderer class
   4   *
   5   * @package Graph
   6   * @version 1.5
   7   * @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
   8   * @license http://ez.no/licenses/new_bsd New BSD License
   9   */
  10  /**
  11   * Can render axis labels rotated, so that more axis labels fit on one axis.
  12   * Produces best results if the axis space was increased, so that more spcae is
  13   * available below the axis.
  14   *
  15   * <code>
  16   *   $chart->xAxis->axisLabelRenderer = new ezcGraphAxisRotatedLabelRenderer();
  17   *
  18   *   // Define angle manually in degree
  19   *   $chart->xAxis->axisLabelRenderer->angle = 45;
  20   *
  21   *   // Increase axis space
  22   *   $chart->xAxis->axisSpace = .2;
  23   * </code>
  24   *
  25   * @property float $angle
  26   *           Angle of labels on axis in degrees.
  27   *
  28   * @version 1.5
  29   * @package Graph
  30   * @mainclass
  31   */
  32  class ezcGraphAxisRotatedBoxedLabelRenderer extends ezcGraphAxisRotatedLabelRenderer
  33  {
  34      /**
  35       * Render Axis labels
  36       *
  37       * Render labels for an axis.
  38       *
  39       * @param ezcGraphRenderer $renderer Renderer used to draw the chart
  40       * @param ezcGraphBoundings $boundings Boundings of the axis
  41       * @param ezcGraphCoordinate $start Axis starting point
  42       * @param ezcGraphCoordinate $end Axis ending point
  43       * @param ezcGraphChartElementAxis $axis Axis instance
  44       * @return void
  45       */
  46      public function renderLabels(
  47          ezcGraphRenderer $renderer,
  48          ezcGraphBoundings $boundings,
  49          ezcGraphCoordinate $start,
  50          ezcGraphCoordinate $end,
  51          ezcGraphChartElementAxis $axis,
  52          ezcGraphBoundings $innerBoundings = null )
  53      {
  54          // receive rendering parameters from axis
  55          $this->steps = $steps = $axis->getSteps();
  56  
  57          $axisBoundings = new ezcGraphBoundings(
  58              $start->x, $start->y,
  59              $end->x, $end->y
  60          );
  61  
  62          // Determine normalized axis direction
  63          $this->direction = new ezcGraphVector(
  64              $end->x - $start->x,
  65              $end->y - $start->y
  66          );
  67          $this->direction->unify();
  68  
  69          // Get axis space
  70          $gridBoundings = null;
  71          list( $xSpace, $ySpace ) = $this->getAxisSpace( $renderer, $boundings, $axis, $innerBoundings, $gridBoundings );
  72  
  73          // Determine optimal angle if none specified
  74          $this->determineAngle( $steps, $xSpace, $ySpace, $axisBoundings );
  75          $degTextAngle = $this->determineTextOffset( $axis, $steps );
  76          $labelLength  = $this->calculateLabelLength( $start, $end, $xSpace, $ySpace, $axisBoundings );
  77  
  78          // Determine additional required axis space by boxes
  79          $firstStep = reset( $steps );
  80          $lastStep = end( $steps );
  81  
  82          $this->widthModifier = 1 + $firstStep->width / 2 + $lastStep->width / 2;
  83  
  84          // Draw steps and grid
  85          foreach ( $steps as $nr => $step )
  86          {
  87              $position = new ezcGraphCoordinate(
  88                  $start->x + ( $end->x - $start->x ) * ( $step->position + $step->width ) / $this->widthModifier,
  89                  $start->y + ( $end->y - $start->y ) * ( $step->position + $step->width ) / $this->widthModifier
  90              );
  91      
  92              $stepWidth = $step->width / $this->widthModifier;
  93  
  94              $stepSize = new ezcGraphCoordinate(
  95                  $axisBoundings->width * $stepWidth,
  96                  $axisBoundings->height * $stepWidth
  97              );
  98  
  99              // Calculate label boundings
 100              $labelSize = $this->calculateLabelSize( $steps, $nr, $step, $xSpace, $ySpace, $axisBoundings );
 101              $lengthReducement = min(
 102                  abs( tan( deg2rad( $this->angle ) ) * ( $labelSize / 2 ) ),
 103                  abs( $labelLength / 2 )
 104              );
 105  
 106              $this->renderLabelText( $renderer, $axis, $position, $step->label, $degTextAngle, $labelLength, $labelSize, $lengthReducement );
 107  
 108              // Major grid
 109              if ( $axis->majorGrid )
 110              {
 111                  $this->drawGrid( $renderer, $gridBoundings, $position, $stepSize, $axis->majorGrid );
 112              }
 113              
 114              // Major step
 115              $this->drawStep( $renderer, $position, $this->direction, $axis->position, $this->majorStepSize, $axis->border );
 116          }
 117      }
 118      
 119      /**
 120       * Modify chart data position
 121       *
 122       * Optionally additionally modify the coodinate of a data point
 123       * 
 124       * @param ezcGraphCoordinate $coordinate Data point coordinate
 125       * @return ezcGraphCoordinate Modified coordinate
 126       */
 127      public function modifyChartDataPosition( ezcGraphCoordinate $coordinate )
 128      {
 129          $firstStep = reset( $this->steps );
 130          $offset = $firstStep->width / 2 / $this->widthModifier;
 131  
 132          return new ezcGraphCoordinate(
 133              $coordinate->x * abs( $this->direction->y ) + (
 134                  $coordinate->x * ( 1 / $this->widthModifier ) * ( 1 - abs( $this->offset ) ) +
 135                  abs( $this->offset ) +
 136                  $offset
 137              ) * abs( $this->direction->x ),
 138              $coordinate->y * abs( $this->direction->x ) + (
 139                  $coordinate->y * ( 1 / $this->widthModifier ) * ( 1 - abs( $this->offset ) ) +
 140                  abs( $this->offset ) +
 141                  $offset
 142              ) * abs( $this->direction->y )
 143          );
 144      }
 145  }
 146  ?>


Generated: Thu Jul 28 15:48:31 2011 Cross-referenced by PHPXref 0.7