| [ Index ] |
PHP Cross Reference of MantisBT |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * File containing the ezcGraphChartElementText 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 * Chart element to display texts in a chart 12 * 13 * Chart elements can be understood as widgets or layout container inside the 14 * chart. The actual transformation to images happens inside the renderers. 15 * They represent all elements inside the chart and contain mostly general 16 * formatting options, while the renderer itself might define additional 17 * formatting options for some chart elments. You can find more about the 18 * general formatting options for chart elements in the base class 19 * ezcGraphChartElement. 20 * 21 * The text element can only be placed at the top or the bottom of the chart. 22 * Beside the common options it has only one additional option defining the 23 * maximum height used for the text box. The actaully required height is 24 * calculated based on the assigned text size. 25 * 26 * <code> 27 * $chart = new ezcGraphPieChart(); 28 * $chart->data['example'] = new ezcGraphArrayDataSet( array( 29 * 'Foo' => 23, 30 * 'Bar' => 42, 31 * ) ); 32 * 33 * $chart->title = 'Some pie chart'; 34 * 35 * // Use at maximum 5% of the chart height for the title. 36 * $chart->title->maxHeight = .05; 37 * 38 * $graph->render( 400, 250, 'title.svg' ); 39 * </code> 40 * 41 * @property float $maxHeight 42 * Maximum percent of bounding used to display the text. 43 * 44 * @version 1.5 45 * @package Graph 46 * @mainclass 47 */ 48 class ezcGraphChartElementText extends ezcGraphChartElement 49 { 50 /** 51 * Constructor 52 * 53 * @param array $options Default option array 54 * @return void 55 * @ignore 56 */ 57 public function __construct( array $options = array() ) 58 { 59 $this->properties['maxHeight'] = .1; 60 61 parent::__construct( $options ); 62 } 63 64 /** 65 * __set 66 * 67 * @param mixed $propertyName 68 * @param mixed $propertyValue 69 * @throws ezcBaseValueException 70 * If a submitted parameter was out of range or type. 71 * @throws ezcBasePropertyNotFoundException 72 * If a the value for the property options is not an instance of 73 * @return void 74 */ 75 public function __set( $propertyName, $propertyValue ) 76 { 77 switch ( $propertyName ) 78 { 79 case 'maxHeight': 80 if ( !is_numeric( $propertyValue ) || 81 ( $propertyValue < 0 ) || 82 ( $propertyValue > 1 ) ) 83 { 84 throw new ezcBaseValueException( $propertyName, $propertyValue, '0 <= float <= 1' ); 85 } 86 87 $this->properties['maxHeight'] = (float) $propertyValue; 88 break; 89 default: 90 parent::__set( $propertyName, $propertyValue ); 91 break; 92 } 93 } 94 95 /** 96 * Render the text 97 * 98 * @param ezcGraphRenderer $renderer Renderer 99 * @param ezcGraphBoundings $boundings Boundings for the axis 100 * @return ezcGraphBoundings Remaining boundings 101 */ 102 public function render( ezcGraphRenderer $renderer, ezcGraphBoundings $boundings ) 103 { 104 $height = (int) min( 105 round( $this->properties['maxHeight'] * ( $boundings->y1 - $boundings->y0 ) ), 106 $this->properties['font']->maxFontSize + $this->padding * 2 + $this->margin * 2 107 ); 108 109 switch ( $this->properties['position'] ) 110 { 111 case ezcGraph::TOP: 112 $textBoundings = new ezcGraphBoundings( 113 $boundings->x0, 114 $boundings->y0, 115 $boundings->x1, 116 $boundings->y0 + $height 117 ); 118 $boundings->y0 += $height + $this->properties['margin']; 119 break; 120 case ezcGraph::BOTTOM: 121 $textBoundings = new ezcGraphBoundings( 122 $boundings->x0, 123 $boundings->y1 - $height, 124 $boundings->x1, 125 $boundings->y1 126 ); 127 $boundings->y1 -= $height + $this->properties['margin']; 128 break; 129 } 130 131 $textBoundings = $renderer->drawBox( 132 $textBoundings, 133 $this->properties['background'], 134 $this->properties['border'], 135 $this->properties['borderWidth'], 136 $this->properties['margin'], 137 $this->properties['padding'] 138 ); 139 140 $renderer->drawText( 141 $textBoundings, 142 $this->properties['title'], 143 ezcGraph::CENTER | ezcGraph::MIDDLE 144 ); 145 146 return $boundings; 147 } 148 } 149 150 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Jul 28 15:48:31 2011 | Cross-referenced by PHPXref 0.7 |