| [ Index ] |
PHP Cross Reference of MantisBT |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * File containing the abstract ezcGraphRenderer 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 * Abstract class to transform the basic chart components. To be extended by 12 * three- and twodimensional renderers. 13 * 14 * @version 1.5 15 * @package Graph 16 */ 17 abstract class ezcGraphRenderer 18 { 19 20 /** 21 * Driver used to render results 22 * 23 * @var ezcGraphDriver 24 */ 25 protected $driver; 26 27 /** 28 * Axis space used for the x axis 29 * 30 * @var float 31 */ 32 protected $xAxisSpace = false; 33 34 /** 35 * Axis space used for the y axis 36 * 37 * @var float 38 */ 39 protected $yAxisSpace = false; 40 41 /** 42 * Context sensitive references to chart elements to use for referencing 43 * image elements depending on the output driver, like image maps, etc. 44 * 45 * @var array 46 */ 47 protected $elements = array(); 48 49 /** 50 * Set renderers driver 51 * 52 * This method is used internally to set the direver used inside the chart 53 * class in the renderer. If you want to change the driver used for your 54 * chart, you should do this using the chart driver property, like: 55 * 56 * <code> 57 * $chart = new ezcGraphPieChart(); 58 * $chart->driver = new ezcGraphSvgDriver(); 59 * </code> 60 * 61 * @param ezcGraphDriver $driver Output driver 62 * @return void 63 */ 64 public function setDriver( ezcGraphDriver $driver ) 65 { 66 $this->driver = $driver; 67 } 68 69 /** 70 * Adds a element reference for context 71 * 72 * @param ezcGraphContext $context Dataoint context 73 * @param mixed $reference Driver dependant reference 74 * @return void 75 */ 76 protected function addElementReference( ezcGraphContext $context, $reference ) 77 { 78 $this->elements['data'][$context->dataset][$context->datapoint][] = $reference; 79 } 80 81 /** 82 * Return all chart element references 83 * 84 * Returns element references for the data sets in the chart, so the 85 * created graphic may be enhanced later. 86 * 87 * The resulting array looks like: 88 * <code> 89 * array ( 90 * legend_url => array ( 91 * $name => $url | null, 92 * ... 93 * ), 94 * legend => array ( 95 * $name => $data, 96 * ... 97 * ) 98 * data => array ( 99 * $dataset => array ( 100 * $name => $data, 101 * ... 102 * ), 103 * ... 104 * ) 105 * ) 106 * </code> 107 * 108 * The legend elements won't show up in the array, if there is no legend 109 * redered. The URLs are only available, if the url property has been set 110 * on the respective dataset. 111 * 112 * The data assigned to the legends and data elements is completely direver 113 * dependent. In the SVG and Flash driver there will jsut be some IDs, 114 * which allow you to reference the affected elements or element groups 115 * inside the flash or SVG file. 116 * 117 * For bitmap formats, like in the Cairo or GD driver, $data will be an 118 * array of ezcGraphCoordinate objects, which roughly describe the outline 119 * of the referenced element. For circles and alike the resolution of this 120 * outline can be configured in the respective driver. 121 * 122 * @return array 123 */ 124 public function getElementReferences() 125 { 126 return $this->elements; 127 } 128 129 /** 130 * __get 131 * 132 * @param string $propertyName 133 * @throws ezcBasePropertyNotFoundException 134 * If a the value for the property options is not an instance of 135 * @return mixed 136 * @ignore 137 */ 138 public function __get( $propertyName ) 139 { 140 switch ( $propertyName ) 141 { 142 case 'xAxisSpace': 143 case 'yAxisSpace': 144 return $this->$propertyName; 145 case 'elements': 146 return $this->elements; 147 default: 148 throw new ezcBasePropertyNotFoundException( $propertyName ); 149 } 150 } 151 152 /** 153 * Draw pie segment 154 * 155 * Draws a single pie segment 156 * 157 * @param ezcGraphBoundings $boundings Chart boundings 158 * @param ezcGraphContext $context Context of call 159 * @param ezcGraphColor $color Color of pie segment 160 * @param float $startAngle Start angle 161 * @param float $endAngle End angle 162 * @param mixed $label Label of pie segment 163 * @param bool $moveOut Move out from middle for hilighting 164 * @return void 165 */ 166 abstract public function drawPieSegment( 167 ezcGraphBoundings $boundings, 168 ezcGraphContext $context, 169 ezcGraphColor $color, 170 $startAngle = .0, 171 $endAngle = 360., 172 $label = false, 173 $moveOut = false 174 ); 175 176 /** 177 * Draw bar 178 * 179 * Draws a bar as a data element in a line chart 180 * 181 * @param ezcGraphBoundings $boundings Chart boundings 182 * @param ezcGraphContext $context Context of call 183 * @param ezcGraphColor $color Color of line 184 * @param ezcGraphCoordinate $position Position of data point 185 * @param float $stepSize Space which can be used for bars 186 * @param int $dataNumber Number of dataset 187 * @param int $dataCount Count of datasets in chart 188 * @param int $symbol Symbol to draw for line 189 * @param float $axisPosition Position of axis for drawing filled lines 190 * @return void 191 */ 192 abstract public function drawBar( 193 ezcGraphBoundings $boundings, 194 ezcGraphContext $context, 195 ezcGraphColor $color, 196 ezcGraphCoordinate $position, 197 $stepSize, 198 $dataNumber = 1, 199 $dataCount = 1, 200 $symbol = ezcGraph::NO_SYMBOL, 201 $axisPosition = 0. 202 ); 203 204 /** 205 * Draw data line 206 * 207 * Draws a line as a data element in a line chart 208 * 209 * @param ezcGraphBoundings $boundings Chart boundings 210 * @param ezcGraphContext $context Context of call 211 * @param ezcGraphColor $color Color of line 212 * @param ezcGraphCoordinate $start Starting point 213 * @param ezcGraphCoordinate $end Ending point 214 * @param int $dataNumber Number of dataset 215 * @param int $dataCount Count of datasets in chart 216 * @param int $symbol Symbol to draw for line 217 * @param ezcGraphColor $symbolColor Color of the symbol, defaults to linecolor 218 * @param ezcGraphColor $fillColor Color to fill line with 219 * @param float $axisPosition Position of axis for drawing filled lines 220 * @param float $thickness Line thickness 221 * @return void 222 */ 223 abstract public function drawDataLine( 224 ezcGraphBoundings $boundings, 225 ezcGraphContext $context, 226 ezcGraphColor $color, 227 ezcGraphCoordinate $start, 228 ezcGraphCoordinate $end, 229 $dataNumber = 1, 230 $dataCount = 1, 231 $symbol = ezcGraph::NO_SYMBOL, 232 ezcGraphColor $symbolColor = null, 233 ezcGraphColor $fillColor = null, 234 $axisPosition = 0., 235 $thickness = 1. 236 ); 237 238 /** 239 * Draws a highlight textbox for a datapoint. 240 * 241 * A highlight textbox for line and bar charts means a box with the current 242 * value in the graph. 243 * 244 * @param ezcGraphBoundings $boundings Chart boundings 245 * @param ezcGraphContext $context Context of call 246 * @param ezcGraphCoordinate $end Ending point 247 * @param float $axisPosition Position of axis for drawing filled lines 248 * @param int $dataNumber Number of dataset 249 * @param int $dataCount Count of datasets in chart 250 * @param ezcGraphFontOptions $font Font used for highlight string 251 * @param string $text Acutual value 252 * @param int $size Size of highlight text 253 * @param ezcGraphColor $markLines 254 * @param int $xOffset 255 * @param int $yOffset 256 * @param float $stepSize 257 * @param int $type 258 * @return void 259 */ 260 abstract public function drawDataHighlightText( 261 ezcGraphBoundings $boundings, 262 ezcGraphContext $context, 263 ezcGraphCoordinate $end, 264 $axisPosition = 0., 265 $dataNumber = 1, 266 $dataCount = 1, 267 ezcGraphFontOptions $font, 268 $text, 269 $size, 270 ezcGraphColor $markLines = null, 271 $xOffset = 0, 272 $yOffset = 0, 273 $stepSize = 0., 274 $type = ezcGraph::LINE 275 ); 276 277 /** 278 * Draw legend 279 * 280 * Will draw a legend in the bounding box 281 * 282 * @param ezcGraphBoundings $boundings Bounding of legend 283 * @param ezcGraphChartElementLegend $legend Legend to draw 284 * @param int $type Type of legend: Protrait or landscape 285 * @return void 286 */ 287 abstract public function drawLegend( 288 ezcGraphBoundings $boundings, 289 ezcGraphChartElementLegend $legend, 290 $type = ezcGraph::VERTICAL 291 ); 292 293 /** 294 * Draw box 295 * 296 * Box are wrapping each major chart element and draw border, background 297 * and title to each chart element. 298 * 299 * Optionally a padding and margin for each box can be defined. 300 * 301 * @param ezcGraphBoundings $boundings Boundings of the box 302 * @param ezcGraphColor $background Background color 303 * @param ezcGraphColor $borderColor Border color 304 * @param int $borderWidth Border width 305 * @param int $margin Margin 306 * @param int $padding Padding 307 * @param mixed $title Title of the box 308 * @param int $titleSize Size of title in the box 309 * @return ezcGraphBoundings Remaining inner boundings 310 */ 311 abstract public function drawBox( 312 ezcGraphBoundings $boundings, 313 ezcGraphColor $background = null, 314 ezcGraphColor $borderColor = null, 315 $borderWidth = 0, 316 $margin = 0, 317 $padding = 0, 318 $title = false, 319 $titleSize = 16 320 ); 321 322 /** 323 * Draw text 324 * 325 * Draws the provided text in the boundings 326 * 327 * @param ezcGraphBoundings $boundings Boundings of text 328 * @param string $text Text 329 * @param int $align Alignement of text 330 * @param ezcGraphRotation $rotation 331 * @return void 332 */ 333 abstract public function drawText( 334 ezcGraphBoundings $boundings, 335 $text, 336 $align = ezcGraph::LEFT, 337 ezcGraphRotation $rotation = null 338 ); 339 340 /** 341 * Draw axis 342 * 343 * Draws an axis form the provided start point to the end point. A specific 344 * angle of the axis is not required. 345 * 346 * For the labeleing of the axis a sorted array with major steps and an 347 * array with minor steps is expected, which are build like this: 348 * array( 349 * array( 350 * 'position' => (float), 351 * 'label' => (string), 352 * ) 353 * ) 354 * where the label is optional. 355 * 356 * The label renderer class defines how the labels are rendered. For more 357 * documentation on this topic have a look at the basic label renderer 358 * class. 359 * 360 * Additionally it can be specified if a major and minor grid are rendered 361 * by defining a color for them. The axis label is used to add a caption 362 * for the axis. 363 * 364 * @param ezcGraphBoundings $boundings Boundings of axis 365 * @param ezcGraphCoordinate $start Start point of axis 366 * @param ezcGraphCoordinate $end Endpoint of axis 367 * @param ezcGraphChartElementAxis $axis Axis to render 368 * @param ezcGraphAxisLabelRenderer $labelClass Used label renderer 369 * @return void 370 */ 371 abstract public function drawAxis( 372 ezcGraphBoundings $boundings, 373 ezcGraphCoordinate $start, 374 ezcGraphCoordinate $end, 375 ezcGraphChartElementAxis $axis, 376 ezcGraphAxisLabelRenderer $labelClass = null 377 ); 378 379 /** 380 * Draw axis arrow head 381 * 382 * Draw an arrow head at the specified position using specified size 383 * and direction of the error head. Repsects the axisEndStyle option in 384 * the base renderer options class. 385 * 386 * @param ezcGraphCoordinate $position 387 * @param ezcGraphVector $direction 388 * @param float $size 389 * @param ezcGraphColor $color 390 * @return void 391 */ 392 protected function drawAxisArrowHead( ezcGraphCoordinate $position, ezcGraphVector $direction, $size, ezcGraphColor $color ) 393 { 394 $orthogonalDirection = clone $direction; 395 $orthogonalDirection->rotateClockwise(); 396 397 if ( $this->options->axisEndStyle === ezcGraph::ARROW ) 398 { 399 $this->driver->drawPolygon( 400 array( 401 new ezcGraphCoordinate( 402 $position->x, 403 $position->y 404 ), 405 new ezcGraphCoordinate( 406 $position->x 407 - $orthogonalDirection->x * $size / 2 408 + $direction->x * $size, 409 $position->y 410 - $orthogonalDirection->y * $size / 2 411 + $direction->y * $size 412 ), 413 new ezcGraphCoordinate( 414 $position->x 415 + $orthogonalDirection->x * $size / 2 416 + $direction->x * $size, 417 $position->y 418 + $orthogonalDirection->y * $size / 2 419 + $direction->y * $size 420 ), 421 ), 422 $color, 423 true 424 ); 425 } 426 elseif ( $this->options->axisEndStyle !== ezcGraph::NO_SYMBOL ) 427 { 428 $topLeft = new ezcGraphCoordinate( 429 $position->x 430 + $orthogonalDirection->x * $size / 2 431 + $direction->x * $size, 432 $position->y 433 + $orthogonalDirection->y * $size / 2 434 + $direction->y * $size 435 ); 436 437 $bottomRight = new ezcGraphCoordinate( 438 $position->x 439 - $orthogonalDirection->x * $size / 2, 440 $position->y 441 - $orthogonalDirection->y * $size / 2 442 ); 443 444 $this->drawSymbol( 445 $boundings = new ezcGraphBoundings( 446 min( $topLeft->x, $bottomRight->x ), 447 min( $topLeft->y, $bottomRight->y ), 448 max( $topLeft->x, $bottomRight->x ), 449 max( $topLeft->y, $bottomRight->y ) 450 ), 451 $color, 452 $this->options->axisEndStyle 453 ); 454 } 455 } 456 457 /** 458 * Draw background image 459 * 460 * Draws a background image at the defined position. If repeat is set the 461 * background image will be repeated like any texture. 462 * 463 * @param ezcGraphBoundings $boundings Boundings for the background image 464 * @param string $file Filename of background image 465 * @param int $position Position of background image 466 * @param int $repeat Type of repetition 467 * @return void 468 */ 469 abstract public function drawBackgroundImage( 470 ezcGraphBoundings $boundings, 471 $file, 472 $position = 48, // ezcGraph::CENTER | ezcGraph::MIDDLE 473 $repeat = ezcGraph::NO_REPEAT 474 ); 475 476 /** 477 * Draw Symbol 478 * 479 * Draws a single symbol defined by the symbol constants in ezcGraph. for 480 * NO_SYMBOL a rect will be drawn. 481 * 482 * @param ezcGraphBoundings $boundings Boundings of symbol 483 * @param ezcGraphColor $color Color of symbol 484 * @param int $symbol Type of symbol 485 * @return void 486 */ 487 public function drawSymbol( 488 ezcGraphBoundings $boundings, 489 ezcGraphColor $color, 490 $symbol = ezcGraph::NO_SYMBOL ) 491 { 492 switch ( $symbol ) 493 { 494 case ezcGraph::NO_SYMBOL: 495 case ezcGraph::SQUARE: 496 $return = $this->driver->drawPolygon( 497 array( 498 new ezcGraphCoordinate( $boundings->x0, $boundings->y0 ), 499 new ezcGraphCoordinate( $boundings->x1, $boundings->y0 ), 500 new ezcGraphCoordinate( $boundings->x1, $boundings->y1 ), 501 new ezcGraphCoordinate( $boundings->x0, $boundings->y1 ), 502 ), 503 $color, 504 true 505 ); 506 507 // Draw optional gleam 508 if ( $this->options->legendSymbolGleam !== false ) 509 { 510 $return = $this->driver->drawPolygon( 511 array( 512 $topLeft = new ezcGraphCoordinate( 513 $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $this->options->legendSymbolGleamSize, 514 $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $this->options->legendSymbolGleamSize 515 ), 516 new ezcGraphCoordinate( 517 $boundings->x1 - ( $boundings->x1 - $boundings->x0 ) * $this->options->legendSymbolGleamSize, 518 $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $this->options->legendSymbolGleamSize 519 ), 520 $bottomRight = new ezcGraphCoordinate( 521 $boundings->x1 - ( $boundings->x1 - $boundings->x0 ) * $this->options->legendSymbolGleamSize, 522 $boundings->y1 - ( $boundings->y1 - $boundings->y0 ) * $this->options->legendSymbolGleamSize 523 ), 524 new ezcGraphCoordinate( 525 $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $this->options->legendSymbolGleamSize, 526 $boundings->y1 - ( $boundings->y1 - $boundings->y0 ) * $this->options->legendSymbolGleamSize 527 ), 528 ), 529 new ezcGraphLinearGradient( 530 $bottomRight, 531 $topLeft, 532 $color->darken( -$this->options->legendSymbolGleam ), 533 $color->darken( $this->options->legendSymbolGleam ) 534 ), 535 true 536 ); 537 } 538 return $return; 539 case ezcGraph::BOX: 540 $return = $this->driver->drawPolygon( 541 array( 542 new ezcGraphCoordinate( $boundings->x0, $boundings->y0 ), 543 new ezcGraphCoordinate( $boundings->x1, $boundings->y0 ), 544 new ezcGraphCoordinate( $boundings->x1, $boundings->y1 ), 545 new ezcGraphCoordinate( $boundings->x0, $boundings->y1 ), 546 ), 547 $color, 548 false 549 ); 550 return $return; 551 case ezcGraph::DIAMOND: 552 $return = $this->driver->drawPolygon( 553 array( 554 new ezcGraphCoordinate( 555 $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) / 2, 556 $boundings->y0 557 ), 558 new ezcGraphCoordinate( 559 $boundings->x1, 560 $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) / 2 561 ), 562 new ezcGraphCoordinate( 563 $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) / 2, 564 $boundings->y1 565 ), 566 new ezcGraphCoordinate( 567 $boundings->x0, 568 $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) / 2 569 ), 570 ), 571 $color, 572 true 573 ); 574 575 // Draw optional gleam 576 if ( $this->options->legendSymbolGleam !== false ) 577 { 578 $return = $this->driver->drawPolygon( 579 array( 580 new ezcGraphCoordinate( 581 $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) / 2, 582 $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $this->options->legendSymbolGleamSize 583 ), 584 new ezcGraphCoordinate( 585 $boundings->x1 - ( $boundings->x1 - $boundings->x0 ) * $this->options->legendSymbolGleamSize, 586 $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) / 2 587 ), 588 new ezcGraphCoordinate( 589 $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) / 2, 590 $boundings->y1 - ( $boundings->y1 - $boundings->y0 ) * $this->options->legendSymbolGleamSize 591 ), 592 new ezcGraphCoordinate( 593 $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $this->options->legendSymbolGleamSize, 594 $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) / 2 595 ), 596 ), 597 new ezcGraphLinearGradient( 598 new ezcGraphCoordinate( 599 $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * 0.353553391, 600 $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * 0.353553391 601 ), 602 new ezcGraphCoordinate( 603 $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * ( 1 - 0.353553391 ), 604 $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * ( 1 - 0.353553391 ) 605 ), 606 $color->darken( -$this->options->legendSymbolGleam ), 607 $color->darken( $this->options->legendSymbolGleam ) 608 ), 609 true 610 ); 611 } 612 return $return; 613 case ezcGraph::BULLET: 614 $return = $this->driver->drawCircle( 615 new ezcGraphCoordinate( 616 $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) / 2, 617 $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) / 2 618 ), 619 $boundings->x1 - $boundings->x0, 620 $boundings->y1 - $boundings->y0, 621 $color, 622 true 623 ); 624 625 // Draw optional gleam 626 if ( $this->options->legendSymbolGleam !== false ) 627 { 628 $return = $this->driver->drawCircle( 629 new ezcGraphCoordinate( 630 $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) / 2, 631 $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) / 2 632 ), 633 ( $boundings->x1 - $boundings->x0 ) * $this->options->legendSymbolGleamSize, 634 ( $boundings->y1 - $boundings->y0 ) * $this->options->legendSymbolGleamSize, 635 new ezcGraphLinearGradient( 636 new ezcGraphCoordinate( 637 $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * 0.292893219, 638 $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * 0.292893219 639 ), 640 new ezcGraphCoordinate( 641 $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * 0.707106781, 642 $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * 0.707106781 643 ), 644 $color->darken( -$this->options->legendSymbolGleam ), 645 $color->darken( $this->options->legendSymbolGleam ) 646 ), 647 true 648 ); 649 } 650 return $return; 651 case ezcGraph::CIRCLE: 652 return $this->driver->drawCircle( 653 new ezcGraphCoordinate( 654 $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) / 2, 655 $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) / 2 656 ), 657 $boundings->x1 - $boundings->x0, 658 $boundings->y1 - $boundings->y0, 659 $color, 660 false 661 ); 662 } 663 } 664 665 /** 666 * Finish rendering 667 * 668 * Method is called before the final image is renderer, so that finishing 669 * operations can be performed here. 670 * 671 * @return void 672 */ 673 abstract protected function finish(); 674 675 /** 676 * Reset renderer properties 677 * 678 * Reset all renderer properties, which were calculated during the 679 * rendering process, to offer a clean environment for rerendering. 680 * 681 * @return void 682 */ 683 protected function resetRenderer() 684 { 685 $this->xAxisSpace = false; 686 $this->yAxisSpace = false; 687 688 // Reset driver, maintaining its configuration 689 $driverClass = get_class( $this->driver ); 690 $driverOptions = $this->driver->options; 691 $this->driver = new $driverClass(); 692 $this->driver->options = $driverOptions; 693 } 694 695 /** 696 * Finally renders the image 697 * 698 * @param string $file Filename of destination file 699 * @return void 700 */ 701 public function render( $file = null ) 702 { 703 $this->finish(); 704 705 if ( $file === null ) 706 { 707 $this->driver->renderToOutput(); 708 } 709 else 710 { 711 $this->driver->render( $file ); 712 } 713 714 $this->resetRenderer(); 715 } 716 } 717 ?>
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 |