You are here

function pDraw::drawXThreshold in Visitors 7.2

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

File

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

Class

pDraw

Code

function drawXThreshold($Value, $Format = "") {
  $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"] : 5;
  $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"] : 3;
  $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"] : 30;
  $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;
  $ValueIsLabel = isset($Format["ValueIsLabel"]) ? $Format["ValueIsLabel"] : FALSE;
  $Data = $this->DataSet
    ->getData();
  $AbscissaMargin = $this
    ->getAbscissaMargin($Data);
  $XScale = $this
    ->scaleGetXSettings();
  if (is_array($Value)) {
    foreach ($Value as $Key => $ID) {
      $this
        ->drawXThreshold($ID, $Format);
    }
    return 0;
  }
  if ($ValueIsLabel) {
    $Format["ValueIsLabel"] = FALSE;
    foreach ($Data["Series"][$Data["Abscissa"]]["Data"] as $Key => $SerieValue) {
      if ($SerieValue == $Value) {
        $this
          ->drawXThreshold($Key, $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,
  );
  if ($Caption == NULL) {
    if (isset($Data["Abscissa"])) {
      if (isset($Data["Series"][$Data["Abscissa"]]["Data"][$Value])) {
        $Caption = $Data["Series"][$Data["Abscissa"]]["Data"][$Value];
      }
      else {
        $Caption = $Value;
      }
    }
    else {
      $Caption = $Value;
    }
  }
  if ($Data["Orientation"] == SCALE_POS_LEFTRIGHT) {
    $XStep = ($this->GraphAreaX2 - $this->GraphAreaX1 - $XScale[0] * 2) / $XScale[1];
    $XPos = $this->GraphAreaX1 + $XScale[0] + $XStep * $Value;
    $YPos1 = $this->GraphAreaY1 + $Data["YMargin"];
    $YPos2 = $this->GraphAreaY2 - $Data["YMargin"];
    if ($XPos >= $this->GraphAreaX1 + $AbscissaMargin && $XPos <= $this->GraphAreaX2 - $AbscissaMargin) {
      $this
        ->drawLine($XPos, $YPos1, $XPos, $YPos2, array(
        "R" => $R,
        "G" => $G,
        "B" => $B,
        "Alpha" => $Alpha,
        "Ticks" => $Ticks,
        "Weight" => $Weight,
      ));
      if ($Wide) {
        $this
          ->drawLine($XPos - 1, $YPos1, $XPos - 1, $YPos2, array(
          "R" => $R,
          "G" => $G,
          "B" => $B,
          "Alpha" => $Alpha / $WideFactor,
          "Ticks" => $Ticks,
        ));
        $this
          ->drawLine($XPos + 1, $YPos1, $XPos + 1, $YPos2, array(
          "R" => $R,
          "G" => $G,
          "B" => $B,
          "Alpha" => $Alpha / $WideFactor,
          "Ticks" => $Ticks,
        ));
      }
      if ($WriteCaption) {
        if ($CaptionAlign == CAPTION_LEFT_TOP) {
          $Y = $YPos1 + $CaptionOffset;
          $CaptionSettings["Align"] = TEXT_ALIGN_TOPMIDDLE;
        }
        else {
          $Y = $YPos2 - $CaptionOffset;
          $CaptionSettings["Align"] = TEXT_ALIGN_BOTTOMMIDDLE;
        }
        $this
          ->drawText($XPos, $Y, $Caption, $CaptionSettings);
      }
      return array(
        "X" => $XPos,
      );
    }
  }
  elseif ($Data["Orientation"] == SCALE_POS_TOPBOTTOM) {
    $XStep = ($this->GraphAreaY2 - $this->GraphAreaY1 - $XScale[0] * 2) / $XScale[1];
    $XPos = $this->GraphAreaY1 + $XScale[0] + $XStep * $Value;
    $YPos1 = $this->GraphAreaX1 + $Data["YMargin"];
    $YPos2 = $this->GraphAreaX2 - $Data["YMargin"];
    if ($XPos >= $this->GraphAreaY1 + $AbscissaMargin && $XPos <= $this->GraphAreaY2 - $AbscissaMargin) {
      $this
        ->drawLine($YPos1, $XPos, $YPos2, $XPos, array(
        "R" => $R,
        "G" => $G,
        "B" => $B,
        "Alpha" => $Alpha,
        "Ticks" => $Ticks,
        "Weight" => $Weight,
      ));
      if ($Wide) {
        $this
          ->drawLine($YPos1, $XPos - 1, $YPos2, $XPos - 1, array(
          "R" => $R,
          "G" => $G,
          "B" => $B,
          "Alpha" => $Alpha / $WideFactor,
          "Ticks" => $Ticks,
        ));
        $this
          ->drawLine($YPos1, $XPos + 1, $YPos2, $XPos + 1, array(
          "R" => $R,
          "G" => $G,
          "B" => $B,
          "Alpha" => $Alpha / $WideFactor,
          "Ticks" => $Ticks,
        ));
      }
      if ($WriteCaption) {
        if ($CaptionAlign == CAPTION_LEFT_TOP) {
          $Y = $YPos1 + $CaptionOffset;
          $CaptionSettings["Align"] = TEXT_ALIGN_MIDDLELEFT;
        }
        else {
          $Y = $YPos2 - $CaptionOffset;
          $CaptionSettings["Align"] = TEXT_ALIGN_MIDDLERIGHT;
        }
        $this
          ->drawText($Y, $XPos, $Caption, $CaptionSettings);
      }
      return array(
        "X" => $XPos,
      );
    }
  }
}