| [ Index ] |
PHP Cross Reference of MantisBT |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * File containing the ezcGraphOdometerChart 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 * Class for odometer charts. Can only use one dataset which will be dispalyed 12 * as a odometer chart. 13 * 14 * <code> 15 * $graph = new ezcGraphOdometerChart(); 16 * $graph->title = 'Custom odometer'; 17 * 18 * $graph->data['data'] = new ezcGraphArrayDataSet( 19 * array( 87 ) 20 * ); 21 * 22 * // Set the marker color 23 * $graph->data['data']->color[0] = '#A0000055'; 24 * 25 * // Set colors for the background gradient 26 * $graph->options->startColor = '#2E3436'; 27 * $graph->options->endColor = '#EEEEEC'; 28 * 29 * // Define a border for the odometer 30 * $graph->options->borderWidth = 2; 31 * $graph->options->borderColor = '#BABDB6'; 32 * 33 * // Set marker width 34 * $graph->options->markerWidth = 5; 35 * 36 * // Set space, which the odometer may consume 37 * $graph->options->odometerHeight = .7; 38 * 39 * // Set axis span and label 40 * $graph->axis->min = 0; 41 * $graph->axis->max = 100; 42 * $graph->axis->label = 'Coverage '; 43 * 44 * $graph->render( 400, 150, 'custom_odometer_chart.svg' ); 45 * </code> 46 * 47 * Each chart consists of several chart elements which represents logical parts 48 * of the chart and can be formatted independently. The odometer chart consists 49 * of: 50 * - title ( {@link ezcGraphChartElementText} ) 51 * - background ( {@link ezcGraphChartElementBackground} ) 52 * 53 * All elements can be configured by accessing them as properties of the chart: 54 * 55 * <code> 56 * $chart->title->position = ezcGraph::BOTTOM; 57 * </code> 58 * 59 * The chart itself also offers several options to configure the appearance. 60 * The extended configure options are available in 61 * {@link ezcGraphOdometerChartOptions} extending the {@link 62 * ezcGraphChartOptions}. 63 * 64 * @property ezcGraphOdometerChartOptions $options 65 * Chart options class 66 * 67 * @version 1.5 68 * @package Graph 69 * @mainclass 70 */ 71 class ezcGraphOdometerChart extends ezcGraphChart 72 { 73 74 /** 75 * Constructor 76 * 77 * @param array $options Default option array 78 * @return void 79 * @ignore 80 */ 81 public function __construct( array $options = array() ) 82 { 83 $this->options = new ezcGraphOdometerChartOptions( $options ); 84 85 parent::__construct( $options ); 86 87 $this->data = new ezcGraphChartSingleDataContainer( $this ); 88 89 $this->addElement( 'axis', new ezcGraphChartElementNumericAxis()); 90 $this->elements['axis']->axisLabelRenderer = new ezcGraphAxisCenteredLabelRenderer(); 91 $this->elements['axis']->axisLabelRenderer->showZeroValue = true; 92 $this->elements['axis']->position = ezcGraph::LEFT; 93 $this->elements['axis']->axisSpace = .05; 94 } 95 96 /** 97 * Property write access 98 * 99 * @throws ezcBasePropertyNotFoundException 100 * If Option could not be found 101 * @throws ezcBaseValueException 102 * If value is out of range 103 * @param string $propertyName Option name 104 * @param mixed $propertyValue Option value; 105 * @return void 106 * @ignore 107 */ 108 public function __set( $propertyName, $propertyValue ) 109 { 110 switch ( $propertyName ) { 111 case 'axis': 112 if ( $propertyValue instanceof ezcGraphChartElementAxis ) 113 { 114 $this->addElement( 'axis', $propertyValue ); 115 $this->elements['axis']->axisLabelRenderer = new ezcGraphAxisCenteredLabelRenderer(); 116 $this->elements['axis']->axisLabelRenderer->showZeroValue = true; 117 $this->elements['axis']->position = ezcGraph::LEFT; 118 $this->elements['axis']->axisSpace = .05; 119 } 120 else 121 { 122 throw new ezcBaseValueException( $propertyName, $propertyValue, 'ezcGraphChartElementAxis' ); 123 } 124 break; 125 case 'renderer': 126 if ( $propertyValue instanceof ezcGraphOdometerRenderer ) 127 { 128 parent::__set( $propertyName, $propertyValue ); 129 } 130 else 131 { 132 throw new ezcBaseValueException( $propertyName, $propertyValue, 'ezcGraphOdometerRenderer' ); 133 } 134 break; 135 default: 136 parent::__set( $propertyName, $propertyValue ); 137 } 138 } 139 140 /** 141 * Render the assigned data 142 * 143 * Will renderer all charts data in the remaining boundings after drawing 144 * all other chart elements. The data will be rendered depending on the 145 * settings in the dataset. 146 * 147 * @param ezcGraphRenderer $renderer Renderer 148 * @param ezcGraphBoundings $boundings Remaining boundings 149 * @return void 150 */ 151 protected function renderData( ezcGraphRenderer $renderer, ezcGraphBoundings $boundings ) 152 { 153 // Draw the odometer data 154 $dataset = $this->data->rewind(); 155 156 foreach ( $dataset as $key => $value ) 157 { 158 $renderer->drawOdometerMarker( 159 $boundings, 160 $this->elements['axis']->axisLabelRenderer->modifyChartDataPosition( 161 new ezcGraphCoordinate( 162 $this->elements['axis']->getCoordinate( $value ), 163 0 164 ) 165 ), 166 $dataset->symbol[$key], 167 $dataset->color[$key], 168 $this->options->markerWidth 169 ); 170 } 171 } 172 173 /** 174 * Returns the default display type of the current chart type. 175 * 176 * @return int Display type 177 */ 178 public function getDefaultDisplayType() 179 { 180 return ezcGraph::ODOMETER; 181 } 182 183 /** 184 * Renders the basic elements of this chart type 185 * 186 * @param int $width 187 * @param int $height 188 * @return void 189 */ 190 protected function renderElements( $width, $height ) 191 { 192 if ( !count( $this->data ) ) 193 { 194 throw new ezcGraphNoDataException(); 195 } 196 197 // Set image properties in driver 198 $this->driver->options->width = $width; 199 $this->driver->options->height = $height; 200 201 // no legend 202 $this->renderElement['legend'] = false; 203 204 // Get boundings from parameters 205 $this->options->width = $width; 206 $this->options->height = $height; 207 208 $boundings = new ezcGraphBoundings(); 209 $boundings->x1 = $this->options->width; 210 $boundings->y1 = $this->options->height; 211 212 // Get values out the single used dataset to calculate axis boundings 213 $values = array(); 214 foreach ( $this->data->rewind() as $value ) 215 { 216 $values[] = $value; 217 } 218 219 // Set values for Axis 220 $this->elements['axis']->addData( $values ); 221 $this->elements['axis']->nullPosition = 0.5 + $this->options->odometerHeight / 2; 222 $this->elements['axis']->calculateAxisBoundings(); 223 224 // Render subelements exept axis, which will be drawn together with the 225 // odometer bar 226 foreach ( $this->elements as $name => $element ) 227 { 228 // Skip element, if it should not get rendered 229 if ( $this->renderElement[$name] === false || 230 $name === 'axis' ) 231 { 232 continue; 233 } 234 235 $this->driver->options->font = $element->font; 236 $boundings = $element->render( $this->renderer, $boundings ); 237 } 238 239 // Draw basic odometer 240 $this->driver->options->font = $this->elements['axis']->font; 241 $boundings = $this->renderer->drawOdometer( 242 $boundings, 243 $this->elements['axis'], 244 $this->options 245 ); 246 247 // Render graph 248 $this->renderData( $this->renderer, $boundings ); 249 } 250 251 /** 252 * Render the pie chart 253 * 254 * Renders the chart into a file or stream. The width and height are 255 * needed to specify the dimensions of the resulting image. For direct 256 * output use 'php://stdout' as output file. 257 * 258 * @param int $width Image width 259 * @param int $height Image height 260 * @param string $file Output file 261 * @apichange 262 * @return void 263 */ 264 public function render( $width, $height, $file = null ) 265 { 266 $this->renderElements( $width, $height ); 267 268 if ( !empty( $file ) ) 269 { 270 $this->renderer->render( $file ); 271 } 272 273 $this->renderedFile = $file; 274 } 275 276 /** 277 * Renders this chart to direct output 278 * 279 * Does the same as ezcGraphChart::render(), but renders directly to 280 * output and not into a file. 281 * 282 * @param int $width 283 * @param int $height 284 * @apichange 285 * @return void 286 */ 287 public function renderToOutput( $width, $height ) 288 { 289 // @TODO: merge this function with render an deprecate ommit of third 290 // argument in render() when API break is possible 291 $this->renderElements( $width, $height ); 292 $this->renderer->render( null ); 293 } 294 } 295 296 ?>
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 |