| Conditions | 108 |
| Paths | 0 |
| Total Lines | 281 |
| Code Lines | 182 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 11772 |
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 |
||
| 399 | function drawPolar($Object,$Values,$Format="") |
||
| 400 | { |
||
| 401 | $this->pChartObject = $Object; |
||
| 402 | |||
| 403 | $FixedMax = isset($Format["FixedMax"]) ? $Format["FixedMax"] : VOID; |
||
| 404 | $AxisR = isset($Format["AxisR"]) ? $Format["AxisR"] : 60; |
||
| 405 | $AxisG = isset($Format["AxisG"]) ? $Format["AxisG"] : 60; |
||
| 406 | $AxisB = isset($Format["AxisB"]) ? $Format["AxisB"] : 60; |
||
| 407 | $AxisAlpha = isset($Format["AxisAlpha"]) ? $Format["AxisAlpha"] : 50; |
||
| 408 | $AxisRotation = isset($Format["AxisRotation"]) ? $Format["AxisRotation"] : -90; |
||
| 409 | $DrawTicks = isset($Format["DrawTicks"]) ? $Format["DrawTicks"] : TRUE; |
||
| 410 | $TicksLength = isset($Format["TicksLength"]) ? $Format["TicksLength"] : 2; |
||
| 411 | $DrawAxisValues = isset($Format["DrawAxisValues"]) ? $Format["DrawAxisValues"] : TRUE; |
||
| 412 | $AxisBoxRounded = isset($Format["AxisBoxRounded"]) ? $Format["AxisBoxRounded"] : TRUE; |
||
| 413 | $AxisFontName = isset($Format["FontName"]) ? $Format["FontName"] : $this->pChartObject->FontName; |
||
| 414 | $AxisFontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : $this->pChartObject->FontSize; |
||
| 415 | $WriteValues = isset($Format["WriteValues"]) ? $Format["WriteValues"] : FALSE; |
||
| 416 | $WriteValuesInBubble = isset($Format["WriteValuesInBubble"]) ? $Format["WriteValuesInBubble"] : TRUE; |
||
| 417 | $ValueFontName = isset($Format["ValueFontName"]) ? $Format["ValueFontName"] : $this->pChartObject->FontName; |
||
| 418 | $ValueFontSize = isset($Format["ValueFontSize"]) ? $Format["ValueFontSize"] : $this->pChartObject->FontSize; |
||
| 419 | $ValuePadding = isset($Format["ValuePadding"]) ? $Format["ValuePadding"] : 4; |
||
| 420 | $OuterBubbleRadius = isset($Format["OuterBubbleRadius"]) ? $Format["OuterBubbleRadius"] : 2; |
||
| 421 | $OuterBubbleR = isset($Format["OuterBubbleR"]) ? $Format["OuterBubbleR"] : VOID; |
||
| 422 | $OuterBubbleG = isset($Format["OuterBubbleG"]) ? $Format["OuterBubbleG"] : VOID; |
||
| 423 | $OuterBubbleB = isset($Format["OuterBubbleB"]) ? $Format["OuterBubbleB"] : VOID; |
||
| 424 | $OuterBubbleAlpha = isset($Format["OuterBubbleAlpha"]) ? $Format["OuterBubbleAlpha"] : 100; |
||
| 425 | $InnerBubbleR = isset($Format["InnerBubbleR"]) ? $Format["InnerBubbleR"] : 255; |
||
| 426 | $InnerBubbleG = isset($Format["InnerBubbleG"]) ? $Format["InnerBubbleG"] : 255; |
||
| 427 | $InnerBubbleB = isset($Format["InnerBubbleB"]) ? $Format["InnerBubbleB"] : 255; |
||
| 428 | $InnerBubbleAlpha = isset($Format["InnerBubbleAlpha"]) ? $Format["InnerBubbleAlpha"] : 100; |
||
| 429 | $DrawBackground = isset($Format["DrawBackground"]) ? $Format["DrawBackground"] : TRUE; |
||
| 430 | $BackgroundR = isset($Format["BackgroundR"]) ? $Format["BackgroundR"] : 255; |
||
| 431 | $BackgroundG = isset($Format["BackgroundG"]) ? $Format["BackgroundG"] : 255; |
||
| 432 | $BackgroundB = isset($Format["BackgroundB"]) ? $Format["BackgroundB"] : 255; |
||
| 433 | $BackgroundAlpha = isset($Format["BackgroundAlpha"]) ? $Format["BackgroundAlpha"] : 50; |
||
| 434 | $BackgroundGradient= isset($Format["BackgroundGradient"]) ? $Format["BackgroundGradient"] : NULL; |
||
| 435 | $AxisSteps = isset($Format["AxisSteps"]) ? $Format["AxisSteps"] : 20; |
||
| 436 | $SegmentHeight = isset($Format["SegmentHeight"]) ? $Format["SegmentHeight"] : SEGMENT_HEIGHT_AUTO; |
||
| 437 | $Segments = isset($Format["Segments"]) ? $Format["Segments"] : 4; |
||
| 438 | $WriteLabels = isset($Format["WriteLabels"]) ? $Format["WriteLabels"] : TRUE; |
||
| 439 | $LabelsBackground = isset($Format["LabelsBackground"]) ? $Format["LabelsBackground"] : TRUE; |
||
| 440 | $LabelsBGR = isset($Format["LabelsBGR"]) ? $Format["LabelsBGR"] : 255; |
||
| 441 | $LabelsBGG = isset($Format["LabelsBGR"]) ? $Format["LabelsBGG"] : 255; |
||
| 442 | $LabelsBGB = isset($Format["LabelsBGR"]) ? $Format["LabelsBGB"] : 255; |
||
| 443 | $LabelsBGAlpha = isset($Format["LabelsBGAlpha"]) ? $Format["LabelsBGAlpha"] : 50; |
||
| 444 | $LabelPos = isset($Format["LabelPos"]) ? $Format["LabelPos"] : RADAR_LABELS_ROTATED; |
||
| 445 | $LabelPadding = isset($Format["LabelPadding"]) ? $Format["LabelPadding"] : 4; |
||
| 446 | $DrawPoints = isset($Format["DrawPoints"]) ? $Format["DrawPoints"] : TRUE; |
||
| 447 | $PointRadius = isset($Format["PointRadius"]) ? $Format["PointRadius"] : 4; |
||
| 448 | $PointSurrounding = isset($Format["PointRadius"]) ? $Format["PointRadius"] : -30; |
||
| 449 | $DrawLines = isset($Format["DrawLines"]) ? $Format["DrawLines"] : TRUE; |
||
| 450 | $LineLoopStart = isset($Format["LineLoopStart"]) ? $Format["LineLoopStart"] : FALSE; |
||
| 451 | $DrawPoly = isset($Format["DrawPoly"]) ? $Format["DrawPoly"] : FALSE; |
||
| 452 | $PolyAlpha = isset($Format["PolyAlpha"]) ? $Format["PolyAlpha"] : NULL; |
||
| 453 | $FontSize = $Object->FontSize; |
||
| 454 | $X1 = $Object->GraphAreaX1; |
||
| 455 | $Y1 = $Object->GraphAreaY1; |
||
| 456 | $X2 = $Object->GraphAreaX2; |
||
| 457 | $Y2 = $Object->GraphAreaY2; |
||
| 458 | $RecordImageMap = isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE; |
||
| 459 | |||
| 460 | if ( $AxisBoxRounded ) { $DrawAxisValues = TRUE; } |
||
| 461 | |||
| 462 | /* Cancel default tick length if ticks not enabled */ |
||
| 463 | if ( $DrawTicks == FALSE ) { $TicksLength = 0; } |
||
| 464 | |||
| 465 | /* Data Processing */ |
||
| 466 | $Data = $Values->getData(); |
||
| 467 | $Palette = $Values->getPalette(); |
||
| 468 | |||
| 469 | /* Catch the number of required axis */ |
||
| 470 | $LabelSerie = $Data["Abscissa"]; |
||
| 471 | if ( $LabelSerie != "" ) |
||
| 472 | { $Points = count($Data["Series"][$LabelSerie]["Data"]); } |
||
| 473 | else |
||
| 474 | { |
||
| 475 | $Points = 0; |
||
| 476 | foreach($Data["Series"] as $SerieName => $DataArray) |
||
| 477 | { if ( count($DataArray["Data"]) > $Points ) { $Points = count($DataArray["Data"]); } } |
||
| 478 | } |
||
| 479 | |||
| 480 | /* Draw the axis */ |
||
| 481 | $CenterX = ($X2-$X1)/2 + $X1; |
||
| 482 | $CenterY = ($Y2-$Y1)/2 + $Y1; |
||
| 483 | |||
| 484 | $EdgeHeight = min(($X2-$X1)/2,($Y2-$Y1)/2); |
||
| 485 | if ( $WriteLabels ) |
||
| 486 | $EdgeHeight = $EdgeHeight - $FontSize - $LabelPadding - $TicksLength; |
||
| 487 | |||
| 488 | /* Determine the scale if set to automatic */ |
||
| 489 | if ( $SegmentHeight == SEGMENT_HEIGHT_AUTO) |
||
| 490 | { |
||
| 491 | if ( $FixedMax != VOID ) |
||
| 492 | $Max = $FixedMax; |
||
| 493 | else |
||
| 494 | { |
||
| 495 | $Max = 0; |
||
| 496 | foreach($Data["Series"] as $SerieName => $DataArray) |
||
| 497 | { |
||
| 498 | if ( $SerieName != $LabelSerie ) |
||
| 499 | { |
||
| 500 | if ( max($DataArray["Data"]) > $Max ) { $Max = max($DataArray["Data"]); } |
||
| 501 | } |
||
| 502 | } |
||
| 503 | } |
||
| 504 | $MaxSegments = $EdgeHeight/20; |
||
| 505 | $Scale = $Object->computeScale(0,$Max,$MaxSegments,array(1,2,5)); |
||
| 506 | |||
| 507 | $Segments = $Scale["Rows"]; |
||
| 508 | $SegmentHeight = $Scale["RowHeight"]; |
||
| 509 | } |
||
| 510 | |||
| 511 | |||
| 512 | /* Background processing */ |
||
| 513 | if ( $DrawBackground ) |
||
| 514 | { |
||
| 515 | $RestoreShadow = $Object->Shadow; |
||
| 516 | $Object->Shadow = FALSE; |
||
| 517 | |||
| 518 | if ($BackgroundGradient == NULL) |
||
| 519 | { |
||
| 520 | $Color = array("R"=>$BackgroundR,"G"=>$BackgroundG,"B"=>$BackgroundB,"Alpha"=>$BackgroundAlpha); |
||
| 521 | $Object->drawFilledCircle($CenterX,$CenterY,$EdgeHeight,$Color); |
||
| 522 | } |
||
| 523 | else |
||
| 524 | { |
||
| 525 | $GradientROffset = ($BackgroundGradient["EndR"] - $BackgroundGradient["StartR"]) / $Segments; |
||
| 526 | $GradientGOffset = ($BackgroundGradient["EndG"] - $BackgroundGradient["StartG"]) / $Segments; |
||
| 527 | $GradientBOffset = ($BackgroundGradient["EndB"] - $BackgroundGradient["StartB"]) / $Segments; |
||
| 528 | $GradientAlphaOffset = ($BackgroundGradient["EndAlpha"] - $BackgroundGradient["StartAlpha"]) / $Segments; |
||
| 529 | |||
| 530 | for($j=$Segments;$j>=1;$j--) |
||
| 531 | { |
||
| 532 | $Color = array("R"=>$BackgroundGradient["StartR"]+$GradientROffset*$j,"G"=>$BackgroundGradient["StartG"]+$GradientGOffset*$j,"B"=>$BackgroundGradient["StartB"]+$GradientBOffset*$j,"Alpha"=>$BackgroundGradient["StartAlpha"]+$GradientAlphaOffset*$j); |
||
| 533 | $Object->drawFilledCircle($CenterX,$CenterY,($EdgeHeight/$Segments)*$j,$Color); |
||
| 534 | } |
||
| 535 | } |
||
| 536 | $Object->Shadow = $RestoreShadow; |
||
| 537 | } |
||
| 538 | |||
| 539 | /* Axis to axis lines */ |
||
| 540 | $Color = array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha); |
||
| 541 | for($j=1;$j<=$Segments;$j++) |
||
| 542 | { |
||
| 543 | $Radius = ($EdgeHeight/$Segments)*$j; |
||
| 544 | $Object->drawCircle($CenterX,$CenterY,$Radius,$Radius,$Color); |
||
| 545 | } |
||
| 546 | |||
| 547 | if ( $DrawAxisValues ) |
||
| 548 | { |
||
| 549 | if ( $LabelsBackground ) |
||
| 550 | $Options = array("DrawBox"=>TRUE, "Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"BoxR"=>$LabelsBGR,"BoxG"=>$LabelsBGG,"BoxB"=>$LabelsBGB,"BoxAlpha"=>$LabelsBGAlpha); |
||
| 551 | else |
||
| 552 | $Options = array("Align"=>TEXT_ALIGN_MIDDLEMIDDLE); |
||
| 553 | |||
| 554 | if ( $AxisBoxRounded ) { $Options["BoxRounded"] = TRUE; } |
||
| 555 | |||
| 556 | $Options["FontName"] = $AxisFontName; |
||
| 557 | $Options["FontSize"] = $AxisFontSize; |
||
| 558 | |||
| 559 | $Angle = 360 / ($Points*2); |
||
| 560 | for($j=1;$j<=$Segments;$j++) |
||
| 561 | { |
||
| 562 | $EdgeX1 = cos(deg2rad($Angle+$AxisRotation)) * ($EdgeHeight/$Segments)*$j + $CenterX; |
||
| 563 | $EdgeY1 = sin(deg2rad($Angle+$AxisRotation)) * ($EdgeHeight/$Segments)*$j + $CenterY; |
||
| 564 | $Label = $j*$SegmentHeight; |
||
| 565 | |||
| 566 | $Object->drawText($EdgeX1,$EdgeY1,$Label,$Options); |
||
| 567 | } |
||
| 568 | } |
||
| 569 | |||
| 570 | /* Axis lines */ |
||
| 571 | $ID = 0; |
||
| 572 | for($i=0;$i<=359;$i=$i+$AxisSteps) |
||
| 573 | { |
||
| 574 | $EdgeX = cos(deg2rad($i+$AxisRotation)) * ($EdgeHeight+$TicksLength) + $CenterX; |
||
| 575 | $EdgeY = sin(deg2rad($i+$AxisRotation)) * ($EdgeHeight+$TicksLength) + $CenterY; |
||
| 576 | |||
| 577 | $Object->drawLine($CenterX,$CenterY,$EdgeX,$EdgeY,$Color); |
||
| 578 | |||
| 579 | if ( $WriteLabels ) |
||
| 580 | { |
||
| 581 | $LabelX = cos(deg2rad($i+$AxisRotation)) * ($EdgeHeight+$LabelPadding+$TicksLength) + $CenterX; |
||
| 582 | $LabelY = sin(deg2rad($i+$AxisRotation)) * ($EdgeHeight+$LabelPadding+$TicksLength) + $CenterY; |
||
| 583 | $Label = $i."�"; |
||
| 584 | |||
| 585 | if ( $LabelPos == RADAR_LABELS_ROTATED ) |
||
| 586 | $Object->drawText($LabelX,$LabelY,$Label,array("Angle"=>(360-$i),"Align"=>TEXT_ALIGN_BOTTOMMIDDLE)); |
||
| 587 | else |
||
| 588 | { |
||
| 589 | if ( (floor($LabelX) == floor($CenterX)) && (floor($LabelY) < floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE)); } |
||
| 590 | if ( (floor($LabelX) > floor($CenterX)) && (floor($LabelY) < floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_BOTTOMLEFT)); } |
||
| 591 | if ( (floor($LabelX) > floor($CenterX)) && (floor($LabelY) == floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_MIDDLELEFT)); } |
||
| 592 | if ( (floor($LabelX) > floor($CenterX)) && (floor($LabelY) > floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_TOPLEFT)); } |
||
| 593 | if ( (floor($LabelX) < floor($CenterX)) && (floor($LabelY) < floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_BOTTOMRIGHT)); } |
||
| 594 | if ( (floor($LabelX) < floor($CenterX)) && (floor($LabelY) == floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_MIDDLERIGHT)); } |
||
| 595 | if ( (floor($LabelX) < floor($CenterX)) && (floor($LabelY) > floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_TOPRIGHT)); } |
||
| 596 | if ( (floor($LabelX) == floor($CenterX)) && (floor($LabelY) > floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_TOPMIDDLE)); } |
||
| 597 | } |
||
| 598 | } |
||
| 599 | $ID++; |
||
| 600 | } |
||
| 601 | |||
| 602 | /* Compute the plots position */ |
||
| 603 | $ID = 0; $Plot = ""; |
||
| 604 | foreach($Data["Series"] as $SerieName => $DataSet) |
||
| 605 | { |
||
| 606 | if ( $SerieName != $LabelSerie ) |
||
| 607 | { |
||
| 608 | $Color = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"],"Surrounding"=>$PointSurrounding); |
||
| 609 | foreach($DataSet["Data"] as $Key => $Value) |
||
| 610 | { |
||
| 611 | $Angle = $Data["Series"][$LabelSerie]["Data"][$Key]; |
||
| 612 | $Length = ($EdgeHeight/($Segments*$SegmentHeight))*$Value; |
||
| 613 | |||
| 614 | $X = cos(deg2rad($Angle+$AxisRotation)) * $Length + $CenterX; |
||
| 615 | $Y = sin(deg2rad($Angle+$AxisRotation)) * $Length + $CenterY; |
||
| 616 | |||
| 617 | if ( $RecordImageMap ) { $this->pChartObject->addToImageMap("CIRCLE",floor($X).",".floor($Y).",".floor($PointRadius),$this->pChartObject->toHTMLColor($Palette[$ID]["R"],$Palette[$ID]["G"],$Palette[$ID]["B"]),$DataSet["Description"],$Data["Series"][$LabelSerie]["Data"][$Key]."° = ".$Value); } |
||
| 618 | |||
| 619 | $Plot[$ID][] = array($X,$Y,$Value); |
||
| 620 | } |
||
| 621 | $ID++; |
||
| 622 | } |
||
| 623 | } |
||
| 624 | |||
| 625 | /* Draw all that stuff! */ |
||
| 626 | foreach($Plot as $ID => $Points) |
||
| 627 | { |
||
| 628 | $Color = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"],"Surrounding"=>$PointSurrounding); |
||
| 629 | |||
| 630 | /* Draw the polygons */ |
||
| 631 | if ( $DrawPoly ) |
||
| 632 | { |
||
| 633 | if ($PolyAlpha != NULL) |
||
| 634 | $Color = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$PolyAlpha,"Surrounding"=>$PointSurrounding); |
||
| 635 | |||
| 636 | $PointsArray = ""; |
||
| 637 | for($i=0; $i<count($Points);$i++) |
||
| 638 | { $PointsArray[] = $Points[$i][0]; $PointsArray[] = $Points[$i][1]; } |
||
| 639 | |||
| 640 | $Object->drawPolygon($PointsArray,$Color); |
||
| 641 | } |
||
| 642 | |||
| 643 | $Color = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"],"Surrounding"=>$PointSurrounding); |
||
| 644 | |||
| 645 | /* Bubble and labels settings */ |
||
| 646 | $TextSettings = array("Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"FontName"=>$ValueFontName,"FontSize"=>$ValueFontSize,"R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"]); |
||
| 647 | $InnerColor = array("R"=>$InnerBubbleR,"G"=>$InnerBubbleG,"B"=>$InnerBubbleB,"Alpha"=>$InnerBubbleAlpha); |
||
| 648 | if ( $OuterBubbleR != VOID ) |
||
| 649 | $OuterColor = array("R"=>$OuterBubbleR,"G"=>$OuterBubbleG,"B"=>$OuterBubbleB,"Alpha"=>$OuterBubbleAlpha); |
||
| 650 | else |
||
| 651 | $OuterColor = array("R"=>$Palette[$ID]["R"]+20,"G"=>$Palette[$ID]["G"]+20,"B"=>$Palette[$ID]["B"]+20,"Alpha"=>$Palette[$ID]["Alpha"]); |
||
| 652 | |||
| 653 | /* Loop to the starting points if asked */ |
||
| 654 | if ( $LineLoopStart && $DrawLines ) |
||
| 655 | $Object->drawLine($Points[count($Points)-1][0],$Points[count($Points)-1][1],$Points[0][0],$Points[0][1],$Color); |
||
| 656 | |||
| 657 | /* Draw the lines & points */ |
||
| 658 | for($i=0; $i<count($Points);$i++) |
||
| 659 | { |
||
| 660 | if ( $DrawLines && $i < count($Points)-1) |
||
| 661 | $Object->drawLine($Points[$i][0],$Points[$i][1],$Points[$i+1][0],$Points[$i+1][1],$Color); |
||
| 662 | |||
| 663 | if ( $DrawPoints ) |
||
| 664 | $Object->drawFilledCircle($Points[$i][0],$Points[$i][1],$PointRadius,$Color); |
||
| 665 | |||
| 666 | if ( $WriteValuesInBubble && $WriteValues ) |
||
| 667 | { |
||
| 668 | $TxtPos = $this->pChartObject->getTextBox($Points[$i][0],$Points[$i][1],$ValueFontName,$ValueFontSize,0,$Points[$i][2]); |
||
| 669 | $Radius = floor(($TxtPos[1]["X"] - $TxtPos[0]["X"] + $ValuePadding*2)/2); |
||
| 670 | |||
| 671 | $this->pChartObject->drawFilledCircle($Points[$i][0],$Points[$i][1],$Radius+$OuterBubbleRadius,$OuterColor); |
||
| 672 | $this->pChartObject->drawFilledCircle($Points[$i][0],$Points[$i][1],$Radius,$InnerColor); |
||
| 673 | } |
||
| 674 | |||
| 675 | if ( $WriteValues ) |
||
| 676 | $this->pChartObject->drawText($Points[$i][0]-1,$Points[$i][1]-1,$Points[$i][2],$TextSettings); |
||
| 677 | } |
||
| 678 | } |
||
| 679 | } |
||
| 680 | } |
||
| 681 | ?> |