示例#1
0
 /**
  * Draw the legend of the active series
  * @param int $X
  * @param int $Y
  * @param array $Format
  */
 public function drawScatterLegend($X, $Y, array $Format = array())
 {
     $Family = isset($Format["Family"]) ? $Format["Family"] : LEGEND_FAMILY_BOX;
     $FontName = isset($Format["FontName"]) ? $Format["FontName"] : $this->pChartObject->FontName;
     $FontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : $this->pChartObject->FontSize;
     $FontR = isset($Format["FontR"]) ? $Format["FontR"] : $this->pChartObject->FontColorR;
     $FontG = isset($Format["FontG"]) ? $Format["FontG"] : $this->pChartObject->FontColorG;
     $FontB = isset($Format["FontB"]) ? $Format["FontB"] : $this->pChartObject->FontColorB;
     $BoxWidth = isset($Format["BoxWidth"]) ? $Format["BoxWidth"] : 5;
     $BoxHeight = isset($Format["BoxHeight"]) ? $Format["BoxHeight"] : 5;
     $IconAreaWidth = isset($Format["IconAreaWidth"]) ? $Format["IconAreaWidth"] : $BoxWidth;
     $IconAreaHeight = isset($Format["IconAreaHeight"]) ? $Format["IconAreaHeight"] : $BoxHeight;
     $XSpacing = isset($Format["XSpacing"]) ? $Format["XSpacing"] : 5;
     $Margin = isset($Format["Margin"]) ? $Format["Margin"] : 5;
     $R = isset($Format["R"]) ? $Format["R"] : 200;
     $G = isset($Format["G"]) ? $Format["G"] : 200;
     $B = isset($Format["B"]) ? $Format["B"] : 200;
     $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
     $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : 255;
     $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : 255;
     $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : 255;
     $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : null;
     $Style = isset($Format["Style"]) ? $Format["Style"] : LEGEND_ROUND;
     $Mode = isset($Format["Mode"]) ? $Format["Mode"] : LEGEND_VERTICAL;
     if ($Surrounding != null) {
         $BorderR = $R + $Surrounding;
         $BorderG = $G + $Surrounding;
         $BorderB = $B + $Surrounding;
     }
     $Data = $this->pDataObject->getData();
     foreach ($Data["ScatterSeries"] as $Key => $Series) {
         if ($Series["isDrawable"] == true && isset($Series["Picture"])) {
             list($PicWidth, $PicHeight) = $this->pChartObject->getPicInfo($Series["Picture"]);
             if ($IconAreaWidth < $PicWidth) {
                 $IconAreaWidth = $PicWidth;
             }
             if ($IconAreaHeight < $PicHeight) {
                 $IconAreaHeight = $PicHeight;
             }
         }
     }
     $YStep = max($this->pChartObject->FontSize, $IconAreaHeight) + 5;
     $XStep = $XSpacing;
     $Boundaries = array();
     $Boundaries["L"] = $X;
     $Boundaries["T"] = $Y;
     $Boundaries["R"] = 0;
     $Boundaries["B"] = 0;
     $vY = $Y;
     $vX = $X;
     foreach ($Data["ScatterSeries"] as $Key => $Series) {
         if ($Series["isDrawable"] == true) {
             if ($Mode == LEGEND_VERTICAL) {
                 $BoxArray = $this->pChartObject->getTextBox($vX + $IconAreaWidth + 4, $vY + $IconAreaHeight / 2, $FontName, $FontSize, 0, $Series["Description"]);
                 if ($Boundaries["T"] > $BoxArray[2]["Y"] + $IconAreaHeight / 2) {
                     $Boundaries["T"] = $BoxArray[2]["Y"] + $IconAreaHeight / 2;
                 }
                 if ($Boundaries["R"] < $BoxArray[1]["X"] + 2) {
                     $Boundaries["R"] = $BoxArray[1]["X"] + 2;
                 }
                 if ($Boundaries["B"] < $BoxArray[1]["Y"] + 2 + $IconAreaHeight / 2) {
                     $Boundaries["B"] = $BoxArray[1]["Y"] + 2 + $IconAreaHeight / 2;
                 }
                 $Lines = preg_split("/\n/", $Series["Description"]);
                 $vY = $vY + max($this->pChartObject->FontSize * count($Lines), $IconAreaHeight) + 5;
             } elseif ($Mode == LEGEND_HORIZONTAL) {
                 $Lines = preg_split("/\n/", $Series["Description"]);
                 $Width = array();
                 foreach ($Lines as $Key => $Value) {
                     $BoxArray = $this->pChartObject->getTextBox($vX + $IconAreaWidth + 6, $Y + $IconAreaHeight / 2 + ($this->pChartObject->FontSize + 3) * $Key, $FontName, $FontSize, 0, $Value);
                     if ($Boundaries["T"] > $BoxArray[2]["Y"] + $IconAreaHeight / 2) {
                         $Boundaries["T"] = $BoxArray[2]["Y"] + $IconAreaHeight / 2;
                     }
                     if ($Boundaries["R"] < $BoxArray[1]["X"] + 2) {
                         $Boundaries["R"] = $BoxArray[1]["X"] + 2;
                     }
                     if ($Boundaries["B"] < $BoxArray[1]["Y"] + 2 + $IconAreaHeight / 2) {
                         $Boundaries["B"] = $BoxArray[1]["Y"] + 2 + $IconAreaHeight / 2;
                     }
                     $Width[] = $BoxArray[1]["X"];
                 }
                 $vX = max($Width) + $XStep;
             }
         }
     }
     $vY = $vY - $YStep;
     $vX = $vX - $XStep;
     $TopOffset = $Y - $Boundaries["T"];
     if ($Boundaries["B"] - ($vY + $IconAreaHeight) < $TopOffset) {
         $Boundaries["B"] = $vY + $IconAreaHeight + $TopOffset;
     }
     if ($Style == LEGEND_ROUND) {
         $this->pChartObject->drawRoundedFilledRectangle($Boundaries["L"] - $Margin, $Boundaries["T"] - $Margin, $Boundaries["R"] + $Margin, $Boundaries["B"] + $Margin, $Margin, array("R" => $R, "G" => $G, "B" => $B, "Alpha" => $Alpha, "BorderR" => $BorderR, "BorderG" => $BorderG, "BorderB" => $BorderB));
     } elseif ($Style == LEGEND_BOX) {
         $this->pChartObject->drawFilledRectangle($Boundaries["L"] - $Margin, $Boundaries["T"] - $Margin, $Boundaries["R"] + $Margin, $Boundaries["B"] + $Margin, array("R" => $R, "G" => $G, "B" => $B, "Alpha" => $Alpha, "BorderR" => $BorderR, "BorderG" => $BorderG, "BorderB" => $BorderB));
     }
     $RestoreShadow = $this->pChartObject->Shadow;
     $this->Shadow = false;
     foreach ($Data["ScatterSeries"] as $Key => $Series) {
         if ($Series["isDrawable"] == true) {
             $R = $Series["Color"]["R"];
             $G = $Series["Color"]["G"];
             $B = $Series["Color"]["B"];
             $Ticks = $Series["Ticks"];
             $Weight = $Series["Weight"];
             if (isset($Series["Picture"])) {
                 $Picture = $Series["Picture"];
                 list($PicWidth, $PicHeight) = $this->pChartObject->getPicInfo($Picture);
                 $PicX = $X + $IconAreaWidth / 2;
                 $PicY = $Y + $IconAreaHeight / 2;
                 $this->pChartObject->drawFromPNG($PicX - $PicWidth / 2, $PicY - $PicHeight / 2, $Picture);
             } else {
                 if ($Family == LEGEND_FAMILY_BOX) {
                     if ($BoxWidth != $IconAreaWidth) {
                         $XOffset = floor(($IconAreaWidth - $BoxWidth) / 2);
                     } else {
                         $XOffset = 0;
                     }
                     if ($BoxHeight != $IconAreaHeight) {
                         $YOffset = floor(($IconAreaHeight - $BoxHeight) / 2);
                     } else {
                         $YOffset = 0;
                     }
                     $this->pChartObject->drawFilledRectangle($X + 1 + $XOffset, $Y + 1 + $YOffset, $X + $BoxWidth + $XOffset + 1, $Y + $BoxHeight + 1 + $YOffset, array("R" => 0, "G" => 0, "B" => 0, "Alpha" => 20));
                     $this->pChartObject->drawFilledRectangle($X + $XOffset, $Y + $YOffset, $X + $BoxWidth + $XOffset, $Y + $BoxHeight + $YOffset, array("R" => $R, "G" => $G, "B" => $B, "Surrounding" => 20));
                 } elseif ($Family == LEGEND_FAMILY_CIRCLE) {
                     $this->pChartObject->drawFilledCircle($X + 1 + $IconAreaWidth / 2, $Y + 1 + $IconAreaHeight / 2, min($IconAreaHeight / 2, $IconAreaWidth / 2), array("R" => 0, "G" => 0, "B" => 0, "Alpha" => 20));
                     $this->pChartObject->drawFilledCircle($X + $IconAreaWidth / 2, $Y + $IconAreaHeight / 2, min($IconAreaHeight / 2, $IconAreaWidth / 2), array("R" => $R, "G" => $G, "B" => $B, "Surrounding" => 20));
                 } elseif ($Family == LEGEND_FAMILY_LINE) {
                     $this->pChartObject->drawLine($X + 1, $Y + 1 + $IconAreaHeight / 2, $X + 1 + $IconAreaWidth, $Y + 1 + $IconAreaHeight / 2, array("R" => 0, "G" => 0, "B" => 0, "Alpha" => 20, "Ticks" => $Ticks, "Weight" => $Weight));
                     $this->pChartObject->drawLine($X, $Y + $IconAreaHeight / 2, $X + $IconAreaWidth, $Y + $IconAreaHeight / 2, array("R" => $R, "G" => $G, "B" => $B, "Ticks" => $Ticks, "Weight" => $Weight));
                 }
             }
             if ($Mode == LEGEND_VERTICAL) {
                 $Lines = preg_split("/\n/", $Series["Description"]);
                 foreach ($Lines as $Key => $Value) {
                     $this->pChartObject->drawText($X + $IconAreaWidth + 4, $Y + $IconAreaHeight / 2 + ($this->pChartObject->FontSize + 3) * $Key, $Value, array("R" => $FontR, "G" => $FontG, "B" => $FontB, "Align" => TEXT_ALIGN_MIDDLELEFT));
                 }
                 $Y = $Y + max($this->pChartObject->FontSize * count($Lines), $IconAreaHeight) + 5;
             } elseif ($Mode == LEGEND_HORIZONTAL) {
                 $Lines = preg_split("/\n/", $Series["Description"]);
                 $Width = array();
                 foreach ($Lines as $Key => $Value) {
                     $BoxArray = $this->pChartObject->drawText($X + $IconAreaWidth + 4, $Y + $IconAreaHeight / 2 + ($this->pChartObject->FontSize + 3) * $Key, $Value, array("R" => $FontR, "G" => $FontG, "B" => $FontB, "Align" => TEXT_ALIGN_MIDDLELEFT));
                     $Width[] = $BoxArray[1]["X"];
                 }
                 $X = max($Width) + 2 + $XStep;
             }
         }
     }
     $this->Shadow = $RestoreShadow;
 }