[ Index ] |
|
Code source de Cr@wltr@ck 2.2.1 |
1 <?php 2 /* 3 * This work is hereby released into the Public Domain. 4 * To view a copy of the public domain dedication, 5 * visit http://creativecommons.org/licenses/publicdomain/ or send a letter to 6 * Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA. 7 * 8 */ 9 10 require_once dirname(__FILE__)."/Plot.class.php"; 11 12 /* <php4> */ 13 14 define("LINEPLOT_LINE", 0); 15 define("LINEPLOT_MIDDLE", 1); 16 17 /* </php4> */ 18 19 /** 20 * LinePlot 21 * 22 * @package Artichow 23 */ 24 class awLinePlot extends awPlot { 25 26 /** 27 * Add marks to your line plot 28 * 29 * @var Mark 30 */ 31 var $mark; 32 33 /** 34 * Labels on your line plot 35 * 36 * @var Label 37 */ 38 var $label; 39 40 /** 41 * Filled areas 42 * 43 * @var bool 44 */ 45 var $areas = array(); 46 47 /** 48 * Is the line hidden 49 * 50 * @var bool 51 */ 52 var $lineHide = FALSE; 53 54 /** 55 * Line color 56 * 57 * @var Color 58 */ 59 var $lineColor; 60 61 /** 62 * Line mode 63 * 64 * @var int 65 */ 66 var $lineMode = LINEPLOT_LINE; 67 68 /** 69 * Line type 70 * 71 * @var int 72 */ 73 var $lineStyle = LINE_SOLID; 74 75 /** 76 * Line thickness 77 * 78 * @var int 79 */ 80 var $lineThickness = 1; 81 82 /** 83 * Line background 84 * 85 * @var Color, Gradient 86 */ 87 var $lineBackground; 88 89 /** 90 * Line mode 91 * 92 * @var int 93 */ 94 95 96 /** 97 * Line in the middle 98 * 99 * @var int 100 */ 101 102 103 /** 104 * Construct a new awLinePlot 105 * 106 * @param array $values Some numeric values for Y axis 107 * @param int $mode 108 */ 109 function awLinePlot($values, $mode = LINEPLOT_LINE) { 110 111 parent::awPlot(); 112 113 $this->mark = new awMark; 114 $this->label = new awLabel; 115 116 $this->lineMode = (int)$mode; 117 118 $this->setValues($values); 119 120 } 121 122 /** 123 * Hide line 124 * 125 * @param bool $hide 126 */ 127 function hideLine($hide) { 128 $this->lineHide = (bool)$hide; 129 } 130 131 /** 132 * Add a filled area 133 * 134 * @param int $start Begining of the area 135 * @param int $end End of the area 136 * @param mixed $background Background color or gradient of the area 137 */ 138 function setFilledArea($start, $stop, $background) { 139 140 if($stop <= $start) { 141 awImage::drawError("Class LinePlot: End position can not be greater than begin position in setFilledArea()."); 142 } 143 144 $this->areas[] = array((int)$start, (int)$stop, $background); 145 146 } 147 148 /** 149 * Change line color 150 * 151 * @param $color 152 */ 153 function setColor($color) { 154 $this->lineColor = $color; 155 } 156 157 /** 158 * Change line style 159 * 160 * @param int $style 161 */ 162 function setStyle($style) { 163 $this->lineStyle = (int)$style; 164 } 165 166 /** 167 * Change line tickness 168 * 169 * @param int $tickness 170 */ 171 function setThickness($tickness) { 172 $this->lineThickness = (int)$tickness; 173 } 174 175 /** 176 * Change line background color 177 * 178 * @param $color 179 */ 180 function setFillColor($color) { 181 $this->lineBackground = $color; 182 } 183 184 /** 185 * Change line background gradient 186 * 187 * @param $gradient 188 */ 189 function setFillGradient($gradient) { 190 $this->lineBackground = $gradient; 191 } 192 193 /** 194 * Get the line thickness 195 * 196 * @return int 197 */ 198 function getLegendLineThickness() { 199 return $this->lineThickness; 200 } 201 202 /** 203 * Get the line type 204 * 205 * @return int 206 */ 207 function getLegendLineStyle() { 208 return $this->lineStyle; 209 } 210 211 /** 212 * Get the color of line 213 * 214 * @return Color 215 */ 216 function getLegendLineColor() { 217 return $this->lineColor; 218 } 219 220 /** 221 * Get the background color or gradient of an element of the component 222 * 223 * @return Color, Gradient 224 */ 225 function getLegendBackground() { 226 return $this->lineBackground; 227 } 228 229 /** 230 * Get a mark object 231 * 232 * @return Mark 233 */ 234 function getLegendMark() { 235 return $this->mark; 236 } 237 238 function drawComponent($drawer, $x1, $y1, $x2, $y2, $aliasing) { 239 240 $max = $this->getRealYMax(); 241 $min = $this->getRealYMin(); 242 243 // Get start and stop values 244 list($start, $stop) = $this->getLimit(); 245 246 if($this->lineMode === LINEPLOT_MIDDLE) { 247 $inc = $this->xAxis->getDistance(0, 1) / 2; 248 } else { 249 $inc = 0; 250 } 251 252 // Build the polygon 253 $polygon = new awPolygon; 254 255 for($key = $start; $key <= $stop; $key++) { 256 257 $value = $this->datay[$key]; 258 259 if($value !== NULL) { 260 261 $p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($key, $value)); 262 $p = $p->move($inc, 0); 263 $polygon->set($key, $p); 264 265 } 266 267 } 268 269 // Draw backgrounds 270 if(is_a($this->lineBackground, 'awColor') or is_a($this->lineBackground, 'awGradient')) { 271 272 $backgroundPolygon = new awPolygon; 273 274 $p = $this->xAxisPoint($start); 275 $p = $p->move($inc, 0); 276 $backgroundPolygon->append($p); 277 278 // Add others points 279 foreach($polygon->all() as $point) { 280 $backgroundPolygon->append($point); 281 } 282 283 $p = $this->xAxisPoint($stop); 284 $p = $p->move($inc, 0); 285 $backgroundPolygon->append($p); 286 287 // Draw polygon background 288 $drawer->filledPolygon($this->lineBackground, $backgroundPolygon); 289 290 } 291 292 $this->drawArea($drawer, $polygon); 293 294 // Draw line 295 $prev = NULL; 296 297 // Line color 298 if($this->lineHide === FALSE) { 299 300 if($this->lineColor === NULL) { 301 $this->lineColor = new awColor(0, 0, 0); 302 } 303 304 foreach($polygon->all() as $point) { 305 306 if($prev !== NULL) { 307 $drawer->line( 308 $this->lineColor, 309 new awLine( 310 $prev, 311 $point, 312 $this->lineStyle, 313 $this->lineThickness 314 ) 315 ); 316 } 317 $prev = $point; 318 319 } 320 321 $this->lineColor->free(); 322 323 } 324 325 // Draw marks and labels 326 foreach($polygon->all() as $key => $point) { 327 328 $this->mark->draw($drawer, $point); 329 $this->label->draw($drawer, $point, $key); 330 331 } 332 333 } 334 335 function drawArea($drawer, &$polygon) { 336 337 $starts = array(); 338 foreach($this->areas as $area) { 339 list($start) = $area; 340 $starts[$start] = TRUE; 341 } 342 343 // Draw filled areas 344 foreach($this->areas as $area) { 345 346 list($start, $stop, $background) = $area; 347 348 $polygonArea = new awPolygon; 349 350 $p = $this->xAxisPoint($start); 351 $polygonArea->append($p); 352 353 for($i = $start; $i <= $stop; $i++) { 354 $p = $polygon->get($i); 355 if($i === $stop and array_key_exists($stop, $starts)) { 356 $p = $p->move(-1, 0); 357 } 358 $polygonArea->append($p); 359 } 360 361 $p = $this->xAxisPoint($stop); 362 if(array_key_exists($stop, $starts)) { 363 $p = $p->move(-1, 0); 364 } 365 $polygonArea->append($p); 366 367 // Draw area 368 $drawer->filledPolygon($background, $polygonArea); 369 370 } 371 372 } 373 374 function getXAxisNumber() { 375 if($this->lineMode === LINEPLOT_MIDDLE) { 376 return count($this->datay) + 1; 377 } else { 378 return count($this->datay); 379 } 380 } 381 382 function xAxisPoint($position) { 383 $y = $this->xAxisZero ? 0 : $this->getRealYMin(); 384 return awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($position, $y)); 385 } 386 387 function getXCenter() { 388 return ($this->lineMode === LINEPLOT_MIDDLE); 389 } 390 391 } 392 393 registerClass('LinePlot'); 394 395 396 /** 397 * Simple LinePlot 398 * Useful to draw simple horizontal lines 399 * 400 * @package Artichow 401 */ 402 class awSimpleLinePlot extends awPlot { 403 404 /** 405 * Line color 406 * 407 * @var Color 408 */ 409 var $lineColor; 410 411 /** 412 * Line start 413 * 414 * @var int 415 */ 416 var $lineStart; 417 418 /** 419 * Line stop 420 * 421 * @var int 422 */ 423 var $lineStop; 424 425 /** 426 * Line value 427 * 428 * @var flaot 429 */ 430 var $lineValue; 431 432 /** 433 * Line mode 434 * 435 * @var int 436 */ 437 var $lineMode = LINEPLOT_LINE; 438 439 /** 440 * Line type 441 * 442 * @var int 443 */ 444 var $lineStyle = LINE_SOLID; 445 446 /** 447 * Line thickness 448 * 449 * @var int 450 */ 451 var $lineThickness = 1; 452 453 /** 454 * Line mode 455 * 456 * @var int 457 */ 458 459 460 /** 461 * Line in the middle 462 * 463 * @var int 464 */ 465 466 467 /** 468 * Construct a new awLinePlot 469 * 470 * @param float $value A Y value 471 * @param int $start Line start index 472 * @param int $stop Line stop index 473 * @param int $mode Line mode 474 */ 475 function awSimpleLinePlot($value, $start, $stop, $mode = LINEPLOT_LINE) { 476 477 parent::awPlot(); 478 479 $this->lineMode = (int)$mode; 480 481 $this->lineStart = (int)$start; 482 $this->lineStop = (int)$stop; 483 $this->lineValue = (float)$value; 484 485 $this->lineColor = new awColor(0, 0, 0); 486 487 } 488 489 /** 490 * Change line color 491 * 492 * @param $color 493 */ 494 function setColor($color) { 495 $this->lineColor = $color; 496 } 497 498 /** 499 * Change line style 500 * 501 * @param int $style 502 */ 503 function setStyle($style) { 504 $this->lineStyle = (int)$style; 505 } 506 507 /** 508 * Change line tickness 509 * 510 * @param int $tickness 511 */ 512 function setThickness($tickness) { 513 $this->lineThickness = (int)$tickness; 514 } 515 516 /** 517 * Get the line thickness 518 * 519 * @return int 520 */ 521 function getLegendLineThickness() { 522 return $this->lineThickness; 523 } 524 525 /** 526 * Get the line type 527 * 528 * @return int 529 */ 530 function getLegendLineStyle() { 531 return $this->lineStyle; 532 } 533 534 /** 535 * Get the color of line 536 * 537 * @return Color 538 */ 539 function getLegendLineColor() { 540 return $this->lineColor; 541 } 542 543 function getLegendBackground() { 544 return NULL; 545 } 546 547 function getLegendMark() { 548 return NULL; 549 } 550 551 function drawComponent($drawer, $x1, $y1, $x2, $y2, $aliasing) { 552 553 if($this->lineMode === LINEPLOT_MIDDLE) { 554 $inc = $this->xAxis->getDistance(0, 1) / 2; 555 } else { 556 $inc = 0; 557 } 558 559 $p1 = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($this->lineStart, $this->lineValue)); 560 $p2 = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($this->lineStop, $this->lineValue)); 561 562 $drawer->line( 563 $this->lineColor, 564 new awLine( 565 $p1->move($inc, 0), 566 $p2->move($inc, 0), 567 $this->lineStyle, 568 $this->lineThickness 569 ) 570 ); 571 572 $this->lineColor->free(); 573 574 } 575 576 function getXAxisNumber() { 577 if($this->lineMode === LINEPLOT_MIDDLE) { 578 return count($this->datay) + 1; 579 } else { 580 return count($this->datay); 581 } 582 } 583 584 function xAxisPoint($position) { 585 $y = $this->xAxisZero ? 0 : $this->getRealYMin(); 586 return awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($position, $y)); 587 } 588 589 function getXCenter() { 590 return ($this->lineMode === LINEPLOT_MIDDLE); 591 } 592 593 } 594 595 registerClass('SimpleLinePlot'); 596 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Thu Sep 6 14:14:11 2007 | par Balluche grâce à PHPXref 0.7 |