| Conditions | 55 |
| Paths | > 20000 |
| Total Lines | 372 |
| Code Lines | 264 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 393 | public function Stroke($img, $xscale, $yscale) |
||
| 394 | { |
||
| 395 | $numpoints = safe_count($this->coords[0]); |
||
| 396 | if (isset($this->coords[1])) { |
||
| 397 | if (safe_count($this->coords[1]) != $numpoints) { |
||
| 398 | Util\JpGraphError::RaiseL(2003, safe_count($this->coords[1]), $numpoints); |
||
| 399 | //"Number of X and Y points are not equal. Number of X-points:". safe_count($this->coords[1])."Number of Y-points:$numpoints"); |
||
| 400 | } else { |
||
| 401 | $exist_x = true; |
||
| 402 | } |
||
| 403 | } else { |
||
| 404 | $exist_x = false; |
||
| 405 | } |
||
| 406 | |||
| 407 | $numbars = safe_count($this->coords[0]); |
||
| 408 | |||
| 409 | // Use GetMinVal() instead of scale[0] directly since in the case |
||
| 410 | // of log scale we get a correct value. Log scales will have negative |
||
| 411 | // values for values < 1 while still not representing negative numbers. |
||
| 412 | if ($yscale->GetMinVal() >= 0) { |
||
| 413 | $zp = $yscale->scale_abs[0]; |
||
| 414 | } else { |
||
| 415 | $zp = $yscale->Translate(0); |
||
| 416 | } |
||
| 417 | |||
| 418 | if ($this->abswidth > -1) { |
||
| 419 | $abswidth = $this->abswidth; |
||
| 420 | } else { |
||
| 421 | $abswidth = round($this->width * $xscale->scale_factor, 0); |
||
| 422 | } |
||
| 423 | |||
| 424 | // Count pontetial pattern array to avoid doing the count for each iteration |
||
| 425 | if (is_array($this->iPattern)) { |
||
| 426 | $np = safe_count($this->iPattern); |
||
| 427 | } |
||
| 428 | |||
| 429 | $grad = null; |
||
| 430 | for ($i = 0; $i < $numbars; ++$i) { |
||
| 431 | // If value is NULL, or 0 then don't draw a bar at all |
||
| 432 | if ($this->coords[0][$i] === null || $this->coords[0][$i] === '') { |
||
| 433 | continue; |
||
| 434 | } |
||
| 435 | |||
| 436 | if ($exist_x) { |
||
| 437 | $x = $this->coords[1][$i]; |
||
| 438 | } else { |
||
| 439 | $x = $i; |
||
| 440 | } |
||
| 441 | |||
| 442 | $x = $xscale->Translate($x); |
||
| 443 | |||
| 444 | // Comment Note: This confuses the positioning when using acc together with |
||
| 445 | // grouped bars. Workaround for fixing #191 |
||
| 446 | /* |
||
| 447 | if( !$xscale->textscale ) { |
||
| 448 | if($this->align=="center") |
||
| 449 | $x -= $abswidth/2; |
||
| 450 | elseif($this->align=="right") |
||
| 451 | $x -= $abswidth; |
||
| 452 | } |
||
| 453 | */ |
||
| 454 | // Stroke fill color and fill gradient |
||
| 455 | $pts = [ |
||
| 456 | $x, $zp, |
||
| 457 | $x, $yscale->Translate($this->coords[0][$i]), |
||
| 458 | $x + $abswidth, $yscale->Translate($this->coords[0][$i]), |
||
| 459 | $x + $abswidth, $zp, ]; |
||
| 460 | if ($this->grad) { |
||
| 461 | if ($grad === null) { |
||
| 462 | $grad = new Gradient($img); |
||
| 463 | } |
||
| 464 | if (is_array($this->grad_fromcolor)) { |
||
| 465 | // The first argument (grad_fromcolor) can be either an array or a single color. If it is an array |
||
| 466 | // then we have two choices. It can either a) be a single color specified as an Image\RGB triple or it can be |
||
| 467 | // an array to specify both (from, to style) for each individual bar. The way to know the difference is |
||
| 468 | // to investgate the first element. If this element is an integer [0,255] then we assume it is an Image\RGB |
||
| 469 | // triple. |
||
| 470 | $ng = safe_count($this->grad_fromcolor); |
||
| 471 | if ($ng === 3) { |
||
| 472 | if (is_numeric($this->grad_fromcolor[0]) && $this->grad_fromcolor[0] > 0 && $this->grad_fromcolor[0] < 256) { |
||
| 473 | // Image\RGB Triple |
||
| 474 | $fromcolor = $this->grad_fromcolor; |
||
| 475 | $tocolor = $this->grad_tocolor; |
||
| 476 | $style = $this->grad_style; |
||
| 477 | } else { |
||
| 478 | $fromcolor = $this->grad_fromcolor[$i % $ng][0]; |
||
| 479 | $tocolor = $this->grad_fromcolor[$i % $ng][1]; |
||
| 480 | $style = $this->grad_fromcolor[$i % $ng][2]; |
||
| 481 | } |
||
| 482 | } else { |
||
| 483 | $fromcolor = $this->grad_fromcolor[$i % $ng][0]; |
||
| 484 | $tocolor = $this->grad_fromcolor[$i % $ng][1]; |
||
| 485 | $style = $this->grad_fromcolor[$i % $ng][2]; |
||
| 486 | } |
||
| 487 | $grad->FilledRectangle( |
||
| 488 | $pts[2], |
||
| 489 | $pts[3], |
||
| 490 | $pts[6], |
||
| 491 | $pts[7], |
||
| 492 | $fromcolor, |
||
| 493 | $tocolor, |
||
| 494 | $style |
||
| 495 | ); |
||
| 496 | } else { |
||
| 497 | $grad->FilledRectangle( |
||
| 498 | $pts[2], |
||
| 499 | $pts[3], |
||
| 500 | $pts[6], |
||
| 501 | $pts[7], |
||
| 502 | $this->grad_fromcolor, |
||
| 503 | $this->grad_tocolor, |
||
| 504 | $this->grad_style |
||
| 505 | ); |
||
| 506 | } |
||
| 507 | } elseif (!empty($this->fill_color)) { |
||
| 508 | if (is_array($this->fill_color)) { |
||
| 509 | $img->PushColor($this->fill_color[$i % safe_count($this->fill_color)]); |
||
| 510 | } else { |
||
| 511 | $img->PushColor($this->fill_color); |
||
| 512 | } |
||
| 513 | $img->FilledPolygon($pts); |
||
| 514 | $img->PopColor(); |
||
| 515 | } |
||
| 516 | |||
| 517 | /////////////////////////kokorahen rectangle polygon////////////////////// |
||
| 518 | |||
| 519 | // Remember value of this bar |
||
| 520 | $val = $this->coords[0][$i]; |
||
| 521 | |||
| 522 | if (!empty($val) && !is_numeric($val)) { |
||
| 523 | Util\JpGraphError::RaiseL(2004, $i, $val); |
||
| 524 | //'All values for a barplot must be numeric. You have specified value['.$i.'] == \''.$val.'\''); |
||
| 525 | } |
||
| 526 | |||
| 527 | // Determine the shadow |
||
| 528 | if ($this->bar_shadow && $val != 0) { |
||
| 529 | $ssh = $this->bar_shadow_hsize; |
||
| 530 | $ssv = $this->bar_shadow_vsize; |
||
| 531 | // Create points to create a "upper-right" shadow |
||
| 532 | if ($val > 0) { |
||
| 533 | $sp[0] = $pts[6]; |
||
| 534 | $sp[1] = $pts[7]; |
||
| 535 | $sp[2] = $pts[4]; |
||
| 536 | $sp[3] = $pts[5]; |
||
| 537 | $sp[4] = $pts[2]; |
||
| 538 | $sp[5] = $pts[3]; |
||
| 539 | $sp[6] = $pts[2] + $ssh; |
||
| 540 | $sp[7] = $pts[3] - $ssv; |
||
| 541 | $sp[8] = $pts[4] + $ssh; |
||
| 542 | $sp[9] = $pts[5] - $ssv; |
||
| 543 | $sp[10] = $pts[6] + $ssh; |
||
| 544 | $sp[11] = $pts[7] - $ssv; |
||
| 545 | } elseif ($val < 0) { |
||
| 546 | $sp[0] = $pts[4]; |
||
| 547 | $sp[1] = $pts[5]; |
||
| 548 | $sp[2] = $pts[6]; |
||
| 549 | $sp[3] = $pts[7]; |
||
| 550 | $sp[4] = $pts[0]; |
||
| 551 | $sp[5] = $pts[1]; |
||
| 552 | $sp[6] = $pts[0] + $ssh; |
||
| 553 | $sp[7] = $pts[1] - $ssv; |
||
| 554 | $sp[8] = $pts[6] + $ssh; |
||
| 555 | $sp[9] = $pts[7] - $ssv; |
||
| 556 | $sp[10] = $pts[4] + $ssh; |
||
| 557 | $sp[11] = $pts[5] - $ssv; |
||
| 558 | } |
||
| 559 | if (is_array($this->bar_shadow_color)) { |
||
| 560 | $numcolors = safe_count($this->bar_shadow_color); |
||
| 561 | if ($numcolors == 0) { |
||
| 562 | Util\JpGraphError::RaiseL(2005); //('You have specified an empty array for shadow colors in the bar plot.'); |
||
| 563 | } |
||
| 564 | $img->PushColor($this->bar_shadow_color[$i % $numcolors]); |
||
| 565 | } else { |
||
| 566 | $img->PushColor($this->bar_shadow_color); |
||
| 567 | } |
||
| 568 | $img->FilledPolygon($sp); |
||
| 569 | $img->PopColor(); |
||
| 570 | } elseif ($this->bar_3d && $val != 0) { |
||
| 571 | // Determine the 3D |
||
| 572 | |||
| 573 | $ssh = $this->bar_3d_hsize; |
||
| 574 | $ssv = $this->bar_3d_vsize; |
||
| 575 | |||
| 576 | // Create points to create a "upper-right" shadow |
||
| 577 | if ($val > 0) { |
||
| 578 | $sp1[0] = $pts[6]; |
||
| 579 | $sp1[1] = $pts[7]; |
||
| 580 | $sp1[2] = $pts[4]; |
||
| 581 | $sp1[3] = $pts[5]; |
||
| 582 | $sp1[4] = $pts[4] + $ssh; |
||
| 583 | $sp1[5] = $pts[5] - $ssv; |
||
| 584 | $sp1[6] = $pts[6] + $ssh; |
||
| 585 | $sp1[7] = $pts[7] - $ssv; |
||
| 586 | |||
| 587 | $sp2[0] = $pts[4]; |
||
| 588 | $sp2[1] = $pts[5]; |
||
| 589 | $sp2[2] = $pts[2]; |
||
| 590 | $sp2[3] = $pts[3]; |
||
| 591 | $sp2[4] = $pts[2] + $ssh; |
||
| 592 | $sp2[5] = $pts[3] - $ssv; |
||
| 593 | $sp2[6] = $pts[4] + $ssh; |
||
| 594 | $sp2[7] = $pts[5] - $ssv; |
||
| 595 | } elseif ($val < 0) { |
||
| 596 | $sp1[0] = $pts[4]; |
||
| 597 | $sp1[1] = $pts[5]; |
||
| 598 | $sp1[2] = $pts[6]; |
||
| 599 | $sp1[3] = $pts[7]; |
||
| 600 | $sp1[4] = $pts[6] + $ssh; |
||
| 601 | $sp1[5] = $pts[7] - $ssv; |
||
| 602 | $sp1[6] = $pts[4] + $ssh; |
||
| 603 | $sp1[7] = $pts[5] - $ssv; |
||
| 604 | |||
| 605 | $sp2[0] = $pts[6]; |
||
| 606 | $sp2[1] = $pts[7]; |
||
| 607 | $sp2[2] = $pts[0]; |
||
| 608 | $sp2[3] = $pts[1]; |
||
| 609 | $sp2[4] = $pts[0] + $ssh; |
||
| 610 | $sp2[5] = $pts[1] - $ssv; |
||
| 611 | $sp2[6] = $pts[6] + $ssh; |
||
| 612 | $sp2[7] = $pts[7] - $ssv; |
||
| 613 | } |
||
| 614 | |||
| 615 | $base_color = $this->fill_color; |
||
| 616 | |||
| 617 | $img->PushColor($base_color . ':0.7'); |
||
| 618 | $img->FilledPolygon($sp1); |
||
| 619 | $img->PopColor(); |
||
| 620 | |||
| 621 | $img->PushColor($base_color . ':1.1'); |
||
| 622 | $img->FilledPolygon($sp2); |
||
| 623 | $img->PopColor(); |
||
| 624 | } |
||
| 625 | |||
| 626 | // Stroke the pattern |
||
| 627 | if (is_array($this->iPattern)) { |
||
| 628 | $f = new Graph\RectPatternFactory(); |
||
| 629 | if (is_array($this->iPatternColor)) { |
||
| 630 | $pcolor = $this->iPatternColor[$i % $np]; |
||
| 631 | } else { |
||
| 632 | $pcolor = $this->iPatternColor; |
||
| 633 | } |
||
| 634 | $prect = $f->Create($this->iPattern[$i % $np], $pcolor, 1); |
||
| 635 | $prect->SetDensity($this->iPatternDensity[$i % $np]); |
||
| 636 | |||
| 637 | if ($val < 0) { |
||
| 638 | $rx = $pts[0]; |
||
| 639 | $ry = $pts[1]; |
||
| 640 | } else { |
||
| 641 | $rx = $pts[2]; |
||
| 642 | $ry = $pts[3]; |
||
| 643 | } |
||
| 644 | $width = abs($pts[4] - $pts[0]) + 1; |
||
| 645 | $height = abs($pts[1] - $pts[3]) + 1; |
||
| 646 | $prect->SetPos(new Util\Rectangle($rx, $ry, $width, $height)); |
||
| 647 | $prect->Stroke($img); |
||
| 648 | } else { |
||
| 649 | if ($this->iPattern > -1) { |
||
| 650 | $f = new Graph\RectPatternFactory(); |
||
| 651 | $prect = $f->Create($this->iPattern, $this->iPatternColor, 1); |
||
| 652 | $prect->SetDensity($this->iPatternDensity); |
||
| 653 | if ($val < 0) { |
||
| 654 | $rx = $pts[0]; |
||
| 655 | $ry = $pts[1]; |
||
| 656 | } else { |
||
| 657 | $rx = $pts[2]; |
||
| 658 | $ry = $pts[3]; |
||
| 659 | } |
||
| 660 | $width = abs($pts[4] - $pts[0]) + 1; |
||
| 661 | $height = abs($pts[1] - $pts[3]) + 1; |
||
| 662 | $prect->SetPos(new Util\Rectangle($rx, $ry, $width, $height)); |
||
| 663 | $prect->Stroke($img); |
||
| 664 | } |
||
| 665 | } |
||
| 666 | |||
| 667 | // Stroke the outline of the bar |
||
| 668 | if (is_array($this->color)) { |
||
| 669 | $img->SetColor($this->color[$i % safe_count($this->color)]); |
||
| 670 | } else { |
||
| 671 | $img->SetColor($this->color); |
||
| 672 | } |
||
| 673 | |||
| 674 | $pts[] = $pts[0]; |
||
| 675 | $pts[] = $pts[1]; |
||
| 676 | |||
| 677 | if ($this->weight > 0) { |
||
| 678 | $img->SetLineWeight($this->weight); |
||
| 679 | $img->Polygon($pts); |
||
| 680 | } |
||
| 681 | |||
| 682 | // Determine how to best position the values of the individual bars |
||
| 683 | $x = $pts[2] + ($pts[4] - $pts[2]) / 2; |
||
| 684 | $this->value->SetMargin(5); |
||
| 685 | |||
| 686 | if ($this->valuepos == 'top') { |
||
| 687 | $y = $pts[3]; |
||
| 688 | if ($img->a === 90) { |
||
| 689 | if ($val < 0) { |
||
| 690 | $this->value->SetAlign('right', 'center'); |
||
| 691 | } else { |
||
| 692 | $this->value->SetAlign('left', 'center'); |
||
| 693 | } |
||
| 694 | } else { |
||
| 695 | if ($val < 0) { |
||
| 696 | $this->value->SetMargin(-5); |
||
| 697 | $y = $pts[1]; |
||
| 698 | $this->value->SetAlign('center', 'bottom'); |
||
| 699 | } else { |
||
| 700 | $this->value->SetAlign('center', 'bottom'); |
||
| 701 | } |
||
| 702 | } |
||
| 703 | $this->value->Stroke($img, $val, $x, $y); |
||
| 704 | } elseif ($this->valuepos == 'max') { |
||
| 705 | $y = $pts[3]; |
||
| 706 | if ($img->a === 90) { |
||
| 707 | if ($val < 0) { |
||
| 708 | $this->value->SetAlign('left', 'center'); |
||
| 709 | } else { |
||
| 710 | $this->value->SetAlign('right', 'center'); |
||
| 711 | } |
||
| 712 | } else { |
||
| 713 | if ($val < 0) { |
||
| 714 | $this->value->SetAlign('center', 'bottom'); |
||
| 715 | } else { |
||
| 716 | $this->value->SetAlign('center', 'top'); |
||
| 717 | } |
||
| 718 | } |
||
| 719 | $this->value->SetMargin(-5); |
||
| 720 | $this->value->Stroke($img, $val, $x, $y); |
||
| 721 | } elseif ($this->valuepos == 'center') { |
||
| 722 | $y = ($pts[3] + $pts[1]) / 2; |
||
| 723 | $this->value->SetAlign('center', 'center'); |
||
| 724 | $this->value->SetMargin(0); |
||
| 725 | $this->value->Stroke($img, $val, $x, $y); |
||
| 726 | } elseif ($this->valuepos == 'bottom' || $this->valuepos == 'min') { |
||
| 727 | $y = $pts[1]; |
||
| 728 | if ($img->a === 90) { |
||
| 729 | if ($val < 0) { |
||
| 730 | $this->value->SetAlign('right', 'center'); |
||
| 731 | } else { |
||
| 732 | $this->value->SetAlign('left', 'center'); |
||
| 733 | } |
||
| 734 | } |
||
| 735 | $this->value->SetMargin(3); |
||
| 736 | $this->value->Stroke($img, $val, $x, $y); |
||
| 737 | } else { |
||
| 738 | Util\JpGraphError::RaiseL(2006, $this->valuepos); |
||
| 739 | //'Unknown position for values on bars :'.$this->valuepos); |
||
| 740 | } |
||
| 741 | // Create the client side image map |
||
| 742 | $rpts = $img->ArrRotate($pts); |
||
| 743 | $csimcoord = round($rpts[0]) . ', ' . round($rpts[1]); |
||
| 744 | for ($j = 1; $j < 4; ++$j) { |
||
| 745 | $csimcoord .= ', ' . round($rpts[2 * $j]) . ', ' . round($rpts[2 * $j + 1]); |
||
| 746 | } |
||
| 747 | if (!empty($this->csimtargets[$i])) { |
||
| 748 | $this->csimareas .= '<area shape="poly" coords="' . $csimcoord . '" '; |
||
| 749 | $this->csimareas .= ' href="' . htmlentities($this->csimtargets[$i]) . '"'; |
||
| 750 | |||
| 751 | if (!empty($this->csimwintargets[$i])) { |
||
| 752 | $this->csimareas .= ' target="' . $this->csimwintargets[$i] . '" '; |
||
| 753 | } |
||
| 754 | |||
| 755 | $sval = ''; |
||
| 756 | if (!empty($this->csimalts[$i])) { |
||
| 757 | $sval = sprintf($this->csimalts[$i], $this->coords[0][$i]); |
||
| 758 | $this->csimareas .= " title=\"${sval}\" alt=\"${sval}\" "; |
||
| 759 | } |
||
| 760 | $this->csimareas .= " />\n"; |
||
| 761 | } |
||
| 762 | } |
||
| 763 | |||
| 764 | return true; |
||
| 765 | } |
||
| 769 |