You are here

function pChart::drawFilledRadar in Visitors 7.0

Same name and namespace in other branches
  1. 8 pchart/pChart.inc \pChart::drawFilledRadar()

File

pchart/pChart.inc, line 1673

Class

pChart

Code

function drawFilledRadar(&$Data, &$DataDescription, $Alpha = 50, $BorderOffset = 10, $MaxValue = -1) {

  /* Validate the Data and DataDescription array */
  $this
    ->validateDataDescription("drawFilledRadar", $DataDescription);
  $this
    ->validateData("drawFilledRadar", $Data);
  $Points = count($Data);
  $LayerWidth = $this->GArea_X2 - $this->GArea_X1;
  $LayerHeight = $this->GArea_Y2 - $this->GArea_Y1;
  $Radius = ($this->GArea_Y2 - $this->GArea_Y1) / 2 - $BorderOffset;
  $XCenter = ($this->GArea_X2 - $this->GArea_X1) / 2;
  $YCenter = ($this->GArea_Y2 - $this->GArea_Y1) / 2;

  /* Search for the max value */
  if ($MaxValue == -1) {
    foreach ($DataDescription["Values"] as $Key2 => $ColName) {
      foreach ($Data as $Key => $Values) {
        if (isset($Data[$Key][$ColName])) {
          if ($Data[$Key][$ColName] > $MaxValue && is_numeric($Data[$Key][$ColName])) {
            $MaxValue = $Data[$Key][$ColName];
          }
        }
      }
    }
  }
  $GraphID = 0;
  foreach ($DataDescription["Values"] as $Key2 => $ColName) {
    $ID = 0;
    foreach ($DataDescription["Description"] as $keyI => $ValueI) {
      if ($keyI == $ColName) {
        $ColorID = $ID;
      }
      $ID++;
    }
    $Angle = -90;
    $XLast = -1;
    $Plots = "";
    foreach ($Data as $Key => $Values) {
      if (isset($Data[$Key][$ColName])) {
        $Value = $Data[$Key][$ColName];
        if (!is_numeric($Value)) {
          $Value = 0;
        }
        $Strength = $Radius / $MaxValue * $Value;
        $XPos = cos($Angle * 3.1418 / 180) * $Strength + $XCenter;
        $YPos = sin($Angle * 3.1418 / 180) * $Strength + $YCenter;
        $Plots[] = $XPos;
        $Plots[] = $YPos;
        $Angle = $Angle + 360 / $Points;
        $XLast = $XPos;
        $YLast = $YPos;
      }
    }
    if (isset($Plots[0])) {
      $Plots[] = $Plots[0];
      $Plots[] = $Plots[1];
      $this->Layers[0] = imagecreatetruecolor($LayerWidth, $LayerHeight);
      $C_White = imagecolorallocate($this->Layers[0], 255, 255, 255);
      imagefilledrectangle($this->Layers[0], 0, 0, $LayerWidth, $LayerHeight, $C_White);
      imagecolortransparent($this->Layers[0], $C_White);
      $C_Graph = imagecolorallocate($this->Layers[0], $this->Palette[$ColorID]["R"], $this->Palette[$ColorID]["G"], $this->Palette[$ColorID]["B"]);
      imagefilledpolygon($this->Layers[0], $Plots, (count($Plots) + 1) / 2, $C_Graph);
      imagecopymerge($this->Picture, $this->Layers[0], $this->GArea_X1, $this->GArea_Y1, 0, 0, $LayerWidth, $LayerHeight, $Alpha);
      imagedestroy($this->Layers[0]);
      for ($i = 0; $i <= count($Plots) - 4; $i = $i + 2) {
        $this
          ->drawLine($Plots[$i] + $this->GArea_X1, $Plots[$i + 1] + $this->GArea_Y1, $Plots[$i + 2] + $this->GArea_X1, $Plots[$i + 3] + $this->GArea_Y1, $this->Palette[$ColorID]["R"], $this->Palette[$ColorID]["G"], $this->Palette[$ColorID]["B"]);
      }
    }
    $GraphID++;
  }
}