You are here

function pDraw::drawScale in Visitors 7.2

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

File

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

Class

pDraw

Code

function drawScale($Format = "") {
  $Pos = isset($Format["Pos"]) ? $Format["Pos"] : SCALE_POS_LEFTRIGHT;
  $Floating = isset($Format["Floating"]) ? $Format["Floating"] : FALSE;
  $Mode = isset($Format["Mode"]) ? $Format["Mode"] : SCALE_MODE_FLOATING;
  $RemoveXAxis = isset($Format["RemoveXAxis"]) ? $Format["RemoveXAxis"] : FALSE;
  $MinDivHeight = isset($Format["MinDivHeight"]) ? $Format["MinDivHeight"] : 20;
  $Factors = isset($Format["Factors"]) ? $Format["Factors"] : array(
    1,
    2,
    5,
  );
  $ManualScale = isset($Format["ManualScale"]) ? $Format["ManualScale"] : array(
    "0" => array(
      "Min" => -100,
      "Max" => 100,
    ),
  );
  $XMargin = isset($Format["XMargin"]) ? $Format["XMargin"] : AUTO;
  $YMargin = isset($Format["YMargin"]) ? $Format["YMargin"] : 0;
  $ScaleSpacing = isset($Format["ScaleSpacing"]) ? $Format["ScaleSpacing"] : 15;
  $InnerTickWidth = isset($Format["InnerTickWidth"]) ? $Format["InnerTickWidth"] : 2;
  $OuterTickWidth = isset($Format["OuterTickWidth"]) ? $Format["OuterTickWidth"] : 2;
  $DrawXLines = isset($Format["DrawXLines"]) ? $Format["DrawXLines"] : TRUE;
  $DrawYLines = isset($Format["DrawYLines"]) ? $Format["DrawYLines"] : ALL;
  $GridTicks = isset($Format["GridTicks"]) ? $Format["GridTicks"] : 4;
  $GridR = isset($Format["GridR"]) ? $Format["GridR"] : 255;
  $GridG = isset($Format["GridG"]) ? $Format["GridG"] : 255;
  $GridB = isset($Format["GridB"]) ? $Format["GridB"] : 255;
  $GridAlpha = isset($Format["GridAlpha"]) ? $Format["GridAlpha"] : 40;
  $AxisRo = isset($Format["AxisR"]) ? $Format["AxisR"] : 0;
  $AxisGo = isset($Format["AxisG"]) ? $Format["AxisG"] : 0;
  $AxisBo = isset($Format["AxisB"]) ? $Format["AxisB"] : 0;
  $AxisAlpha = isset($Format["AxisAlpha"]) ? $Format["AxisAlpha"] : 100;
  $TickRo = isset($Format["TickR"]) ? $Format["TickR"] : 0;
  $TickGo = isset($Format["TickG"]) ? $Format["TickG"] : 0;
  $TickBo = isset($Format["TickB"]) ? $Format["TickB"] : 0;
  $TickAlpha = isset($Format["TickAlpha"]) ? $Format["TickAlpha"] : 100;
  $DrawSubTicks = isset($Format["DrawSubTicks"]) ? $Format["DrawSubTicks"] : FALSE;
  $InnerSubTickWidth = isset($Format["InnerSubTickWidth"]) ? $Format["InnerSubTickWidth"] : 0;
  $OuterSubTickWidth = isset($Format["OuterSubTickWidth"]) ? $Format["OuterSubTickWidth"] : 2;
  $SubTickR = isset($Format["SubTickR"]) ? $Format["SubTickR"] : 255;
  $SubTickG = isset($Format["SubTickG"]) ? $Format["SubTickG"] : 0;
  $SubTickB = isset($Format["SubTickB"]) ? $Format["SubTickB"] : 0;
  $SubTickAlpha = isset($Format["SubTickAlpha"]) ? $Format["SubTickAlpha"] : 100;
  $AutoAxisLabels = isset($Format["AutoAxisLabels"]) ? $Format["AutoAxisLabels"] : TRUE;
  $XReleasePercent = isset($Format["XReleasePercent"]) ? $Format["XReleasePercent"] : 1;
  $DrawArrows = isset($Format["DrawArrows"]) ? $Format["DrawArrows"] : FALSE;
  $ArrowSize = isset($Format["ArrowSize"]) ? $Format["ArrowSize"] : 8;
  $CycleBackground = isset($Format["CycleBackground"]) ? $Format["CycleBackground"] : FALSE;
  $BackgroundR1 = isset($Format["BackgroundR1"]) ? $Format["BackgroundR1"] : 255;
  $BackgroundG1 = isset($Format["BackgroundG1"]) ? $Format["BackgroundG1"] : 255;
  $BackgroundB1 = isset($Format["BackgroundB1"]) ? $Format["BackgroundB1"] : 255;
  $BackgroundAlpha1 = isset($Format["BackgroundAlpha1"]) ? $Format["BackgroundAlpha1"] : 20;
  $BackgroundR2 = isset($Format["BackgroundR2"]) ? $Format["BackgroundR2"] : 230;
  $BackgroundG2 = isset($Format["BackgroundG2"]) ? $Format["BackgroundG2"] : 230;
  $BackgroundB2 = isset($Format["BackgroundB2"]) ? $Format["BackgroundB2"] : 230;
  $BackgroundAlpha2 = isset($Format["BackgroundAlpha2"]) ? $Format["BackgroundAlpha2"] : 20;
  $LabelingMethod = isset($Format["LabelingMethod"]) ? $Format["LabelingMethod"] : LABELING_ALL;
  $LabelSkip = isset($Format["LabelSkip"]) ? $Format["LabelSkip"] : 0;
  $LabelRotation = isset($Format["LabelRotation"]) ? $Format["LabelRotation"] : 0;
  $RemoveSkippedAxis = isset($Format["RemoveSkippedAxis"]) ? $Format["RemoveSkippedAxis"] : FALSE;
  $SkippedAxisTicks = isset($Format["SkippedAxisTicks"]) ? $Format["SkippedAxisTicks"] : $GridTicks + 2;
  $SkippedAxisR = isset($Format["SkippedAxisR"]) ? $Format["SkippedAxisR"] : $GridR;
  $SkippedAxisG = isset($Format["SkippedAxisG"]) ? $Format["SkippedAxisG"] : $GridG;
  $SkippedAxisB = isset($Format["SkippedAxisB"]) ? $Format["SkippedAxisB"] : $GridB;
  $SkippedAxisAlpha = isset($Format["SkippedAxisAlpha"]) ? $Format["SkippedAxisAlpha"] : $GridAlpha - 30;
  $SkippedTickR = isset($Format["SkippedTickR"]) ? $Format["SkippedTickR"] : $TickRo;
  $SkippedTickG = isset($Format["SkippedTickG"]) ? $Format["SkippedTickG"] : $TickGo;
  $SkippedTickB = isset($Format["SkippedTicksB"]) ? $Format["SkippedTickB"] : $TickBo;
  $SkippedTickAlpha = isset($Format["SkippedTickAlpha"]) ? $Format["SkippedTickAlpha"] : $TickAlpha - 80;
  $SkippedInnerTickWidth = isset($Format["SkippedInnerTickWidth"]) ? $Format["SkippedInnerTickWidth"] : 0;
  $SkippedOuterTickWidth = isset($Format["SkippedOuterTickWidth"]) ? $Format["SkippedOuterTickWidth"] : 2;

  /* Floating scale require X & Y margins to be set manually */
  if ($Floating && ($XMargin == AUTO || $YMargin == 0)) {
    $Floating = FALSE;
  }

  /* Skip a NOTICE event in case of an empty array */
  if ($DrawYLines == NONE || $DrawYLines == FALSE) {
    $DrawYLines = array(
      "zarma" => "31",
    );
  }

  /* Define the color for the skipped elements */
  $SkippedAxisColor = array(
    "R" => $SkippedAxisR,
    "G" => $SkippedAxisG,
    "B" => $SkippedAxisB,
    "Alpha" => $SkippedAxisAlpha,
    "Ticks" => $SkippedAxisTicks,
  );
  $SkippedTickColor = array(
    "R" => $SkippedTickR,
    "G" => $SkippedTickG,
    "B" => $SkippedTickB,
    "Alpha" => $SkippedTickAlpha,
  );
  $Data = $this->DataSet
    ->getData();
  if (isset($Data["Abscissa"])) {
    $Abscissa = $Data["Abscissa"];
  }
  else {
    $Abscissa = NULL;
  }

  /* Unset the abscissa axis, needed if we display multiple charts on the same picture */
  if ($Abscissa != NULL) {
    foreach ($Data["Axis"] as $AxisID => $Parameters) {
      if ($Parameters["Identity"] == AXIS_X) {
        unset($Data["Axis"][$AxisID]);
      }
    }
  }

  /* Build the scale settings */
  $GotXAxis = FALSE;
  foreach ($Data["Axis"] as $AxisID => $AxisParameter) {
    if ($AxisParameter["Identity"] == AXIS_X) {
      $GotXAxis = TRUE;
    }
    if ($Pos == SCALE_POS_LEFTRIGHT && $AxisParameter["Identity"] == AXIS_Y) {
      $Height = $this->GraphAreaY2 - $this->GraphAreaY1 - $YMargin * 2;
    }
    elseif ($Pos == SCALE_POS_LEFTRIGHT && $AxisParameter["Identity"] == AXIS_X) {
      $Height = $this->GraphAreaX2 - $this->GraphAreaX1;
    }
    elseif ($Pos == SCALE_POS_TOPBOTTOM && $AxisParameter["Identity"] == AXIS_Y) {
      $Height = $this->GraphAreaX2 - $this->GraphAreaX1 - $YMargin * 2;
    }
    else {
      $Height = $this->GraphAreaY2 - $this->GraphAreaY1;
    }
    $AxisMin = ABSOLUTE_MAX;
    $AxisMax = OUT_OF_SIGHT;
    if ($Mode == SCALE_MODE_FLOATING || $Mode == SCALE_MODE_START0) {
      foreach ($Data["Series"] as $SerieID => $SerieParameter) {
        if ($SerieParameter["Axis"] == $AxisID && $Data["Series"][$SerieID]["isDrawable"] && $Data["Abscissa"] != $SerieID) {
          $AxisMax = max($AxisMax, $Data["Series"][$SerieID]["Max"]);
          $AxisMin = min($AxisMin, $Data["Series"][$SerieID]["Min"]);
        }
      }
      $AutoMargin = ($AxisMax - $AxisMin) / 100 * $XReleasePercent;
      $Data["Axis"][$AxisID]["Min"] = $AxisMin - $AutoMargin;
      $Data["Axis"][$AxisID]["Max"] = $AxisMax + $AutoMargin;
      if ($Mode == SCALE_MODE_START0) {
        $Data["Axis"][$AxisID]["Min"] = 0;
      }
    }
    elseif ($Mode == SCALE_MODE_MANUAL) {
      if (isset($ManualScale[$AxisID]["Min"]) && isset($ManualScale[$AxisID]["Max"])) {
        $Data["Axis"][$AxisID]["Min"] = $ManualScale[$AxisID]["Min"];
        $Data["Axis"][$AxisID]["Max"] = $ManualScale[$AxisID]["Max"];
      }
      else {
        echo "Manual scale boundaries not set.";
        exit;
      }
    }
    elseif ($Mode == SCALE_MODE_ADDALL || $Mode == SCALE_MODE_ADDALL_START0) {
      $Series = "";
      foreach ($Data["Series"] as $SerieID => $SerieParameter) {
        if ($SerieParameter["Axis"] == $AxisID && $SerieParameter["isDrawable"] && $Data["Abscissa"] != $SerieID) {
          $Series[$SerieID] = count($Data["Series"][$SerieID]["Data"]);
        }
      }
      for ($ID = 0; $ID <= max($Series) - 1; $ID++) {
        $PointMin = 0;
        $PointMax = 0;
        foreach ($Series as $SerieID => $ValuesCount) {
          if (isset($Data["Series"][$SerieID]["Data"][$ID]) && $Data["Series"][$SerieID]["Data"][$ID] != NULL) {
            $Value = $Data["Series"][$SerieID]["Data"][$ID];
            if ($Value > 0) {
              $PointMax = $PointMax + $Value;
            }
            else {
              $PointMin = $PointMin + $Value;
            }
          }
        }
        $AxisMax = max($AxisMax, $PointMax);
        $AxisMin = min($AxisMin, $PointMin);
      }
      $AutoMargin = ($AxisMax - $AxisMin) / 100 * $XReleasePercent;
      $Data["Axis"][$AxisID]["Min"] = $AxisMin - $AutoMargin;
      $Data["Axis"][$AxisID]["Max"] = $AxisMax + $AutoMargin;
    }
    $MaxDivs = floor($Height / $MinDivHeight);
    if ($Mode == SCALE_MODE_ADDALL_START0) {
      $Data["Axis"][$AxisID]["Min"] = 0;
    }
    $Scale = $this
      ->computeScale($Data["Axis"][$AxisID]["Min"], $Data["Axis"][$AxisID]["Max"], $MaxDivs, $Factors, $AxisID);
    $Data["Axis"][$AxisID]["Margin"] = $AxisParameter["Identity"] == AXIS_X ? $XMargin : $YMargin;
    $Data["Axis"][$AxisID]["ScaleMin"] = $Scale["XMin"];
    $Data["Axis"][$AxisID]["ScaleMax"] = $Scale["XMax"];
    $Data["Axis"][$AxisID]["Rows"] = $Scale["Rows"];
    $Data["Axis"][$AxisID]["RowHeight"] = $Scale["RowHeight"];
    if (isset($Scale["Format"])) {
      $Data["Axis"][$AxisID]["Format"] = $Scale["Format"];
    }
    if (!isset($Data["Axis"][$AxisID]["Display"])) {
      $Data["Axis"][$AxisID]["Display"] = NULL;
    }
    if (!isset($Data["Axis"][$AxisID]["Format"])) {
      $Data["Axis"][$AxisID]["Format"] = NULL;
    }
    if (!isset($Data["Axis"][$AxisID]["Unit"])) {
      $Data["Axis"][$AxisID]["Unit"] = NULL;
    }
  }

  /* Still no X axis */
  if ($GotXAxis == FALSE) {
    if ($Abscissa != NULL) {
      $Points = count($Data["Series"][$Abscissa]["Data"]);
      if ($AutoAxisLabels) {
        $AxisName = isset($Data["Series"][$Abscissa]["Description"]) ? $Data["Series"][$Abscissa]["Description"] : NULL;
      }
      else {
        $AxisName = NULL;
      }
    }
    else {
      $Points = 0;
      $AxisName = isset($Data["XAxisName"]) ? $Data["XAxisName"] : NULL;
      foreach ($Data["Series"] as $SerieID => $SerieParameter) {
        if ($SerieParameter["isDrawable"]) {
          $Points = max($Points, count($SerieParameter["Data"]));
        }
      }
    }
    $AxisID = count($Data["Axis"]);
    $Data["Axis"][$AxisID]["Identity"] = AXIS_X;
    if ($Pos == SCALE_POS_LEFTRIGHT) {
      $Data["Axis"][$AxisID]["Position"] = AXIS_POSITION_BOTTOM;
    }
    else {
      $Data["Axis"][$AxisID]["Position"] = AXIS_POSITION_LEFT;
    }
    if (isset($Data["AbscissaName"])) {
      $Data["Axis"][$AxisID]["Name"] = $Data["AbscissaName"];
    }
    if ($XMargin == AUTO) {
      if ($Pos == SCALE_POS_LEFTRIGHT) {
        $Height = $this->GraphAreaX2 - $this->GraphAreaX1;
      }
      else {
        $Height = $this->GraphAreaY2 - $this->GraphAreaY1;
      }
      if ($Points == 1) {
        $Data["Axis"][$AxisID]["Margin"] = $Height / 2;
      }
      else {
        $Data["Axis"][$AxisID]["Margin"] = $Height / $Points / 2;
      }
    }
    else {
      $Data["Axis"][$AxisID]["Margin"] = $XMargin;
    }
    $Data["Axis"][$AxisID]["Rows"] = $Points - 1;
    if (!isset($Data["Axis"][$AxisID]["Display"])) {
      $Data["Axis"][$AxisID]["Display"] = NULL;
    }
    if (!isset($Data["Axis"][$AxisID]["Format"])) {
      $Data["Axis"][$AxisID]["Format"] = NULL;
    }
    if (!isset($Data["Axis"][$AxisID]["Unit"])) {
      $Data["Axis"][$AxisID]["Unit"] = NULL;
    }
  }

  /* Do we need to reverse the abscissa position? */
  if ($Pos != SCALE_POS_LEFTRIGHT) {
    if ($Data["AbsicssaPosition"] == AXIS_POSITION_BOTTOM) {
      $Data["AbsicssaPosition"] = AXIS_POSITION_LEFT;
    }
    else {
      $Data["AbsicssaPosition"] = AXIS_POSITION_RIGHT;
    }
  }
  $Data["Axis"][$AxisID]["Position"] = $Data["AbsicssaPosition"];
  $this->DataSet
    ->saveOrientation($Pos);
  $this->DataSet
    ->saveAxisConfig($Data["Axis"]);
  $this->DataSet
    ->saveYMargin($YMargin);
  $FontColorRo = $this->FontColorR;
  $FontColorGo = $this->FontColorG;
  $FontColorBo = $this->FontColorB;
  $AxisPos["L"] = $this->GraphAreaX1;
  $AxisPos["R"] = $this->GraphAreaX2;
  $AxisPos["T"] = $this->GraphAreaY1;
  $AxisPos["B"] = $this->GraphAreaY2;
  foreach ($Data["Axis"] as $AxisID => $Parameters) {
    if (isset($Parameters["Color"])) {
      $AxisR = $Parameters["Color"]["R"];
      $AxisG = $Parameters["Color"]["G"];
      $AxisB = $Parameters["Color"]["B"];
      $TickR = $Parameters["Color"]["R"];
      $TickG = $Parameters["Color"]["G"];
      $TickB = $Parameters["Color"]["B"];
      $this
        ->setFontProperties(array(
        "R" => $Parameters["Color"]["R"],
        "G" => $Parameters["Color"]["G"],
        "B" => $Parameters["Color"]["B"],
      ));
    }
    else {
      $AxisR = $AxisRo;
      $AxisG = $AxisGo;
      $AxisB = $AxisBo;
      $TickR = $TickRo;
      $TickG = $TickGo;
      $TickB = $TickBo;
      $this
        ->setFontProperties(array(
        "R" => $FontColorRo,
        "G" => $FontColorGo,
        "B" => $FontColorBo,
      ));
    }
    $LastValue = "w00t";
    $ID = 1;
    if ($Parameters["Identity"] == AXIS_X) {
      if ($Pos == SCALE_POS_LEFTRIGHT) {
        if ($Parameters["Position"] == AXIS_POSITION_BOTTOM) {
          if ($LabelRotation == 0) {
            $LabelAlign = TEXT_ALIGN_TOPMIDDLE;
            $YLabelOffset = 2;
          }
          if ($LabelRotation > 0 && $LabelRotation < 190) {
            $LabelAlign = TEXT_ALIGN_MIDDLERIGHT;
            $YLabelOffset = 5;
          }
          if ($LabelRotation == 180) {
            $LabelAlign = TEXT_ALIGN_BOTTOMMIDDLE;
            $YLabelOffset = 5;
          }
          if ($LabelRotation > 180 && $LabelRotation < 360) {
            $LabelAlign = TEXT_ALIGN_MIDDLELEFT;
            $YLabelOffset = 2;
          }
          if (!$RemoveXAxis) {
            if ($Floating) {
              $FloatingOffset = $YMargin;
              $this
                ->drawLine($this->GraphAreaX1 + $Parameters["Margin"], $AxisPos["B"], $this->GraphAreaX2 - $Parameters["Margin"], $AxisPos["B"], array(
                "R" => $AxisR,
                "G" => $AxisG,
                "B" => $AxisB,
                "Alpha" => $AxisAlpha,
              ));
            }
            else {
              $FloatingOffset = 0;
              $this
                ->drawLine($this->GraphAreaX1, $AxisPos["B"], $this->GraphAreaX2, $AxisPos["B"], array(
                "R" => $AxisR,
                "G" => $AxisG,
                "B" => $AxisB,
                "Alpha" => $AxisAlpha,
              ));
            }
            if ($DrawArrows) {
              $this
                ->drawArrow($this->GraphAreaX2 - $Parameters["Margin"], $AxisPos["B"], $this->GraphAreaX2 + $ArrowSize * 2, $AxisPos["B"], array(
                "FillR" => $AxisR,
                "FillG" => $AxisG,
                "FillB" => $AxisB,
                "Size" => $ArrowSize,
              ));
            }
          }
          $Width = $this->GraphAreaX2 - $this->GraphAreaX1 - $Parameters["Margin"] * 2;
          if ($Parameters["Rows"] == 0) {
            $Step = $Width;
          }
          else {
            $Step = $Width / $Parameters["Rows"];
          }
          $MaxBottom = $AxisPos["B"];
          for ($i = 0; $i <= $Parameters["Rows"]; $i++) {
            $XPos = $this->GraphAreaX1 + $Parameters["Margin"] + $Step * $i;
            $YPos = $AxisPos["B"];
            if ($Abscissa != NULL) {
              if (isset($Data["Series"][$Abscissa]["Data"][$i])) {
                $Value = $this
                  ->scaleFormat($Data["Series"][$Abscissa]["Data"][$i], $Data["XAxisDisplay"], $Data["XAxisFormat"], $Data["XAxisUnit"]);
              }
              else {
                $Value = "";
              }
            }
            else {
              if (isset($Parameters["ScaleMin"]) && isset($Parameters["RowHeight"])) {
                $Value = $this
                  ->scaleFormat($Parameters["ScaleMin"] + $Parameters["RowHeight"] * $i, $Data["XAxisDisplay"], $Data["XAxisFormat"], $Data["XAxisUnit"]);
              }
              else {
                $Value = $i;
              }
            }
            $ID++;
            $Skipped = TRUE;
            if ($this
              ->isValidLabel($Value, $LastValue, $LabelingMethod, $ID, $LabelSkip) && !$RemoveXAxis) {
              $Bounds = $this
                ->drawText($XPos, $YPos + $OuterTickWidth + $YLabelOffset, $Value, array(
                "Angle" => $LabelRotation,
                "Align" => $LabelAlign,
              ));
              $TxtBottom = $YPos + $OuterTickWidth + 2 + ($Bounds[0]["Y"] - $Bounds[2]["Y"]);
              $MaxBottom = max($MaxBottom, $TxtBottom);
              $LastValue = $Value;
              $Skipped = FALSE;
            }
            if ($RemoveXAxis) {
              $Skipped = FALSE;
            }
            if ($Skipped) {
              if ($DrawXLines && !$RemoveSkippedAxis) {
                $this
                  ->drawLine($XPos, $this->GraphAreaY1 + $FloatingOffset, $XPos, $this->GraphAreaY2 - $FloatingOffset, $SkippedAxisColor);
              }
              if (($SkippedInnerTickWidth != 0 || $SkippedOuterTickWidth != 0) && !$RemoveXAxis && !$RemoveSkippedAxis) {
                $this
                  ->drawLine($XPos, $YPos - $SkippedInnerTickWidth, $XPos, $YPos + $SkippedOuterTickWidth, $SkippedTickColor);
              }
            }
            else {
              if ($DrawXLines && ($XPos != $this->GraphAreaX1 && $XPos != $this->GraphAreaX2)) {
                $this
                  ->drawLine($XPos, $this->GraphAreaY1 + $FloatingOffset, $XPos, $this->GraphAreaY2 - $FloatingOffset, array(
                  "R" => $GridR,
                  "G" => $GridG,
                  "B" => $GridB,
                  "Alpha" => $GridAlpha,
                  "Ticks" => $GridTicks,
                ));
              }
              if (($InnerTickWidth != 0 || $OuterTickWidth != 0) && !$RemoveXAxis) {
                $this
                  ->drawLine($XPos, $YPos - $InnerTickWidth, $XPos, $YPos + $OuterTickWidth, array(
                  "R" => $TickR,
                  "G" => $TickG,
                  "B" => $TickB,
                  "Alpha" => $TickAlpha,
                ));
              }
            }
          }
          if (isset($Parameters["Name"]) && !$RemoveXAxis) {
            $YPos = $MaxBottom + 2;
            $XPos = $this->GraphAreaX1 + ($this->GraphAreaX2 - $this->GraphAreaX1) / 2;
            $Bounds = $this
              ->drawText($XPos, $YPos, $Parameters["Name"], array(
              "Align" => TEXT_ALIGN_TOPMIDDLE,
            ));
            $MaxBottom = $Bounds[0]["Y"];
            $this->DataSet->Data["GraphArea"]["Y2"] = $MaxBottom + $this->FontSize;
          }
          $AxisPos["B"] = $MaxBottom + $ScaleSpacing;
        }
        elseif ($Parameters["Position"] == AXIS_POSITION_TOP) {
          if ($LabelRotation == 0) {
            $LabelAlign = TEXT_ALIGN_BOTTOMMIDDLE;
            $YLabelOffset = 2;
          }
          if ($LabelRotation > 0 && $LabelRotation < 190) {
            $LabelAlign = TEXT_ALIGN_MIDDLELEFT;
            $YLabelOffset = 2;
          }
          if ($LabelRotation == 180) {
            $LabelAlign = TEXT_ALIGN_TOPMIDDLE;
            $YLabelOffset = 5;
          }
          if ($LabelRotation > 180 && $LabelRotation < 360) {
            $LabelAlign = TEXT_ALIGN_MIDDLERIGHT;
            $YLabelOffset = 5;
          }
          if (!$RemoveXAxis) {
            if ($Floating) {
              $FloatingOffset = $YMargin;
              $this
                ->drawLine($this->GraphAreaX1 + $Parameters["Margin"], $AxisPos["T"], $this->GraphAreaX2 - $Parameters["Margin"], $AxisPos["T"], array(
                "R" => $AxisR,
                "G" => $AxisG,
                "B" => $AxisB,
                "Alpha" => $AxisAlpha,
              ));
            }
            else {
              $FloatingOffset = 0;
              $this
                ->drawLine($this->GraphAreaX1, $AxisPos["T"], $this->GraphAreaX2, $AxisPos["T"], array(
                "R" => $AxisR,
                "G" => $AxisG,
                "B" => $AxisB,
                "Alpha" => $AxisAlpha,
              ));
            }
            if ($DrawArrows) {
              $this
                ->drawArrow($this->GraphAreaX2 - $Parameters["Margin"], $AxisPos["T"], $this->GraphAreaX2 + $ArrowSize * 2, $AxisPos["T"], array(
                "FillR" => $AxisR,
                "FillG" => $AxisG,
                "FillB" => $AxisB,
                "Size" => $ArrowSize,
              ));
            }
          }
          $Width = $this->GraphAreaX2 - $this->GraphAreaX1 - $Parameters["Margin"] * 2;
          if ($Parameters["Rows"] == 0) {
            $Step = $Width;
          }
          else {
            $Step = $Width / $Parameters["Rows"];
          }
          $MinTop = $AxisPos["T"];
          for ($i = 0; $i <= $Parameters["Rows"]; $i++) {
            $XPos = $this->GraphAreaX1 + $Parameters["Margin"] + $Step * $i;
            $YPos = $AxisPos["T"];
            if ($Abscissa != NULL) {
              if (isset($Data["Series"][$Abscissa]["Data"][$i])) {
                $Value = $this
                  ->scaleFormat($Data["Series"][$Abscissa]["Data"][$i], $Data["XAxisDisplay"], $Data["XAxisFormat"], $Data["XAxisUnit"]);
              }
              else {
                $Value = "";
              }
            }
            else {
              if (isset($Parameters["ScaleMin"]) && isset($Parameters["RowHeight"])) {
                $Value = $this
                  ->scaleFormat($Parameters["ScaleMin"] + $Parameters["RowHeight"] * $i, $Data["XAxisDisplay"], $Data["XAxisFormat"], $Data["XAxisUnit"]);
              }
              else {
                $Value = $i;
              }
            }
            $ID++;
            $Skipped = TRUE;
            if ($this
              ->isValidLabel($Value, $LastValue, $LabelingMethod, $ID, $LabelSkip) && !$RemoveXAxis) {
              $Bounds = $this
                ->drawText($XPos, $YPos - $OuterTickWidth - $YLabelOffset, $Value, array(
                "Angle" => $LabelRotation,
                "Align" => $LabelAlign,
              ));
              $TxtBox = $YPos - $OuterTickWidth - 2 - ($Bounds[0]["Y"] - $Bounds[2]["Y"]);
              $MinTop = min($MinTop, $TxtBox);
              $LastValue = $Value;
              $Skipped = FALSE;
            }
            if ($RemoveXAxis) {
              $Skipped = FALSE;
            }
            if ($Skipped) {
              if ($DrawXLines && !$RemoveSkippedAxis) {
                $this
                  ->drawLine($XPos, $this->GraphAreaY1 + $FloatingOffset, $XPos, $this->GraphAreaY2 - $FloatingOffset, $SkippedAxisColor);
              }
              if (($SkippedInnerTickWidth != 0 || $SkippedOuterTickWidth != 0) && !$RemoveXAxis && !$RemoveSkippedAxis) {
                $this
                  ->drawLine($XPos, $YPos + $SkippedInnerTickWidth, $XPos, $YPos - $SkippedOuterTickWidth, $SkippedTickColor);
              }
            }
            else {
              if ($DrawXLines) {
                $this
                  ->drawLine($XPos, $this->GraphAreaY1 + $FloatingOffset, $XPos, $this->GraphAreaY2 - $FloatingOffset, array(
                  "R" => $GridR,
                  "G" => $GridG,
                  "B" => $GridB,
                  "Alpha" => $GridAlpha,
                  "Ticks" => $GridTicks,
                ));
              }
              if (($InnerTickWidth != 0 || $OuterTickWidth != 0) && !$RemoveXAxis) {
                $this
                  ->drawLine($XPos, $YPos + $InnerTickWidth, $XPos, $YPos - $OuterTickWidth, array(
                  "R" => $TickR,
                  "G" => $TickG,
                  "B" => $TickB,
                  "Alpha" => $TickAlpha,
                ));
              }
            }
          }
          if (isset($Parameters["Name"]) && !$RemoveXAxis) {
            $YPos = $MinTop - 2;
            $XPos = $this->GraphAreaX1 + ($this->GraphAreaX2 - $this->GraphAreaX1) / 2;
            $Bounds = $this
              ->drawText($XPos, $YPos, $Parameters["Name"], array(
              "Align" => TEXT_ALIGN_BOTTOMMIDDLE,
            ));
            $MinTop = $Bounds[2]["Y"];
            $this->DataSet->Data["GraphArea"]["Y1"] = $MinTop;
          }
          $AxisPos["T"] = $MinTop - $ScaleSpacing;
        }
      }
      elseif ($Pos == SCALE_POS_TOPBOTTOM) {
        if ($Parameters["Position"] == AXIS_POSITION_LEFT) {
          if ($LabelRotation == 0) {
            $LabelAlign = TEXT_ALIGN_MIDDLERIGHT;
            $XLabelOffset = -2;
          }
          if ($LabelRotation > 0 && $LabelRotation < 190) {
            $LabelAlign = TEXT_ALIGN_MIDDLERIGHT;
            $XLabelOffset = -6;
          }
          if ($LabelRotation == 180) {
            $LabelAlign = TEXT_ALIGN_MIDDLELEFT;
            $XLabelOffset = -2;
          }
          if ($LabelRotation > 180 && $LabelRotation < 360) {
            $LabelAlign = TEXT_ALIGN_MIDDLELEFT;
            $XLabelOffset = -5;
          }
          if (!$RemoveXAxis) {
            if ($Floating) {
              $FloatingOffset = $YMargin;
              $this
                ->drawLine($AxisPos["L"], $this->GraphAreaY1 + $Parameters["Margin"], $AxisPos["L"], $this->GraphAreaY2 - $Parameters["Margin"], array(
                "R" => $AxisR,
                "G" => $AxisG,
                "B" => $AxisB,
                "Alpha" => $AxisAlpha,
              ));
            }
            else {
              $FloatingOffset = 0;
              $this
                ->drawLine($AxisPos["L"], $this->GraphAreaY1, $AxisPos["L"], $this->GraphAreaY2, array(
                "R" => $AxisR,
                "G" => $AxisG,
                "B" => $AxisB,
                "Alpha" => $AxisAlpha,
              ));
            }
            if ($DrawArrows) {
              $this
                ->drawArrow($AxisPos["L"], $this->GraphAreaY2 - $Parameters["Margin"], $AxisPos["L"], $this->GraphAreaY2 + $ArrowSize * 2, array(
                "FillR" => $AxisR,
                "FillG" => $AxisG,
                "FillB" => $AxisB,
                "Size" => $ArrowSize,
              ));
            }
          }
          $Height = $this->GraphAreaY2 - $this->GraphAreaY1 - $Parameters["Margin"] * 2;
          if ($Parameters["Rows"] == 0) {
            $Step = $Height;
          }
          else {
            $Step = $Height / $Parameters["Rows"];
          }
          $MinLeft = $AxisPos["L"];
          for ($i = 0; $i <= $Parameters["Rows"]; $i++) {
            $YPos = $this->GraphAreaY1 + $Parameters["Margin"] + $Step * $i;
            $XPos = $AxisPos["L"];
            if ($Abscissa != NULL) {
              if (isset($Data["Series"][$Abscissa]["Data"][$i])) {
                $Value = $this
                  ->scaleFormat($Data["Series"][$Abscissa]["Data"][$i], $Data["XAxisDisplay"], $Data["XAxisFormat"], $Data["XAxisUnit"]);
              }
              else {
                $Value = "";
              }
            }
            else {
              if (isset($Parameters["ScaleMin"]) && isset($Parameters["RowHeight"])) {
                $Value = $this
                  ->scaleFormat($Parameters["ScaleMin"] + $Parameters["RowHeight"] * $i, $Data["XAxisDisplay"], $Data["XAxisFormat"], $Data["XAxisUnit"]);
              }
              else {
                $Value = $i;
              }
            }
            $ID++;
            $Skipped = TRUE;
            if ($this
              ->isValidLabel($Value, $LastValue, $LabelingMethod, $ID, $LabelSkip) && !$RemoveXAxis) {
              $Bounds = $this
                ->drawText($XPos - $OuterTickWidth + $XLabelOffset, $YPos, $Value, array(
                "Angle" => $LabelRotation,
                "Align" => $LabelAlign,
              ));
              $TxtBox = $XPos - $OuterTickWidth - 2 - ($Bounds[1]["X"] - $Bounds[0]["X"]);
              $MinLeft = min($MinLeft, $TxtBox);
              $LastValue = $Value;
              $Skipped = FALSE;
            }
            if ($RemoveXAxis) {
              $Skipped = FALSE;
            }
            if ($Skipped) {
              if ($DrawXLines && !$RemoveSkippedAxis) {
                $this
                  ->drawLine($this->GraphAreaX1 + $FloatingOffset, $YPos, $this->GraphAreaX2 - $FloatingOffset, $YPos, $SkippedAxisColor);
              }
              if (($SkippedInnerTickWidth != 0 || $SkippedOuterTickWidth != 0) && !$RemoveXAxis && !$RemoveSkippedAxis) {
                $this
                  ->drawLine($XPos - $SkippedOuterTickWidth, $YPos, $XPos + $SkippedInnerTickWidth, $YPos, $SkippedTickColor);
              }
            }
            else {
              if ($DrawXLines && ($YPos != $this->GraphAreaY1 && $YPos != $this->GraphAreaY2)) {
                $this
                  ->drawLine($this->GraphAreaX1 + $FloatingOffset, $YPos, $this->GraphAreaX2 - $FloatingOffset, $YPos, array(
                  "R" => $GridR,
                  "G" => $GridG,
                  "B" => $GridB,
                  "Alpha" => $GridAlpha,
                  "Ticks" => $GridTicks,
                ));
              }
              if (($InnerTickWidth != 0 || $OuterTickWidth != 0) && !$RemoveXAxis) {
                $this
                  ->drawLine($XPos - $OuterTickWidth, $YPos, $XPos + $InnerTickWidth, $YPos, array(
                  "R" => $TickR,
                  "G" => $TickG,
                  "B" => $TickB,
                  "Alpha" => $TickAlpha,
                ));
              }
            }
          }
          if (isset($Parameters["Name"]) && !$RemoveXAxis) {
            $XPos = $MinLeft - 2;
            $YPos = $this->GraphAreaY1 + ($this->GraphAreaY2 - $this->GraphAreaY1) / 2;
            $Bounds = $this
              ->drawText($XPos, $YPos, $Parameters["Name"], array(
              "Align" => TEXT_ALIGN_BOTTOMMIDDLE,
              "Angle" => 90,
            ));
            $MinLeft = $Bounds[0]["X"];
            $this->DataSet->Data["GraphArea"]["X1"] = $MinLeft;
          }
          $AxisPos["L"] = $MinLeft - $ScaleSpacing;
        }
        elseif ($Parameters["Position"] == AXIS_POSITION_RIGHT) {
          if ($LabelRotation == 0) {
            $LabelAlign = TEXT_ALIGN_MIDDLELEFT;
            $XLabelOffset = 2;
          }
          if ($LabelRotation > 0 && $LabelRotation < 190) {
            $LabelAlign = TEXT_ALIGN_MIDDLELEFT;
            $XLabelOffset = 6;
          }
          if ($LabelRotation == 180) {
            $LabelAlign = TEXT_ALIGN_MIDDLERIGHT;
            $XLabelOffset = 5;
          }
          if ($LabelRotation > 180 && $LabelRotation < 360) {
            $LabelAlign = TEXT_ALIGN_MIDDLERIGHT;
            $XLabelOffset = 7;
          }
          if (!$RemoveXAxis) {
            if ($Floating) {
              $FloatingOffset = $YMargin;
              $this
                ->drawLine($AxisPos["R"], $this->GraphAreaY1 + $Parameters["Margin"], $AxisPos["R"], $this->GraphAreaY2 - $Parameters["Margin"], array(
                "R" => $AxisR,
                "G" => $AxisG,
                "B" => $AxisB,
                "Alpha" => $AxisAlpha,
              ));
            }
            else {
              $FloatingOffset = 0;
              $this
                ->drawLine($AxisPos["R"], $this->GraphAreaY1, $AxisPos["R"], $this->GraphAreaY2, array(
                "R" => $AxisR,
                "G" => $AxisG,
                "B" => $AxisB,
                "Alpha" => $AxisAlpha,
              ));
            }
            if ($DrawArrows) {
              $this
                ->drawArrow($AxisPos["R"], $this->GraphAreaY2 - $Parameters["Margin"], $AxisPos["R"], $this->GraphAreaY2 + $ArrowSize * 2, array(
                "FillR" => $AxisR,
                "FillG" => $AxisG,
                "FillB" => $AxisB,
                "Size" => $ArrowSize,
              ));
            }
          }
          $Height = $this->GraphAreaY2 - $this->GraphAreaY1 - $Parameters["Margin"] * 2;
          if ($Parameters["Rows"] == 0) {
            $Step = $Height;
          }
          else {
            $Step = $Height / $Parameters["Rows"];
          }
          $MaxRight = $AxisPos["R"];
          for ($i = 0; $i <= $Parameters["Rows"]; $i++) {
            $YPos = $this->GraphAreaY1 + $Parameters["Margin"] + $Step * $i;
            $XPos = $AxisPos["R"];
            if ($Abscissa != NULL) {
              if (isset($Data["Series"][$Abscissa]["Data"][$i])) {
                $Value = $this
                  ->scaleFormat($Data["Series"][$Abscissa]["Data"][$i], $Data["XAxisDisplay"], $Data["XAxisFormat"], $Data["XAxisUnit"]);
              }
              else {
                $Value = "";
              }
            }
            else {
              if (isset($Parameters["ScaleMin"]) && isset($Parameters["RowHeight"])) {
                $Value = $this
                  ->scaleFormat($Parameters["ScaleMin"] + $Parameters["RowHeight"] * $i, $Data["XAxisDisplay"], $Data["XAxisFormat"], $Data["XAxisUnit"]);
              }
              else {
                $Value = $i;
              }
            }
            $ID++;
            $Skipped = TRUE;
            if ($this
              ->isValidLabel($Value, $LastValue, $LabelingMethod, $ID, $LabelSkip) && !$RemoveXAxis) {
              $Bounds = $this
                ->drawText($XPos + $OuterTickWidth + $XLabelOffset, $YPos, $Value, array(
                "Angle" => $LabelRotation,
                "Align" => $LabelAlign,
              ));
              $TxtBox = $XPos + $OuterTickWidth + 2 + ($Bounds[1]["X"] - $Bounds[0]["X"]);
              $MaxRight = max($MaxRight, $TxtBox);
              $LastValue = $Value;
              $Skipped = FALSE;
            }
            if ($RemoveXAxis) {
              $Skipped = FALSE;
            }
            if ($Skipped) {
              if ($DrawXLines && !$RemoveSkippedAxis) {
                $this
                  ->drawLine($this->GraphAreaX1 + $FloatingOffset, $YPos, $this->GraphAreaX2 - $FloatingOffset, $YPos, $SkippedAxisColor);
              }
              if (($SkippedInnerTickWidth != 0 || $SkippedOuterTickWidth != 0) && !$RemoveXAxis && !$RemoveSkippedAxis) {
                $this
                  ->drawLine($XPos + $SkippedOuterTickWidth, $YPos, $XPos - $SkippedInnerTickWidth, $YPos, $SkippedTickColor);
              }
            }
            else {
              if ($DrawXLines) {
                $this
                  ->drawLine($this->GraphAreaX1 + $FloatingOffset, $YPos, $this->GraphAreaX2 - $FloatingOffset, $YPos, array(
                  "R" => $GridR,
                  "G" => $GridG,
                  "B" => $GridB,
                  "Alpha" => $GridAlpha,
                  "Ticks" => $GridTicks,
                ));
              }
              if (($InnerTickWidth != 0 || $OuterTickWidth != 0) && !$RemoveXAxis) {
                $this
                  ->drawLine($XPos + $OuterTickWidth, $YPos, $XPos - $InnerTickWidth, $YPos, array(
                  "R" => $TickR,
                  "G" => $TickG,
                  "B" => $TickB,
                  "Alpha" => $TickAlpha,
                ));
              }
            }
          }
          if (isset($Parameters["Name"]) && !$RemoveXAxis) {
            $XPos = $MaxRight + 4;
            $YPos = $this->GraphAreaY1 + ($this->GraphAreaY2 - $this->GraphAreaY1) / 2;
            $Bounds = $this
              ->drawText($XPos, $YPos, $Parameters["Name"], array(
              "Align" => TEXT_ALIGN_BOTTOMMIDDLE,
              "Angle" => 270,
            ));
            $MaxRight = $Bounds[1]["X"];
            $this->DataSet->Data["GraphArea"]["X2"] = $MaxRight + $this->FontSize;
          }
          $AxisPos["R"] = $MaxRight + $ScaleSpacing;
        }
      }
    }
    if ($Parameters["Identity"] == AXIS_Y) {
      if ($Pos == SCALE_POS_LEFTRIGHT) {
        if ($Parameters["Position"] == AXIS_POSITION_LEFT) {
          if ($Floating) {
            $FloatingOffset = $XMargin;
            $this
              ->drawLine($AxisPos["L"], $this->GraphAreaY1 + $Parameters["Margin"], $AxisPos["L"], $this->GraphAreaY2 - $Parameters["Margin"], array(
              "R" => $AxisR,
              "G" => $AxisG,
              "B" => $AxisB,
              "Alpha" => $AxisAlpha,
            ));
          }
          else {
            $FloatingOffset = 0;
            $this
              ->drawLine($AxisPos["L"], $this->GraphAreaY1, $AxisPos["L"], $this->GraphAreaY2, array(
              "R" => $AxisR,
              "G" => $AxisG,
              "B" => $AxisB,
              "Alpha" => $AxisAlpha,
            ));
          }
          if ($DrawArrows) {
            $this
              ->drawArrow($AxisPos["L"], $this->GraphAreaY1 + $Parameters["Margin"], $AxisPos["L"], $this->GraphAreaY1 - $ArrowSize * 2, array(
              "FillR" => $AxisR,
              "FillG" => $AxisG,
              "FillB" => $AxisB,
              "Size" => $ArrowSize,
            ));
          }
          $Height = $this->GraphAreaY2 - $this->GraphAreaY1 - $Parameters["Margin"] * 2;
          $Step = $Height / $Parameters["Rows"];
          $SubTicksSize = $Step / 2;
          $MinLeft = $AxisPos["L"];
          $LastY = NULL;
          for ($i = 0; $i <= $Parameters["Rows"]; $i++) {
            $YPos = $this->GraphAreaY2 - $Parameters["Margin"] - $Step * $i;
            $XPos = $AxisPos["L"];
            $Value = $this
              ->scaleFormat($Parameters["ScaleMin"] + $Parameters["RowHeight"] * $i, $Parameters["Display"], $Parameters["Format"], $Parameters["Unit"]);
            if ($i % 2 == 1) {
              $BGColor = array(
                "R" => $BackgroundR1,
                "G" => $BackgroundG1,
                "B" => $BackgroundB1,
                "Alpha" => $BackgroundAlpha1,
              );
            }
            else {
              $BGColor = array(
                "R" => $BackgroundR2,
                "G" => $BackgroundG2,
                "B" => $BackgroundB2,
                "Alpha" => $BackgroundAlpha2,
              );
            }
            if ($LastY != NULL && $CycleBackground && ($DrawYLines == ALL || in_array($AxisID, $DrawYLines))) {
              $this
                ->drawFilledRectangle($this->GraphAreaX1 + $FloatingOffset, $LastY, $this->GraphAreaX2 - $FloatingOffset, $YPos, $BGColor);
            }
            if ($DrawYLines == ALL || in_array($AxisID, $DrawYLines)) {
              $this
                ->drawLine($this->GraphAreaX1 + $FloatingOffset, $YPos, $this->GraphAreaX2 - $FloatingOffset, $YPos, array(
                "R" => $GridR,
                "G" => $GridG,
                "B" => $GridB,
                "Alpha" => $GridAlpha,
                "Ticks" => $GridTicks,
              ));
            }
            if ($DrawSubTicks && $i != $Parameters["Rows"]) {
              $this
                ->drawLine($XPos - $OuterSubTickWidth, $YPos - $SubTicksSize, $XPos + $InnerSubTickWidth, $YPos - $SubTicksSize, array(
                "R" => $SubTickR,
                "G" => $SubTickG,
                "B" => $SubTickB,
                "Alpha" => $SubTickAlpha,
              ));
            }
            $this
              ->drawLine($XPos - $OuterTickWidth, $YPos, $XPos + $InnerTickWidth, $YPos, array(
              "R" => $TickR,
              "G" => $TickG,
              "B" => $TickB,
              "Alpha" => $TickAlpha,
            ));
            $Bounds = $this
              ->drawText($XPos - $OuterTickWidth - 2, $YPos, $Value, array(
              "Align" => TEXT_ALIGN_MIDDLERIGHT,
            ));
            $TxtLeft = $XPos - $OuterTickWidth - 2 - ($Bounds[1]["X"] - $Bounds[0]["X"]);
            $MinLeft = min($MinLeft, $TxtLeft);
            $LastY = $YPos;
          }
          if (isset($Parameters["Name"])) {
            $XPos = $MinLeft - 2;
            $YPos = $this->GraphAreaY1 + ($this->GraphAreaY2 - $this->GraphAreaY1) / 2;
            $Bounds = $this
              ->drawText($XPos, $YPos, $Parameters["Name"], array(
              "Align" => TEXT_ALIGN_BOTTOMMIDDLE,
              "Angle" => 90,
            ));
            $MinLeft = $Bounds[2]["X"];
            $this->DataSet->Data["GraphArea"]["X1"] = $MinLeft;
          }
          $AxisPos["L"] = $MinLeft - $ScaleSpacing;
        }
        elseif ($Parameters["Position"] == AXIS_POSITION_RIGHT) {
          if ($Floating) {
            $FloatingOffset = $XMargin;
            $this
              ->drawLine($AxisPos["R"], $this->GraphAreaY1 + $Parameters["Margin"], $AxisPos["R"], $this->GraphAreaY2 - $Parameters["Margin"], array(
              "R" => $AxisR,
              "G" => $AxisG,
              "B" => $AxisB,
              "Alpha" => $AxisAlpha,
            ));
          }
          else {
            $FloatingOffset = 0;
            $this
              ->drawLine($AxisPos["R"], $this->GraphAreaY1, $AxisPos["R"], $this->GraphAreaY2, array(
              "R" => $AxisR,
              "G" => $AxisG,
              "B" => $AxisB,
              "Alpha" => $AxisAlpha,
            ));
          }
          if ($DrawArrows) {
            $this
              ->drawArrow($AxisPos["R"], $this->GraphAreaY1 + $Parameters["Margin"], $AxisPos["R"], $this->GraphAreaY1 - $ArrowSize * 2, array(
              "FillR" => $AxisR,
              "FillG" => $AxisG,
              "FillB" => $AxisB,
              "Size" => $ArrowSize,
            ));
          }
          $Height = $this->GraphAreaY2 - $this->GraphAreaY1 - $Parameters["Margin"] * 2;
          $Step = $Height / $Parameters["Rows"];
          $SubTicksSize = $Step / 2;
          $MaxLeft = $AxisPos["R"];
          $LastY = NULL;
          for ($i = 0; $i <= $Parameters["Rows"]; $i++) {
            $YPos = $this->GraphAreaY2 - $Parameters["Margin"] - $Step * $i;
            $XPos = $AxisPos["R"];
            $Value = $this
              ->scaleFormat($Parameters["ScaleMin"] + $Parameters["RowHeight"] * $i, $Parameters["Display"], $Parameters["Format"], $Parameters["Unit"]);
            if ($i % 2 == 1) {
              $BGColor = array(
                "R" => $BackgroundR1,
                "G" => $BackgroundG1,
                "B" => $BackgroundB1,
                "Alpha" => $BackgroundAlpha1,
              );
            }
            else {
              $BGColor = array(
                "R" => $BackgroundR2,
                "G" => $BackgroundG2,
                "B" => $BackgroundB2,
                "Alpha" => $BackgroundAlpha2,
              );
            }
            if ($LastY != NULL && $CycleBackground && ($DrawYLines == ALL || in_array($AxisID, $DrawYLines))) {
              $this
                ->drawFilledRectangle($this->GraphAreaX1 + $FloatingOffset, $LastY, $this->GraphAreaX2 - $FloatingOffset, $YPos, $BGColor);
            }
            if ($DrawYLines == ALL || in_array($AxisID, $DrawYLines)) {
              $this
                ->drawLine($this->GraphAreaX1 + $FloatingOffset, $YPos, $this->GraphAreaX2 - $FloatingOffset, $YPos, array(
                "R" => $GridR,
                "G" => $GridG,
                "B" => $GridB,
                "Alpha" => $GridAlpha,
                "Ticks" => $GridTicks,
              ));
            }
            if ($DrawSubTicks && $i != $Parameters["Rows"]) {
              $this
                ->drawLine($XPos - $OuterSubTickWidth, $YPos - $SubTicksSize, $XPos + $InnerSubTickWidth, $YPos - $SubTicksSize, array(
                "R" => $SubTickR,
                "G" => $SubTickG,
                "B" => $SubTickB,
                "Alpha" => $SubTickAlpha,
              ));
            }
            $this
              ->drawLine($XPos - $InnerTickWidth, $YPos, $XPos + $OuterTickWidth, $YPos, array(
              "R" => $TickR,
              "G" => $TickG,
              "B" => $TickB,
              "Alpha" => $TickAlpha,
            ));
            $Bounds = $this
              ->drawText($XPos + $OuterTickWidth + 2, $YPos, $Value, array(
              "Align" => TEXT_ALIGN_MIDDLELEFT,
            ));
            $TxtLeft = $XPos + $OuterTickWidth + 2 + ($Bounds[1]["X"] - $Bounds[0]["X"]);
            $MaxLeft = max($MaxLeft, $TxtLeft);
            $LastY = $YPos;
          }
          if (isset($Parameters["Name"])) {
            $XPos = $MaxLeft + 6;
            $YPos = $this->GraphAreaY1 + ($this->GraphAreaY2 - $this->GraphAreaY1) / 2;
            $Bounds = $this
              ->drawText($XPos, $YPos, $Parameters["Name"], array(
              "Align" => TEXT_ALIGN_BOTTOMMIDDLE,
              "Angle" => 270,
            ));
            $MaxLeft = $Bounds[2]["X"];
            $this->DataSet->Data["GraphArea"]["X2"] = $MaxLeft + $this->FontSize;
          }
          $AxisPos["R"] = $MaxLeft + $ScaleSpacing;
        }
      }
      elseif ($Pos == SCALE_POS_TOPBOTTOM) {
        if ($Parameters["Position"] == AXIS_POSITION_TOP) {
          if ($Floating) {
            $FloatingOffset = $XMargin;
            $this
              ->drawLine($this->GraphAreaX1 + $Parameters["Margin"], $AxisPos["T"], $this->GraphAreaX2 - $Parameters["Margin"], $AxisPos["T"], array(
              "R" => $AxisR,
              "G" => $AxisG,
              "B" => $AxisB,
              "Alpha" => $AxisAlpha,
            ));
          }
          else {
            $FloatingOffset = 0;
            $this
              ->drawLine($this->GraphAreaX1, $AxisPos["T"], $this->GraphAreaX2, $AxisPos["T"], array(
              "R" => $AxisR,
              "G" => $AxisG,
              "B" => $AxisB,
              "Alpha" => $AxisAlpha,
            ));
          }
          if ($DrawArrows) {
            $this
              ->drawArrow($this->GraphAreaX2 - $Parameters["Margin"], $AxisPos["T"], $this->GraphAreaX2 + $ArrowSize * 2, $AxisPos["T"], array(
              "FillR" => $AxisR,
              "FillG" => $AxisG,
              "FillB" => $AxisB,
              "Size" => $ArrowSize,
            ));
          }
          $Width = $this->GraphAreaX2 - $this->GraphAreaX1 - $Parameters["Margin"] * 2;
          $Step = $Width / $Parameters["Rows"];
          $SubTicksSize = $Step / 2;
          $MinTop = $AxisPos["T"];
          $LastX = NULL;
          for ($i = 0; $i <= $Parameters["Rows"]; $i++) {
            $XPos = $this->GraphAreaX1 + $Parameters["Margin"] + $Step * $i;
            $YPos = $AxisPos["T"];
            $Value = $this
              ->scaleFormat($Parameters["ScaleMin"] + $Parameters["RowHeight"] * $i, $Parameters["Display"], $Parameters["Format"], $Parameters["Unit"]);
            if ($i % 2 == 1) {
              $BGColor = array(
                "R" => $BackgroundR1,
                "G" => $BackgroundG1,
                "B" => $BackgroundB1,
                "Alpha" => $BackgroundAlpha1,
              );
            }
            else {
              $BGColor = array(
                "R" => $BackgroundR2,
                "G" => $BackgroundG2,
                "B" => $BackgroundB2,
                "Alpha" => $BackgroundAlpha2,
              );
            }
            if ($LastX != NULL && $CycleBackground && ($DrawYLines == ALL || in_array($AxisID, $DrawYLines))) {
              $this
                ->drawFilledRectangle($LastX, $this->GraphAreaY1 + $FloatingOffset, $XPos, $this->GraphAreaY2 - $FloatingOffset, $BGColor);
            }
            if ($DrawYLines == ALL || in_array($AxisID, $DrawYLines)) {
              $this
                ->drawLine($XPos, $this->GraphAreaY1 + $FloatingOffset, $XPos, $this->GraphAreaY2 - $FloatingOffset, array(
                "R" => $GridR,
                "G" => $GridG,
                "B" => $GridB,
                "Alpha" => $GridAlpha,
                "Ticks" => $GridTicks,
              ));
            }
            if ($DrawSubTicks && $i != $Parameters["Rows"]) {
              $this
                ->drawLine($XPos + $SubTicksSize, $YPos - $OuterSubTickWidth, $XPos + $SubTicksSize, $YPos + $InnerSubTickWidth, array(
                "R" => $SubTickR,
                "G" => $SubTickG,
                "B" => $SubTickB,
                "Alpha" => $SubTickAlpha,
              ));
            }
            $this
              ->drawLine($XPos, $YPos - $OuterTickWidth, $XPos, $YPos + $InnerTickWidth, array(
              "R" => $TickR,
              "G" => $TickG,
              "B" => $TickB,
              "Alpha" => $TickAlpha,
            ));
            $Bounds = $this
              ->drawText($XPos, $YPos - $OuterTickWidth - 2, $Value, array(
              "Align" => TEXT_ALIGN_BOTTOMMIDDLE,
            ));
            $TxtHeight = $YPos - $OuterTickWidth - 2 - ($Bounds[1]["Y"] - $Bounds[2]["Y"]);
            $MinTop = min($MinTop, $TxtHeight);
            $LastX = $XPos;
          }
          if (isset($Parameters["Name"])) {
            $YPos = $MinTop - 2;
            $XPos = $this->GraphAreaX1 + ($this->GraphAreaX2 - $this->GraphAreaX1) / 2;
            $Bounds = $this
              ->drawText($XPos, $YPos, $Parameters["Name"], array(
              "Align" => TEXT_ALIGN_BOTTOMMIDDLE,
            ));
            $MinTop = $Bounds[2]["Y"];
            $this->DataSet->Data["GraphArea"]["Y1"] = $MinTop;
          }
          $AxisPos["T"] = $MinTop - $ScaleSpacing;
        }
        elseif ($Parameters["Position"] == AXIS_POSITION_BOTTOM) {
          if ($Floating) {
            $FloatingOffset = $XMargin;
            $this
              ->drawLine($this->GraphAreaX1 + $Parameters["Margin"], $AxisPos["B"], $this->GraphAreaX2 - $Parameters["Margin"], $AxisPos["B"], array(
              "R" => $AxisR,
              "G" => $AxisG,
              "B" => $AxisB,
              "Alpha" => $AxisAlpha,
            ));
          }
          else {
            $FloatingOffset = 0;
            $this
              ->drawLine($this->GraphAreaX1, $AxisPos["B"], $this->GraphAreaX2, $AxisPos["B"], array(
              "R" => $AxisR,
              "G" => $AxisG,
              "B" => $AxisB,
              "Alpha" => $AxisAlpha,
            ));
          }
          if ($DrawArrows) {
            $this
              ->drawArrow($this->GraphAreaX2 - $Parameters["Margin"], $AxisPos["B"], $this->GraphAreaX2 + $ArrowSize * 2, $AxisPos["B"], array(
              "FillR" => $AxisR,
              "FillG" => $AxisG,
              "FillB" => $AxisB,
              "Size" => $ArrowSize,
            ));
          }
          $Width = $this->GraphAreaX2 - $this->GraphAreaX1 - $Parameters["Margin"] * 2;
          $Step = $Width / $Parameters["Rows"];
          $SubTicksSize = $Step / 2;
          $MaxBottom = $AxisPos["B"];
          $LastX = NULL;
          for ($i = 0; $i <= $Parameters["Rows"]; $i++) {
            $XPos = $this->GraphAreaX1 + $Parameters["Margin"] + $Step * $i;
            $YPos = $AxisPos["B"];
            $Value = $this
              ->scaleFormat($Parameters["ScaleMin"] + $Parameters["RowHeight"] * $i, $Parameters["Display"], $Parameters["Format"], $Parameters["Unit"]);
            if ($i % 2 == 1) {
              $BGColor = array(
                "R" => $BackgroundR1,
                "G" => $BackgroundG1,
                "B" => $BackgroundB1,
                "Alpha" => $BackgroundAlpha1,
              );
            }
            else {
              $BGColor = array(
                "R" => $BackgroundR2,
                "G" => $BackgroundG2,
                "B" => $BackgroundB2,
                "Alpha" => $BackgroundAlpha2,
              );
            }
            if ($LastX != NULL && $CycleBackground && ($DrawYLines == ALL || in_array($AxisID, $DrawYLines))) {
              $this
                ->drawFilledRectangle($LastX, $this->GraphAreaY1 + $FloatingOffset, $XPos, $this->GraphAreaY2 - $FloatingOffset, $BGColor);
            }
            if ($DrawYLines == ALL || in_array($AxisID, $DrawYLines)) {
              $this
                ->drawLine($XPos, $this->GraphAreaY1 + $FloatingOffset, $XPos, $this->GraphAreaY2 - $FloatingOffset, array(
                "R" => $GridR,
                "G" => $GridG,
                "B" => $GridB,
                "Alpha" => $GridAlpha,
                "Ticks" => $GridTicks,
              ));
            }
            if ($DrawSubTicks && $i != $Parameters["Rows"]) {
              $this
                ->drawLine($XPos + $SubTicksSize, $YPos - $OuterSubTickWidth, $XPos + $SubTicksSize, $YPos + $InnerSubTickWidth, array(
                "R" => $SubTickR,
                "G" => $SubTickG,
                "B" => $SubTickB,
                "Alpha" => $SubTickAlpha,
              ));
            }
            $this
              ->drawLine($XPos, $YPos - $OuterTickWidth, $XPos, $YPos + $InnerTickWidth, array(
              "R" => $TickR,
              "G" => $TickG,
              "B" => $TickB,
              "Alpha" => $TickAlpha,
            ));
            $Bounds = $this
              ->drawText($XPos, $YPos + $OuterTickWidth + 2, $Value, array(
              "Align" => TEXT_ALIGN_TOPMIDDLE,
            ));
            $TxtHeight = $YPos + $OuterTickWidth + 2 + ($Bounds[1]["Y"] - $Bounds[2]["Y"]);
            $MaxBottom = max($MaxBottom, $TxtHeight);
            $LastX = $XPos;
          }
          if (isset($Parameters["Name"])) {
            $YPos = $MaxBottom + 2;
            $XPos = $this->GraphAreaX1 + ($this->GraphAreaX2 - $this->GraphAreaX1) / 2;
            $Bounds = $this
              ->drawText($XPos, $YPos, $Parameters["Name"], array(
              "Align" => TEXT_ALIGN_TOPMIDDLE,
            ));
            $MaxBottom = $Bounds[0]["Y"];
            $this->DataSet->Data["GraphArea"]["Y2"] = $MaxBottom + $this->FontSize;
          }
          $AxisPos["B"] = $MaxBottom + $ScaleSpacing;
        }
      }
    }
  }
}