Ejemplo n.º 1
0
 /**
  * Create the encoded string
  * @param Image $Object
  * @param string $Value
  * @param int $X
  * @param int $Y
  * @param string $Format
  */
 public function draw(Image $Object, $Value, $X, $Y, $Format = "")
 {
     $this->pChartObject = $Object;
     $R = isset($Format["R"]) ? $Format["R"] : 0;
     $G = isset($Format["G"]) ? $Format["G"] : 0;
     $B = isset($Format["B"]) ? $Format["B"] : 0;
     $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
     $Height = isset($Format["Height"]) ? $Format["Height"] : 30;
     $Angle = isset($Format["Angle"]) ? $Format["Angle"] : 0;
     $ShowLegend = isset($Format["ShowLegend"]) ? $Format["ShowLegend"] : false;
     $LegendOffset = isset($Format["LegendOffset"]) ? $Format["LegendOffset"] : 5;
     $DrawArea = isset($Format["DrawArea"]) ? $Format["DrawArea"] : false;
     $AreaR = isset($Format["AreaR"]) ? $Format["AreaR"] : 255;
     $AreaG = isset($Format["AreaG"]) ? $Format["AreaG"] : 255;
     $AreaB = isset($Format["AreaB"]) ? $Format["AreaB"] : 255;
     $AreaBorderR = isset($Format["AreaBorderR"]) ? $Format["AreaBorderR"] : $AreaR;
     $AreaBorderG = isset($Format["AreaBorderG"]) ? $Format["AreaBorderG"] : $AreaG;
     $AreaBorderB = isset($Format["AreaBorderB"]) ? $Format["AreaBorderB"] : $AreaB;
     $TextString = $this->encode128($Value);
     if ($DrawArea) {
         $X1 = $X + cos(($Angle - 135) * PI / 180) * 10;
         $Y1 = $Y + sin(($Angle - 135) * PI / 180) * 10;
         $X2 = $X1 + cos($Angle * PI / 180) * (strlen($this->Result) + 20);
         $Y2 = $Y1 + sin($Angle * PI / 180) * (strlen($this->Result) + 20);
         if ($ShowLegend) {
             $X3 = $X2 + cos(($Angle + 90) * PI / 180) * ($Height + $LegendOffset + $this->pChartObject->FontSize + 10);
             $Y3 = $Y2 + sin(($Angle + 90) * PI / 180) * ($Height + $LegendOffset + $this->pChartObject->FontSize + 10);
         } else {
             $X3 = $X2 + cos(($Angle + 90) * PI / 180) * ($Height + 20);
             $Y3 = $Y2 + sin(($Angle + 90) * PI / 180) * ($Height + 20);
         }
         $X4 = $X3 + cos(($Angle + 180) * PI / 180) * (strlen($this->Result) + 20);
         $Y4 = $Y3 + sin(($Angle + 180) * PI / 180) * (strlen($this->Result) + 20);
         $Polygon = array($X1, $Y1, $X2, $Y2, $X3, $Y3, $X4, $Y4);
         $Settings = array("R" => $AreaR, "G" => $AreaG, "B" => $AreaB, "BorderR" => $AreaBorderR, "BorderG" => $AreaBorderG, "BorderB" => $AreaBorderB);
         $this->pChartObject->drawPolygon($Polygon, $Settings);
     }
     for ($i = 1; $i <= strlen($this->Result); $i++) {
         if ($this->mid($this->Result, $i, 1) == 1) {
             $X1 = $X + cos($Angle * PI / 180) * $i;
             $Y1 = $Y + sin($Angle * PI / 180) * $i;
             $X2 = $X1 + cos(($Angle + 90) * PI / 180) * $Height;
             $Y2 = $Y1 + sin(($Angle + 90) * PI / 180) * $Height;
             $Settings = array("R" => $R, "G" => $G, "B" => $B, "Alpha" => $Alpha);
             $this->pChartObject->drawLine($X1, $Y1, $X2, $Y2, $Settings);
         }
     }
     if ($ShowLegend) {
         $X1 = $X + cos($Angle * PI / 180) * (strlen($this->Result) / 2);
         $Y1 = $Y + sin($Angle * PI / 180) * (strlen($this->Result) / 2);
         $LegendX = $X1 + cos(($Angle + 90) * PI / 180) * ($Height + $LegendOffset);
         $LegendY = $Y1 + sin(($Angle + 90) * PI / 180) * ($Height + $LegendOffset);
         $Settings = array("R" => $R, "G" => $G, "B" => $B, "Alpha" => $Alpha, "Angle" => -$Angle, "Align" => TEXT_ALIGN_TOPMIDDLE);
         $this->pChartObject->drawText($LegendX, $LegendY, $TextString, $Settings);
     }
 }
Ejemplo n.º 2
0
 /**
  * @param Image $image
  */
 public function setSplineData(Image $image)
 {
     $coordinates = array(array(40, 80), array(280, 60), array(340, 166), array(590, 120));
     $settings = array("R" => 255, "G" => 255, "B" => 255, "ShowControl" => true);
     $image->drawSpline($coordinates, $settings);
 }
Ejemplo n.º 3
0
 /**
  * @Given I render the chart of type :chart
  */
 public function iRenderTheChartOfType(Image $chart)
 {
     $chart->Render($this->getFilePath("example.png"));
 }
Ejemplo n.º 4
0
 /**
  * Draw a Scatter threshold area
  * @param int | float $Value1
  * @param int | float $Value2
  * @param array $Format
  * @return type
  */
 public function drawScatterThresholdArea($Value1, $Value2, array $Format = array())
 {
     $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"] : 20;
     $Border = isset($Format["Border"]) ? $Format["Border"] : true;
     $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : $R;
     $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : $G;
     $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : $B;
     $BorderAlpha = isset($Format["BorderAlpha"]) ? $Format["BorderAlpha"] : $Alpha + 20;
     $BorderTicks = isset($Format["BorderTicks"]) ? $Format["BorderTicks"] : 2;
     $AreaName = isset($Format["AreaName"]) ? $Format["AreaName"] : "La ouate de phoque";
     //null;
     $NameAngle = isset($Format["NameAngle"]) ? $Format["NameAngle"] : ZONE_NAME_ANGLE_AUTO;
     $NameR = isset($Format["NameR"]) ? $Format["NameR"] : 255;
     $NameG = isset($Format["NameG"]) ? $Format["NameG"] : 255;
     $NameB = isset($Format["NameB"]) ? $Format["NameB"] : 255;
     $NameAlpha = isset($Format["NameAlpha"]) ? $Format["NameAlpha"] : 100;
     $DisableShadowOnArea = isset($Format["DisableShadowOnArea"]) ? $Format["DisableShadowOnArea"] : true;
     if ($Value1 > $Value2) {
         list($Value1, $Value2) = array($Value2, $Value1);
     }
     $RestoreShadow = $this->pChartObject->Shadow;
     if ($DisableShadowOnArea && $this->pChartObject->Shadow) {
         $this->pChartObject->Shadow = false;
     }
     if ($BorderAlpha > 100) {
         $BorderAlpha = 100;
     }
     $Data = $this->pDataObject->getData();
     if (!isset($Data["Axis"][$AxisID])) {
         return -1;
     }
     if ($Data["Axis"][$AxisID]["Identity"] == AXIS_X) {
         $Y1 = $this->pChartObject->GraphAreaY1 + $Data["Axis"][$AxisID]["Margin"];
         $Y2 = $this->pChartObject->GraphAreaY2 - $Data["Axis"][$AxisID]["Margin"];
         $X1 = $this->getPosArray($Value1, $AxisID);
         $X2 = $this->getPosArray($Value2, $AxisID);
         if ($X1 <= $this->pChartObject->GraphAreaX1) {
             $X1 = $this->pChartObject->GraphAreaX1 + $Data["Axis"][$AxisID]["Margin"];
         }
         if ($X2 >= $this->pChartObject->GraphAreaX2) {
             $X2 = $this->pChartObject->GraphAreaX2 - $Data["Axis"][$AxisID]["Margin"];
         }
         $this->pChartObject->drawFilledRectangle($X1, $Y1, $X2, $Y2, array("R" => $R, "G" => $G, "B" => $B, "Alpha" => $Alpha));
         if ($Border) {
             $this->pChartObject->drawLine($X1, $Y1, $X1, $Y2, array("R" => $BorderR, "G" => $BorderG, "B" => $BorderB, "Alpha" => $BorderAlpha, "Ticks" => $BorderTicks));
             $this->pChartObject->drawLine($X2, $Y1, $X2, $Y2, array("R" => $BorderR, "G" => $BorderG, "B" => $BorderB, "Alpha" => $BorderAlpha, "Ticks" => $BorderTicks));
         }
         if ($AreaName != null) {
             $XPos = ($X2 - $X1) / 2 + $X1;
             $YPos = ($Y2 - $Y1) / 2 + $Y1;
             if ($NameAngle == ZONE_NAME_ANGLE_AUTO) {
                 $TxtPos = $this->pChartObject->getTextBox($XPos, $YPos, $this->pChartObject->FontName, $this->pChartObject->FontSize, 0, $AreaName);
                 $TxtWidth = $TxtPos[1]["X"] - $TxtPos[0]["X"];
                 if (abs($X2 - $X1) > $TxtWidth) {
                     $NameAngle = 0;
                 } else {
                     $NameAngle = 90;
                 }
             }
             $this->pChartObject->Shadow = $RestoreShadow;
             $this->pChartObject->drawText($XPos, $YPos, $AreaName, array("R" => $NameR, "G" => $NameG, "B" => $NameB, "Alpha" => $NameAlpha, "Angle" => $NameAngle, "Align" => TEXT_ALIGN_MIDDLEMIDDLE));
             if ($DisableShadowOnArea) {
                 $this->pChartObject->Shadow = false;
             }
         }
         $this->pChartObject->Shadow = $RestoreShadow;
         return array("X1" => $X1, "X2" => $X2);
     } elseif ($Data["Axis"][$AxisID]["Identity"] == AXIS_Y) {
         $X1 = $this->pChartObject->GraphAreaX1 + $Data["Axis"][$AxisID]["Margin"];
         $X2 = $this->pChartObject->GraphAreaX2 - $Data["Axis"][$AxisID]["Margin"];
         $Y1 = $this->getPosArray($Value1, $AxisID);
         $Y2 = $this->getPosArray($Value2, $AxisID);
         if ($Y1 >= $this->pChartObject->GraphAreaY2) {
             $Y1 = $this->pChartObject->GraphAreaY2 - $Data["Axis"][$AxisID]["Margin"];
         }
         if ($Y2 <= $this->pChartObject->GraphAreaY1) {
             $Y2 = $this->pChartObject->GraphAreaY1 + $Data["Axis"][$AxisID]["Margin"];
         }
         $this->pChartObject->drawFilledRectangle($X1, $Y1, $X2, $Y2, array("R" => $R, "G" => $G, "B" => $B, "Alpha" => $Alpha));
         if ($Border) {
             $this->pChartObject->drawLine($X1, $Y1, $X2, $Y1, array("R" => $BorderR, "G" => $BorderG, "B" => $BorderB, "Alpha" => $BorderAlpha, "Ticks" => $BorderTicks));
             $this->pChartObject->drawLine($X1, $Y2, $X2, $Y2, array("R" => $BorderR, "G" => $BorderG, "B" => $BorderB, "Alpha" => $BorderAlpha, "Ticks" => $BorderTicks));
         }
         if ($AreaName != null) {
             $XPos = ($X2 - $X1) / 2 + $X1;
             $YPos = ($Y2 - $Y1) / 2 + $Y1;
             $this->pChartObject->Shadow = $RestoreShadow;
             $this->pChartObject->drawText($YPos, $XPos, $AreaName, array("R" => $NameR, "G" => $NameG, "B" => $NameB, "Alpha" => $NameAlpha, "Angle" => 0, "Align" => TEXT_ALIGN_MIDDLEMIDDLE));
             if ($DisableShadowOnArea) {
                 $this->Shadow = false;
             }
         }
         $this->pChartObject->Shadow = $RestoreShadow;
         return array("Y1" => $Y1, "Y2" => $Y2);
     }
 }