Пример #1
0
 /**
  * Draw the data legends 
  * @param int X-Position
  * @param int Y-Position
  * @param array Data pData->getData
  * @param array DataDescription pData->getDataDescription
  * @param Color
  * @param ShadowProperties
  * @access public
  */
 public function drawPieLegend($XPos, $YPos, $Data, $DataDescription, Color $color, ShadowProperties $shadowProperties = null)
 {
     if ($shadowProperties == null) {
         $shadowProperties = ShadowProperties::FromDefaults();
     }
     /* Validate the Data and DataDescription array */
     $this->validateDataDescription("drawPieLegend", $DataDescription, FALSE);
     $this->validateData("drawPieLegend", $Data);
     if ($DataDescription->getPosition() == '') {
         return -1;
     }
     /* <-10->[8]<-4->Text<-10-> */
     $MaxWidth = 0;
     $MaxHeight = 8;
     foreach ($Data as $Key => $Value) {
         $Value2 = $Value[$DataDescription->getPosition()];
         $Position = imageftbbox($this->FontSize, 0, $this->FontName, $Value2);
         $TextWidth = $Position[2] - $Position[0];
         $TextHeight = $Position[1] - $Position[7];
         if ($TextWidth > $MaxWidth) {
             $MaxWidth = $TextWidth;
         }
         $MaxHeight = $MaxHeight + $TextHeight + 4;
     }
     $MaxHeight = $MaxHeight - 3;
     $MaxWidth = $MaxWidth + 32;
     $this->canvas->drawFilledRoundedRectangle(new Point($XPos + 1, $YPos + 1), new Point($XPos + $MaxWidth + 1, $YPos + $MaxHeight + 1), 5, $color->addRGBIncrement(-30), $this->LineWidth, $this->LineDotSize, $shadowProperties);
     $this->canvas->drawFilledRoundedRectangle(new Point($XPos, $YPos), new Point($XPos + $MaxWidth, $YPos + $MaxHeight), 5, $color, $this->LineWidth, $this->LineDotSize, $shadowProperties);
     $YOffset = 4 + $this->FontSize;
     $ID = 0;
     foreach ($Data as $Key => $Value) {
         $Value2 = $Value[$DataDescription->getPosition()];
         $Position = imageftbbox($this->FontSize, 0, $this->FontName, $Value2);
         $TextHeight = $Position[1] - $Position[7];
         $this->canvas->drawFilledRectangle(new Point($XPos + 10, $YPos + $YOffset - 6), new Point($XPos + 14, $YPos + $YOffset - 2), $this->palette->colors[$ID], $shadowProperties);
         $this->canvas->drawText($this->FontSize, 0, new Point($XPos + 22, $YPos + $YOffset), new Color(0, 0, 0), $this->FontName, $Value2, $shadowProperties);
         $YOffset = $YOffset + $TextHeight + 4;
         $ID++;
     }
 }
 /**
  * This function put a label on a specific point
  */
 function setLabel($Data, $DataDescription, $SerieName, $ValueName, $Caption, Color $color = null)
 {
     if ($color == null) {
         $color = new Color(210, 210, 210);
     }
     /* Validate the Data and DataDescription array */
     $this->validateDataDescription("setLabel", $DataDescription);
     $this->validateData("setLabel", $Data);
     $ShadowFactor = 100;
     $Cp = 0;
     $Found = FALSE;
     foreach ($Data as $Value) {
         if ($Value[$DataDescription->getPosition()] == $ValueName) {
             $NumericalValue = $Value[$SerieName];
             $Found = TRUE;
         }
         if (!$Found) {
             $Cp++;
         }
     }
     $XPos = $this->GArea_X1 + $this->GAreaXOffset + $this->DivisionWidth * $Cp + 2;
     $YPos = $this->GArea_Y2 - ($NumericalValue - $this->VMin) * $this->DivisionRatio;
     $Position = imageftbbox($this->FontSize, 0, $this->FontName, $Caption);
     $TextHeight = $Position[3] - $Position[5];
     $TextWidth = $Position[2] - $Position[0] + 2;
     $TextOffset = floor($TextHeight / 2);
     // Shadow
     $Poly = array($XPos + 1, $YPos + 1, $XPos + 9, $YPos - $TextOffset, $XPos + 8, $YPos + $TextOffset + 2);
     $this->canvas->drawFilledPolygon($Poly, 3, $color->addRGBIncrement(-$ShadowFactor));
     $this->canvas->drawLine(new Point($XPos, $YPos + 1), new Point($XPos + 9, $YPos - $TextOffset - 0.2), $color->addRGBIncrement(-$ShadowFactor), $this->LineWidth, $this->LineDotSize, $this->shadowProperties);
     $this->canvas->drawLine(new Point($XPos, $YPos + 1), new Point($XPos + 9, $YPos + $TextOffset + 2.2), $color->addRGBIncrement(-$ShadowFactor), $this->LineWidth, $this->LineDotSize, $this->shadowProperties);
     $this->canvas->drawFilledRectangle(new Point($XPos + 9, $YPos - $TextOffset - 0.2), new Point($XPos + 13 + $TextWidth, $YPos + $TextOffset + 2.2), $color->addRGBIncrement(-$ShadowFactor), $this->shadowProperties);
     // Label background
     $Poly = array($XPos, $YPos, $XPos + 8, $YPos - $TextOffset - 1, $XPos + 8, $YPos + $TextOffset + 1);
     $this->canvas->drawFilledPolygon($Poly, 3, $color);
     /** @todo We draw exactly the same line twice, with the same settings.
      * Surely this is pointless? */
     $this->canvas->drawLine(new Point($XPos - 1, $YPos), new Point($XPos + 8, $YPos - $TextOffset - 1.2), $color, $this->LineWidth, $this->LineDotSize, $this->shadowProperties);
     $this->canvas->drawLine(new Point($XPos - 1, $YPos), new Point($XPos + 8, $YPos + $TextOffset + 1.2), $color, $this->LineWidth, $this->LineDotSize, $this->shadowProperties);
     $this->canvas->drawFilledRectangle(new Point($XPos + 8, $YPos - $TextOffset - 1.2), new Point($XPos + 12 + $TextWidth, $YPos + $TextOffset + 1.2), $color, $this->shadowProperties);
     $this->canvas->drawText($this->FontSize, 0, new Point($XPos + 10, $YPos + $TextOffset), new Color(0, 0, 0), $this->FontName, $Caption, ShadowProperties::NoShadow());
 }