You are here

function pDraw::drawThreshold in Visitors 7.2

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

File

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

Class

pDraw

Code

function drawThreshold($Value, $Format = "") {
  $AxisID = isset($Format["AxisID"]) ? $Format["AxisID"] : 0;
  $R = isset($Format["R"]) ? $Format["R"] : 255;
  $G = isset($Format["G"]) ? $Format["G"] : 0;
  $B = isset($Format["B"]) ? $Format["B"] : 0;
  $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 50;
  $Weight = isset($Format["Weight"]) ? $Format["Weight"] : NULL;
  $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : 6;
  $Wide = isset($Format["Wide"]) ? $Format["Wide"] : FALSE;
  $WideFactor = isset($Format["WideFactor"]) ? $Format["WideFactor"] : 5;
  $WriteCaption = isset($Format["WriteCaption"]) ? $Format["WriteCaption"] : FALSE;
  $Caption = isset($Format["Caption"]) ? $Format["Caption"] : NULL;
  $CaptionAlign = isset($Format["CaptionAlign"]) ? $Format["CaptionAlign"] : CAPTION_LEFT_TOP;
  $CaptionOffset = isset($Format["CaptionOffset"]) ? $Format["CaptionOffset"] : 10;
  $CaptionR = isset($Format["CaptionR"]) ? $Format["CaptionR"] : 255;
  $CaptionG = isset($Format["CaptionG"]) ? $Format["CaptionG"] : 255;
  $CaptionB = isset($Format["CaptionB"]) ? $Format["CaptionB"] : 255;
  $CaptionAlpha = isset($Format["CaptionAlpha"]) ? $Format["CaptionAlpha"] : 100;
  $DrawBox = isset($Format["DrawBox"]) ? $Format["DrawBox"] : TRUE;
  $DrawBoxBorder = isset($Format["DrawBoxBorder"]) ? $Format["DrawBoxBorder"] : FALSE;
  $BorderOffset = isset($Format["BorderOffset"]) ? $Format["BorderOffset"] : 5;
  $BoxRounded = isset($Format["BoxRounded"]) ? $Format["BoxRounded"] : TRUE;
  $RoundedRadius = isset($Format["RoundedRadius"]) ? $Format["RoundedRadius"] : 3;
  $BoxR = isset($Format["BoxR"]) ? $Format["BoxR"] : 0;
  $BoxG = isset($Format["BoxG"]) ? $Format["BoxG"] : 0;
  $BoxB = isset($Format["BoxB"]) ? $Format["BoxB"] : 0;
  $BoxAlpha = isset($Format["BoxAlpha"]) ? $Format["BoxAlpha"] : 20;
  $BoxSurrounding = isset($Format["BoxSurrounding"]) ? $Format["BoxSurrounding"] : "";
  $BoxBorderR = isset($Format["BoxBorderR"]) ? $Format["BoxBorderR"] : 255;
  $BoxBorderG = isset($Format["BoxBorderG"]) ? $Format["BoxBorderG"] : 255;
  $BoxBorderB = isset($Format["BoxBorderB"]) ? $Format["BoxBorderB"] : 255;
  $BoxBorderAlpha = isset($Format["BoxBorderAlpha"]) ? $Format["BoxBorderAlpha"] : 100;
  $NoMargin = isset($Format["NoMargin"]) ? $Format["NoMargin"] : FALSE;
  if (is_array($Value)) {
    foreach ($Value as $Key => $ID) {
      $this
        ->drawThreshold($ID, $Format);
    }
    return 0;
  }
  $CaptionSettings = array(
    "DrawBox" => $DrawBox,
    "DrawBoxBorder" => $DrawBoxBorder,
    "BorderOffset" => $BorderOffset,
    "BoxRounded" => $BoxRounded,
    "RoundedRadius" => $RoundedRadius,
    "BoxR" => $BoxR,
    "BoxG" => $BoxG,
    "BoxB" => $BoxB,
    "BoxAlpha" => $BoxAlpha,
    "BoxSurrounding" => $BoxSurrounding,
    "BoxBorderR" => $BoxBorderR,
    "BoxBorderG" => $BoxBorderG,
    "BoxBorderB" => $BoxBorderB,
    "BoxBorderAlpha" => $BoxBorderAlpha,
    "R" => $CaptionR,
    "G" => $CaptionG,
    "B" => $CaptionB,
    "Alpha" => $CaptionAlpha,
  );
  $Data = $this->DataSet
    ->getData();
  $AbscissaMargin = $this
    ->getAbscissaMargin($Data);
  if ($NoMargin) {
    $AbscissaMargin = 0;
  }
  if (!isset($Data["Axis"][$AxisID])) {
    return -1;
  }
  if ($Caption == NULL) {
    $Caption = $Value;
  }
  if ($Data["Orientation"] == SCALE_POS_LEFTRIGHT) {
    $YPos = $this
      ->scaleComputeY($Value, array(
      "AxisID" => $AxisID,
    ));
    if ($YPos >= $this->GraphAreaY1 + $Data["Axis"][$AxisID]["Margin"] && $YPos <= $this->GraphAreaY2 - $Data["Axis"][$AxisID]["Margin"]) {
      $X1 = $this->GraphAreaX1 + $AbscissaMargin;
      $X2 = $this->GraphAreaX2 - $AbscissaMargin;
      $this
        ->drawLine($X1, $YPos, $X2, $YPos, array(
        "R" => $R,
        "G" => $G,
        "B" => $B,
        "Alpha" => $Alpha,
        "Ticks" => $Ticks,
        "Weight" => $Weight,
      ));
      if ($Wide) {
        $this
          ->drawLine($X1, $YPos - 1, $X2, $YPos - 1, array(
          "R" => $R,
          "G" => $G,
          "B" => $B,
          "Alpha" => $Alpha / $WideFactor,
          "Ticks" => $Ticks,
        ));
        $this
          ->drawLine($X1, $YPos + 1, $X2, $YPos + 1, array(
          "R" => $R,
          "G" => $G,
          "B" => $B,
          "Alpha" => $Alpha / $WideFactor,
          "Ticks" => $Ticks,
        ));
      }
      if ($WriteCaption) {
        if ($CaptionAlign == CAPTION_LEFT_TOP) {
          $X = $X1 + $CaptionOffset;
          $CaptionSettings["Align"] = TEXT_ALIGN_MIDDLELEFT;
        }
        else {
          $X = $X2 - $CaptionOffset;
          $CaptionSettings["Align"] = TEXT_ALIGN_MIDDLERIGHT;
        }
        $this
          ->drawText($X, $YPos, $Caption, $CaptionSettings);
      }
    }
    return array(
      "Y" => $YPos,
    );
  }
  if ($Data["Orientation"] == SCALE_POS_TOPBOTTOM) {
    $XPos = $this
      ->scaleComputeY($Value, array(
      "AxisID" => $AxisID,
    ));
    if ($XPos >= $this->GraphAreaX1 + $Data["Axis"][$AxisID]["Margin"] && $XPos <= $this->GraphAreaX2 - $Data["Axis"][$AxisID]["Margin"]) {
      $Y1 = $this->GraphAreaY1 + $AbscissaMargin;
      $Y2 = $this->GraphAreaY2 - $AbscissaMargin;
      $this
        ->drawLine($XPos, $Y1, $XPos, $Y2, array(
        "R" => $R,
        "G" => $G,
        "B" => $B,
        "Alpha" => $Alpha,
        "Ticks" => $Ticks,
        "Weight" => $Weight,
      ));
      if ($Wide) {
        $this
          ->drawLine($XPos - 1, $Y1, $XPos - 1, $Y2, array(
          "R" => $R,
          "G" => $G,
          "B" => $B,
          "Alpha" => $Alpha / $WideFactor,
          "Ticks" => $Ticks,
        ));
        $this
          ->drawLine($XPos + 1, $Y1, $XPos + 1, $Y2, array(
          "R" => $R,
          "G" => $G,
          "B" => $B,
          "Alpha" => $Alpha / $WideFactor,
          "Ticks" => $Ticks,
        ));
      }
      if ($WriteCaption) {
        if ($CaptionAlign == CAPTION_LEFT_TOP) {
          $Y = $Y1 + $CaptionOffset;
          $CaptionSettings["Align"] = TEXT_ALIGN_TOPMIDDLE;
        }
        else {
          $Y = $Y2 - $CaptionOffset;
          $CaptionSettings["Align"] = TEXT_ALIGN_BOTTOMMIDDLE;
        }
        $CaptionSettings["Align"] = TEXT_ALIGN_TOPMIDDLE;
        $this
          ->drawText($XPos, $Y, $Caption, $CaptionSettings);
      }
    }
    return array(
      "Y" => $XPos,
    );
  }
}