You are here

function pChart::drawOverlayBarGraph in Visitors 7.0

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

File

pchart/pChart.inc, line 1271

Class

pChart

Code

function drawOverlayBarGraph(&$Data, &$DataDescription, $Alpha = 50) {

  /* Validate the Data and DataDescription array */
  $this
    ->validateDataDescription("drawOverlayBarGraph", $DataDescription);
  $this
    ->validateData("drawOverlayBarGraph", $Data);
  $LayerWidth = $this->GArea_X2 - $this->GArea_X1;
  $LayerHeight = $this->GArea_Y2 - $this->GArea_Y1;
  $GraphID = 0;
  foreach ($DataDescription["Values"] as $Key2 => $ColName) {
    $ID = 0;
    foreach ($DataDescription["Description"] as $keyI => $ValueI) {
      if ($keyI == $ColName) {
        $ColorID = $ID;
      }
      $ID++;
    }
    $this->Layers[$GraphID] = imagecreatetruecolor($LayerWidth, $LayerHeight);
    $C_White = imagecolorallocate($this->Layers[$GraphID], 255, 255, 255);
    $C_Graph = imagecolorallocate($this->Layers[$GraphID], $this->Palette[$GraphID]["R"], $this->Palette[$GraphID]["G"], $this->Palette[$GraphID]["B"]);
    imagefilledrectangle($this->Layers[$GraphID], 0, 0, $LayerWidth, $LayerHeight, $C_White);
    imagecolortransparent($this->Layers[$GraphID], $C_White);
    $XWidth = $this->DivisionWidth / 4;
    $XPos = $this->GAreaXOffset;
    $YZero = $LayerHeight - (0 - $this->VMin) * $this->DivisionRatio;
    $XLast = -1;
    $PointsCount = 2;
    foreach ($Data as $Key => $Values) {
      if (isset($Data[$Key][$ColName])) {
        $Value = $Data[$Key][$ColName];
        if (is_numeric($Value)) {
          $YPos = $LayerHeight - ($Value - $this->VMin) * $this->DivisionRatio;
          imagefilledrectangle($this->Layers[$GraphID], $XPos - $XWidth, $YPos, $XPos + $XWidth, $YZero, $C_Graph);
          $X1 = floor($XPos - $XWidth + $this->GArea_X1);
          $Y1 = floor($YPos + $this->GArea_Y1) + 0.2;
          $X2 = floor($XPos + $XWidth + $this->GArea_X1);
          if ($X1 <= $this->GArea_X1) {
            $X1 = $this->GArea_X1 + 1;
          }
          if ($X2 >= $this->GArea_X2) {
            $X2 = $this->GArea_X2 - 1;
          }
          $this
            ->drawLine($X1, $Y1, $X2, $Y1, $this->Palette[$ColorID]["R"], $this->Palette[$ColorID]["G"], $this->Palette[$ColorID]["B"], TRUE);
        }
      }
      $XPos = $XPos + $this->DivisionWidth;
    }
    $GraphID++;
  }
  for ($i = 0; $i <= $GraphID - 1; $i++) {
    imagecopymerge($this->Picture, $this->Layers[$i], $this->GArea_X1, $this->GArea_Y1, 0, 0, $LayerWidth, $LayerHeight, $Alpha);
    imagedestroy($this->Layers[$i]);
  }
}