Exemplo n.º 1
0
 /**
  * Write Max value on a chart
  * @param int $Type
  * @param array $Format
  */
 public function writeBounds($Type = BOUND_BOTH, $Format = null)
 {
     $MaxLabelTxt = isset($Format["MaxLabelTxt"]) ? $Format["MaxLabelTxt"] : "max=";
     $MinLabelTxt = isset($Format["MinLabelTxt"]) ? $Format["MinLabelTxt"] : "min=";
     $Decimals = isset($Format["Decimals"]) ? $Format["Decimals"] : 1;
     $ExcludedSeries = isset($Format["ExcludedSeries"]) ? $Format["ExcludedSeries"] : "";
     $DisplayOffset = isset($Format["DisplayOffset"]) ? $Format["DisplayOffset"] : 4;
     $DisplayColor = isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
     $MaxDisplayR = isset($Format["MaxDisplayR"]) ? $Format["MaxDisplayR"] : 0;
     $MaxDisplayG = isset($Format["MaxDisplayG"]) ? $Format["MaxDisplayG"] : 0;
     $MaxDisplayB = isset($Format["MaxDisplayB"]) ? $Format["MaxDisplayB"] : 0;
     $MinDisplayR = isset($Format["MinDisplayR"]) ? $Format["MinDisplayR"] : 255;
     $MinDisplayG = isset($Format["MinDisplayG"]) ? $Format["MinDisplayG"] : 255;
     $MinDisplayB = isset($Format["MinDisplayB"]) ? $Format["MinDisplayB"] : 255;
     $MinLabelPos = isset($Format["MinLabelPos"]) ? $Format["MinLabelPos"] : BOUND_LABEL_POS_AUTO;
     $MaxLabelPos = isset($Format["MaxLabelPos"]) ? $Format["MaxLabelPos"] : BOUND_LABEL_POS_AUTO;
     $DrawBox = isset($Format["DrawBox"]) ? $Format["DrawBox"] : true;
     $DrawBoxBorder = isset($Format["DrawBoxBorder"]) ? $Format["DrawBoxBorder"] : false;
     $BorderOffset = isset($Format["BorderOffset"]) ? $Format["BorderOffset"] : 5;
     $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"] : 20;
     $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;
     $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);
     list($XMargin, $XDivs) = $this->scaleGetXSettings();
     $Data = $this->DataSet->getData();
     foreach ($Data["Series"] as $SerieName => $Serie) {
         if ($Serie["isDrawable"] == true && $SerieName != $Data["Abscissa"] && !isset($ExcludedSeries[$SerieName])) {
             $R = $Serie["Color"]["R"];
             $G = $Serie["Color"]["G"];
             $B = $Serie["Color"]["B"];
             $MinValue = $this->DataSet->getMin($SerieName);
             $MaxValue = $this->DataSet->getMax($SerieName);
             $MinPos = VOID;
             $MaxPos = VOID;
             foreach ($Serie["Data"] as $Key => $Value) {
                 if ($Value == $MinValue && $MinPos == VOID) {
                     $MinPos = $Key;
                 }
                 if ($Value == $MaxValue) {
                     $MaxPos = $Key;
                 }
             }
             $AxisID = $Serie["Axis"];
             $Mode = $Data["Axis"][$AxisID]["Display"];
             $Format = $Data["Axis"][$AxisID]["Format"];
             $Unit = $Data["Axis"][$AxisID]["Unit"];
             $PosArray = $this->scaleComputeY($Serie["Data"], array("AxisID" => $Serie["Axis"]));
             if ($Data["Orientation"] == SCALE_POS_LEFTRIGHT) {
                 $XStep = ($this->GraphAreaX2 - $this->GraphAreaX1 - $XMargin * 2) / $XDivs;
                 $X = $this->GraphAreaX1 + $XMargin;
                 $SerieOffset = isset($Serie["XOffset"]) ? $Serie["XOffset"] : 0;
                 if ($Type == BOUND_MAX || $Type == BOUND_BOTH) {
                     if ($MaxLabelPos == BOUND_LABEL_POS_TOP || $MaxLabelPos == BOUND_LABEL_POS_AUTO && $MaxValue >= 0) {
                         $YPos = $PosArray[$MaxPos] - $DisplayOffset + 2;
                         $Align = TEXT_ALIGN_BOTTOMMIDDLE;
                     }
                     if ($MaxLabelPos == BOUND_LABEL_POS_BOTTOM || $MaxLabelPos == BOUND_LABEL_POS_AUTO && $MaxValue < 0) {
                         $YPos = $PosArray[$MaxPos] + $DisplayOffset + 2;
                         $Align = TEXT_ALIGN_TOPMIDDLE;
                     }
                     $XPos = $X + $MaxPos * $XStep + $SerieOffset;
                     $Label = sprintf('%s%s', $MaxLabelTxt, $this->scaleFormat(round($MaxValue, $Decimals), $Mode, $Format, $Unit));
                     $TxtPos = $this->getTextBox($XPos, $YPos, $this->FontName, $this->FontSize, 0, $Label);
                     $XOffset = 0;
                     $YOffset = 0;
                     if ($TxtPos[0]["X"] < $this->GraphAreaX1) {
                         $XOffset = ($this->GraphAreaX1 - $TxtPos[0]["X"]) / 2;
                     }
                     if ($TxtPos[1]["X"] > $this->GraphAreaX2) {
                         $XOffset = -(($TxtPos[1]["X"] - $this->GraphAreaX2) / 2);
                     }
                     if ($TxtPos[2]["Y"] < $this->GraphAreaY1) {
                         $YOffset = $this->GraphAreaY1 - $TxtPos[2]["Y"];
                     }
                     if ($TxtPos[0]["Y"] > $this->GraphAreaY2) {
                         $YOffset = -($TxtPos[0]["Y"] - $this->GraphAreaY2);
                     }
                     $CaptionSettings["R"] = $MaxDisplayR;
                     $CaptionSettings["G"] = $MaxDisplayG;
                     $CaptionSettings["B"] = $MaxDisplayB;
                     $CaptionSettings["Align"] = $Align;
                     $this->drawText($XPos + $XOffset, $YPos + $YOffset, $Label, $CaptionSettings);
                 }
                 if ($Type == BOUND_MIN || $Type == BOUND_BOTH) {
                     if ($MinLabelPos == BOUND_LABEL_POS_TOP || $MinLabelPos == BOUND_LABEL_POS_AUTO && $MinValue >= 0) {
                         $YPos = $PosArray[$MinPos] - $DisplayOffset + 2;
                         $Align = TEXT_ALIGN_BOTTOMMIDDLE;
                     }
                     if ($MinLabelPos == BOUND_LABEL_POS_BOTTOM || $MinLabelPos == BOUND_LABEL_POS_AUTO && $MinValue < 0) {
                         $YPos = $PosArray[$MinPos] + $DisplayOffset + 2;
                         $Align = TEXT_ALIGN_TOPMIDDLE;
                     }
                     $XPos = $X + $MinPos * $XStep + $SerieOffset;
                     $Label = sprintf('%s%s', $MinLabelTxt, $this->scaleFormat(round($MinValue, $Decimals), $Mode, $Format, $Unit));
                     $TxtPos = $this->getTextBox($XPos, $YPos, $this->FontName, $this->FontSize, 0, $Label);
                     $XOffset = 0;
                     $YOffset = 0;
                     if ($TxtPos[0]["X"] < $this->GraphAreaX1) {
                         $XOffset = ($this->GraphAreaX1 - $TxtPos[0]["X"]) / 2;
                     }
                     if ($TxtPos[1]["X"] > $this->GraphAreaX2) {
                         $XOffset = -(($TxtPos[1]["X"] - $this->GraphAreaX2) / 2);
                     }
                     if ($TxtPos[2]["Y"] < $this->GraphAreaY1) {
                         $YOffset = $this->GraphAreaY1 - $TxtPos[2]["Y"];
                     }
                     if ($TxtPos[0]["Y"] > $this->GraphAreaY2) {
                         $YOffset = -($TxtPos[0]["Y"] - $this->GraphAreaY2);
                     }
                     $CaptionSettings["R"] = $MinDisplayR;
                     $CaptionSettings["G"] = $MinDisplayG;
                     $CaptionSettings["B"] = $MinDisplayB;
                     $CaptionSettings["Align"] = $Align;
                     $this->drawText($XPos + $XOffset, $YPos - $DisplayOffset + $YOffset, $Label, $CaptionSettings);
                 }
             } else {
                 $XStep = ($this->GraphAreaY2 - $this->GraphAreaY1 - $XMargin * 2) / $XDivs;
                 $X = $this->GraphAreaY1 + $XMargin;
                 $SerieOffset = isset($Serie["XOffset"]) ? $Serie["XOffset"] : 0;
                 if ($Type == BOUND_MAX || $Type == BOUND_BOTH) {
                     if ($MaxLabelPos == BOUND_LABEL_POS_TOP || $MaxLabelPos == BOUND_LABEL_POS_AUTO && $MaxValue >= 0) {
                         $YPos = $PosArray[$MaxPos] + $DisplayOffset + 2;
                         $Align = TEXT_ALIGN_MIDDLELEFT;
                     }
                     if ($MaxLabelPos == BOUND_LABEL_POS_BOTTOM || $MaxLabelPos == BOUND_LABEL_POS_AUTO && $MaxValue < 0) {
                         $YPos = $PosArray[$MaxPos] - $DisplayOffset + 2;
                         $Align = TEXT_ALIGN_MIDDLERIGHT;
                     }
                     $XPos = $X + $MaxPos * $XStep + $SerieOffset;
                     $Label = $MaxLabelTxt . $this->scaleFormat($MaxValue, $Mode, $Format, $Unit);
                     $TxtPos = $this->getTextBox($YPos, $XPos, $this->FontName, $this->FontSize, 0, $Label);
                     $XOffset = 0;
                     $YOffset = 0;
                     if ($TxtPos[0]["X"] < $this->GraphAreaX1) {
                         $XOffset = $this->GraphAreaX1 - $TxtPos[0]["X"];
                     }
                     if ($TxtPos[1]["X"] > $this->GraphAreaX2) {
                         $XOffset = -($TxtPos[1]["X"] - $this->GraphAreaX2);
                     }
                     if ($TxtPos[2]["Y"] < $this->GraphAreaY1) {
                         $YOffset = ($this->GraphAreaY1 - $TxtPos[2]["Y"]) / 2;
                     }
                     if ($TxtPos[0]["Y"] > $this->GraphAreaY2) {
                         $YOffset = -(($TxtPos[0]["Y"] - $this->GraphAreaY2) / 2);
                     }
                     $CaptionSettings["R"] = $MaxDisplayR;
                     $CaptionSettings["G"] = $MaxDisplayG;
                     $CaptionSettings["B"] = $MaxDisplayB;
                     $CaptionSettings["Align"] = $Align;
                     $this->drawText($YPos + $XOffset, $XPos + $YOffset, $Label, $CaptionSettings);
                 }
                 if ($Type == BOUND_MIN || $Type == BOUND_BOTH) {
                     if ($MinLabelPos == BOUND_LABEL_POS_TOP || $MinLabelPos == BOUND_LABEL_POS_AUTO && $MinValue >= 0) {
                         $YPos = $PosArray[$MinPos] + $DisplayOffset + 2;
                         $Align = TEXT_ALIGN_MIDDLELEFT;
                     }
                     if ($MinLabelPos == BOUND_LABEL_POS_BOTTOM || $MinLabelPos == BOUND_LABEL_POS_AUTO && $MinValue < 0) {
                         $YPos = $PosArray[$MinPos] - $DisplayOffset + 2;
                         $Align = TEXT_ALIGN_MIDDLERIGHT;
                     }
                     $XPos = $X + $MinPos * $XStep + $SerieOffset;
                     $Label = $MinLabelTxt . $this->scaleFormat($MinValue, $Mode, $Format, $Unit);
                     $TxtPos = $this->getTextBox($YPos, $XPos, $this->FontName, $this->FontSize, 0, $Label);
                     $XOffset = 0;
                     $YOffset = 0;
                     if ($TxtPos[0]["X"] < $this->GraphAreaX1) {
                         $XOffset = $this->GraphAreaX1 - $TxtPos[0]["X"];
                     }
                     if ($TxtPos[1]["X"] > $this->GraphAreaX2) {
                         $XOffset = -($TxtPos[1]["X"] - $this->GraphAreaX2);
                     }
                     if ($TxtPos[2]["Y"] < $this->GraphAreaY1) {
                         $YOffset = ($this->GraphAreaY1 - $TxtPos[2]["Y"]) / 2;
                     }
                     if ($TxtPos[0]["Y"] > $this->GraphAreaY2) {
                         $YOffset = -(($TxtPos[0]["Y"] - $this->GraphAreaY2) / 2);
                     }
                     $CaptionSettings["R"] = $MinDisplayR;
                     $CaptionSettings["G"] = $MinDisplayG;
                     $CaptionSettings["B"] = $MinDisplayB;
                     $CaptionSettings["Align"] = $Align;
                     $this->drawText($YPos + $XOffset, $XPos + $YOffset, $Label, $CaptionSettings);
                 }
             }
         }
     }
 }