You are here

function pDraw::drawProgress in Visitors 7

Same name and namespace in other branches
  1. 7.2 pChart/class/pDraw.class.php \pDraw::drawProgress()

File

pChart/class/pDraw.class.php, line 1414

Class

pDraw

Code

function drawProgress($X, $Y, $Percent, $Format = "") {
  if ($Percent > 100) {
    $Percent = 100;
  }
  if ($Percent < 0) {
    $Percent = 0;
  }
  $Width = isset($Format["Width"]) ? $Format["Width"] : 200;
  $Height = isset($Format["Height"]) ? $Format["Height"] : 20;
  $Orientation = isset($Format["Orientation"]) ? $Format["Orientation"] : ORIENTATION_HORIZONTAL;
  $ShowLabel = isset($Format["ShowLabel"]) ? $Format["ShowLabel"] : FALSE;
  $LabelPos = isset($Format["LabelPos"]) ? $Format["LabelPos"] : LABEL_POS_INSIDE;
  $Margin = isset($Format["Margin"]) ? $Format["Margin"] : 10;
  $R = isset($Format["R"]) ? $Format["R"] : 130;
  $G = isset($Format["G"]) ? $Format["G"] : 130;
  $B = isset($Format["B"]) ? $Format["B"] : 130;
  $RFade = isset($Format["RFade"]) ? $Format["RFade"] : -1;
  $GFade = isset($Format["GFade"]) ? $Format["GFade"] : -1;
  $BFade = isset($Format["BFade"]) ? $Format["BFade"] : -1;
  $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : $R;
  $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : $G;
  $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : $B;
  $BoxBorderR = isset($Format["BoxBorderR"]) ? $Format["BoxBorderR"] : 0;
  $BoxBorderG = isset($Format["BoxBorderG"]) ? $Format["BoxBorderG"] : 0;
  $BoxBorderB = isset($Format["BoxBorderB"]) ? $Format["BoxBorderB"] : 0;
  $BoxBackR = isset($Format["BoxBackR"]) ? $Format["BoxBackR"] : 255;
  $BoxBackG = isset($Format["BoxBackG"]) ? $Format["BoxBackG"] : 255;
  $BoxBackB = isset($Format["BoxBackB"]) ? $Format["BoxBackB"] : 255;
  $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
  $BoxSurrounding = isset($Format["BoxSurrounding"]) ? $Format["BoxSurrounding"] : NULL;
  $NoAngle = isset($Format["NoAngle"]) ? $Format["NoAngle"] : FALSE;
  if ($RFade != -1 && $GFade != -1 && $BFade != -1) {
    $RFade = ($RFade - $R) / 100 * $Percent + $R;
    $GFade = ($GFade - $G) / 100 * $Percent + $G;
    $BFade = ($BFade - $B) / 100 * $Percent + $B;
  }
  if ($Surrounding != NULL) {
    $BorderR = $R + $Surrounding;
    $BorderG = $G + $Surrounding;
    $BorderB = $B + $Surrounding;
  }
  if ($BoxSurrounding != NULL) {
    $BoxBorderR = $BoxBackR + $Surrounding;
    $BoxBorderG = $BoxBackG + $Surrounding;
    $BoxBorderB = $BoxBackB + $Surrounding;
  }
  if ($Orientation == ORIENTATION_VERTICAL) {
    $InnerHeight = ($Height - 2) / 100 * $Percent;
    $this
      ->drawFilledRectangle($X, $Y, $X + $Width, $Y - $Height, array(
      "R" => $BoxBackR,
      "G" => $BoxBackG,
      "B" => $BoxBackB,
      "BorderR" => $BoxBorderR,
      "BorderG" => $BoxBorderG,
      "BorderB" => $BoxBorderB,
      "NoAngle" => $NoAngle,
    ));
    $RestoreShadow = $this->Shadow;
    $this->Shadow = FALSE;
    if ($RFade != -1 && $GFade != -1 && $BFade != -1) {
      $GradientOptions = array(
        "StartR" => $RFade,
        "StartG" => $GFade,
        "StartB" => $BFade,
        "EndR" => $R,
        "EndG" => $G,
        "EndB" => $B,
      );
      $this
        ->drawGradientArea($X + 1, $Y - 1, $X + $Width - 1, $Y - $InnerHeight, DIRECTION_VERTICAL, $GradientOptions);
      if ($Surrounding) {
        $this
          ->drawRectangle($X + 1, $Y - 1, $X + $Width - 1, $Y - $InnerHeight, array(
          "R" => 255,
          "G" => 255,
          "B" => 255,
          "Alpha" => $Surrounding,
        ));
      }
    }
    else {
      $this
        ->drawFilledRectangle($X + 1, $Y - 1, $X + $Width - 1, $Y - $InnerHeight, array(
        "R" => $R,
        "G" => $G,
        "B" => $B,
        "BorderR" => $BorderR,
        "BorderG" => $BorderG,
        "BorderB" => $BorderB,
      ));
    }
    $this->Shadow = $RestoreShadow;
    if ($ShowLabel && $LabelPos == LABEL_POS_BOTTOM) {
      $this
        ->drawText($X + $Width / 2, $Y + $Margin, $Percent . "%", array(
        "Align" => TEXT_ALIGN_TOPMIDDLE,
      ));
    }
    if ($ShowLabel && $LabelPos == LABEL_POS_TOP) {
      $this
        ->drawText($X + $Width / 2, $Y - $Height - $Margin, $Percent . "%", array(
        "Align" => TEXT_ALIGN_BOTTOMMIDDLE,
      ));
    }
    if ($ShowLabel && $LabelPos == LABEL_POS_INSIDE) {
      $this
        ->drawText($X + $Width / 2, $Y - $InnerHeight - $Margin, $Percent . "%", array(
        "Align" => TEXT_ALIGN_MIDDLELEFT,
        "Angle" => 90,
      ));
    }
    if ($ShowLabel && $LabelPos == LABEL_POS_CENTER) {
      $this
        ->drawText($X + $Width / 2, $Y - $Height / 2, $Percent . "%", array(
        "Align" => TEXT_ALIGN_MIDDLEMIDDLE,
        "Angle" => 90,
      ));
    }
  }
  else {
    if ($Percent == 100) {
      $InnerWidth = $Width - 1;
    }
    else {
      $InnerWidth = ($Width - 2) / 100 * $Percent;
    }
    $this
      ->drawFilledRectangle($X, $Y, $X + $Width, $Y + $Height, array(
      "R" => $BoxBackR,
      "G" => $BoxBackG,
      "B" => $BoxBackB,
      "BorderR" => $BoxBorderR,
      "BorderG" => $BoxBorderG,
      "BorderB" => $BoxBorderB,
      "NoAngle" => $NoAngle,
    ));
    $RestoreShadow = $this->Shadow;
    $this->Shadow = FALSE;
    if ($RFade != -1 && $GFade != -1 && $BFade != -1) {
      $GradientOptions = array(
        "StartR" => $R,
        "StartG" => $G,
        "StartB" => $B,
        "EndR" => $RFade,
        "EndG" => $GFade,
        "EndB" => $BFade,
      );
      $this
        ->drawGradientArea($X + 1, $Y + 1, $X + $InnerWidth, $Y + $Height - 1, DIRECTION_HORIZONTAL, $GradientOptions);
      if ($Surrounding) {
        $this
          ->drawRectangle($X + 1, $Y + 1, $X + $InnerWidth, $Y + $Height - 1, array(
          "R" => 255,
          "G" => 255,
          "B" => 255,
          "Alpha" => $Surrounding,
        ));
      }
    }
    else {
      $this
        ->drawFilledRectangle($X + 1, $Y + 1, $X + $InnerWidth, $Y + $Height - 1, array(
        "R" => $R,
        "G" => $G,
        "B" => $B,
        "BorderR" => $BorderR,
        "BorderG" => $BorderG,
        "BorderB" => $BorderB,
      ));
    }
    $this->Shadow = $RestoreShadow;
    if ($ShowLabel && $LabelPos == LABEL_POS_LEFT) {
      $this
        ->drawText($X - $Margin, $Y + $Height / 2, $Percent . "%", array(
        "Align" => TEXT_ALIGN_MIDDLERIGHT,
      ));
    }
    if ($ShowLabel && $LabelPos == LABEL_POS_RIGHT) {
      $this
        ->drawText($X + $Width + $Margin, $Y + $Height / 2, $Percent . "%", array(
        "Align" => TEXT_ALIGN_MIDDLELEFT,
      ));
    }
    if ($ShowLabel && $LabelPos == LABEL_POS_CENTER) {
      $this
        ->drawText($X + $Width / 2, $Y + $Height / 2, $Percent . "%", array(
        "Align" => TEXT_ALIGN_MIDDLEMIDDLE,
      ));
    }
    if ($ShowLabel && $LabelPos == LABEL_POS_INSIDE) {
      $this
        ->drawText($X + $InnerWidth + $Margin, $Y + $Height / 2, $Percent . "%", array(
        "Align" => TEXT_ALIGN_MIDDLELEFT,
      ));
    }
  }
}