/**
  * Compute and draw the scale for X/Y charts
  */
 function drawXYScale(pData $Data, ScaleStyle $style, $YSerieName, $XSerieName, $Angle = 0, $Decimals = 1)
 {
     /* Validate the Data and DataDescription array */
     $this->validateData("drawScale", $Data->getData());
     $this->canvas->drawLine(new Point($this->GArea_X1, $this->GArea_Y1), new Point($this->GArea_X1, $this->GArea_Y2), $style->getColor(), $style->getLineWidth(), $style->getLineDotSize(), $this->shadowProperties);
     $this->canvas->drawLine(new Point($this->GArea_X1, $this->GArea_Y2), new Point($this->GArea_X2, $this->GArea_Y2), $style->getColor(), $style->getLineWidth(), $style->getLineDotSize(), $this->shadowProperties);
     /* Process Y scale */
     if ($this->VMin == NULL && $this->VMax == NULL) {
         $this->VMin = $Data->getSeriesMin($YSerieName);
         $this->VMax = $Data->getSeriesMax($YSerieName);
         /** @todo The use of ceil() here is questionable if all
          * the values are much less than 1, AIUI */
         $this->VMax = ceil($this->VMax);
         $DataRange = $this->VMax - $this->VMin;
         if ($DataRange == 0) {
             $DataRange = 0.1;
         }
         self::computeAutomaticScaling($this->GArea_Y1, $this->GArea_Y2, $this->VMin, $this->VMax, $Divisions);
     } else {
         $Divisions = $this->Divisions;
     }
     $this->DivisionCount = $Divisions;
     $DataRange = $this->VMax - $this->VMin;
     if ($DataRange == 0) {
         $DataRange = 0.1;
     }
     $this->DivisionHeight = ($this->GArea_Y2 - $this->GArea_Y1) / $Divisions;
     $this->DivisionRatio = ($this->GArea_Y2 - $this->GArea_Y1) / $DataRange;
     $YPos = $this->GArea_Y2;
     $XMin = NULL;
     for ($i = 1; $i <= $Divisions + 1; $i++) {
         $this->canvas->drawLine(new Point($this->GArea_X1, $YPos), new Point($this->GArea_X1 - 5, $YPos), $style->getColor(), $style->getLineWidth(), $style->getLineDotSize(), $this->shadowProperties);
         $Value = $this->VMin + ($i - 1) * (($this->VMax - $this->VMin) / $Divisions);
         $Value = round($Value * pow(10, $Decimals)) / pow(10, $Decimals);
         $Value = $this->convertValueForDisplay($Value, $Data->getDataDescription()->getYFormat(), $Data->getDataDescription()->getYUnit());
         $Position = imageftbbox($this->FontSize, 0, $this->FontName, $Value);
         $TextWidth = $Position[2] - $Position[0];
         $this->canvas->drawText($this->FontSize, 0, new Point($this->GArea_X1 - 10 - $TextWidth, $YPos + $this->FontSize / 2), $style->getColor(), $this->FontName, $Value, $this->shadowProperties);
         if ($XMin > $this->GArea_X1 - 10 - $TextWidth || $XMin == NULL) {
             $XMin = $this->GArea_X1 - 10 - $TextWidth;
         }
         $YPos = $YPos - $this->DivisionHeight;
     }
     /* Process X scale */
     if ($this->VXMin == NULL && $this->VXMax == NULL) {
         $this->VXMax = $Data->getSeriesMax($XSerieName);
         $this->VXMin = $Data->getSeriesMin($XSerieName);
         $this->VXMax = ceil($this->VXMax);
         $DataRange = $this->VMax - $this->VMin;
         if ($DataRange == 0) {
             $DataRange = 0.1;
         }
         /* Compute automatic scaling */
         self::computeAutomaticScaling($this->GArea_X1, $this->GArea_X2, $this->VXMin, $this->VXMax, $XDivisions);
     } else {
         $XDivisions = $this->XDivisions;
     }
     $this->XDivisionCount = $Divisions;
     $this->DataCount = $Divisions + 2;
     $XDataRange = $this->VXMax - $this->VXMin;
     if ($XDataRange == 0) {
         $XDataRange = 0.1;
     }
     $this->DivisionWidth = ($this->GArea_X2 - $this->GArea_X1) / $XDivisions;
     $this->XDivisionRatio = ($this->GArea_X2 - $this->GArea_X1) / $XDataRange;
     $XPos = $this->GArea_X1;
     $YMax = NULL;
     for ($i = 1; $i <= $XDivisions + 1; $i++) {
         $this->canvas->drawLine(new Point($XPos, $this->GArea_Y2), new Point($XPos, $this->GArea_Y2 + 5), $style->getColor(), $style->getLineWidth(), $style->getLineDotSize(), $this->shadowProperties);
         $Value = $this->VXMin + ($i - 1) * (($this->VXMax - $this->VXMin) / $XDivisions);
         $Value = round($Value * pow(10, $Decimals)) / pow(10, $Decimals);
         $Value = $this->convertValueForDisplay($Value, $Data->getDataDescription()->getYFormat(), $Data->getDataDescription()->getYUnit());
         $Position = imageftbbox($this->FontSize, $Angle, $this->FontName, $Value);
         $TextWidth = abs($Position[2]) + abs($Position[0]);
         $TextHeight = abs($Position[1]) + abs($Position[3]);
         if ($Angle == 0) {
             $YPos = $this->GArea_Y2 + 18;
             $this->canvas->drawText($this->FontSize, $Angle, new Point(floor($XPos) - floor($TextWidth / 2), $YPos), $style->getColor(), $this->FontName, $Value, $this->shadowProperties);
         } else {
             $YPos = $this->GArea_Y2 + 10 + $TextHeight;
             if ($Angle <= 90) {
                 $this->canvas->drawText($this->FontSize, $Angle, new Point(floor($XPos) - $TextWidth + 5, $YPos), $style->getColor(), $this->FontName, $Value, $this->shadowProperties);
             } else {
                 $this->canvas->drawText($this->FontSize, $Angle, new Point(floor($XPos) + $TextWidth + 5, $YPos), $style->getColor(), $this->FontName, $Value, $this->shadowProperties);
             }
         }
         if ($YMax < $YPos || $YMax == NULL) {
             $YMax = $YPos;
         }
         $XPos = $XPos + $this->DivisionWidth;
     }
     /* Write the Y Axis caption if set */
     if ($Data->getDataDescription()->getYAxisName() != '') {
         $Position = imageftbbox($this->FontSize, 90, $this->FontName, $Data->getDataDescription()->getYAxisName());
         $TextHeight = abs($Position[1]) + abs($Position[3]);
         $TextTop = ($this->GArea_Y2 - $this->GArea_Y1) / 2 + $this->GArea_Y1 + $TextHeight / 2;
         $this->canvas->drawText($this->FontSize, 90, new Point($XMin - $this->FontSize, $TextTop), $style->getColor(), $this->FontName, $Data->getDataDescription()->getYAxisName(), $this->shadowProperties);
     }
     /* Write the X Axis caption if set */
     $this->writeScaleXAxisCaption($Data, $style, $YMax);
 }