示例#1
0
 /**
  * Get the legend box size
  * @param array $Format
  * @return array
  */
 public function getScatterLegendSize(array $Format = array())
 {
     $FontName = isset($Format["FontName"]) ? $Format["FontName"] : $this->pChartObject->FontName;
     $FontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : $this->pChartObject->FontSize;
     $BoxSize = isset($Format["BoxSize"]) ? $Format["BoxSize"] : 5;
     $Margin = isset($Format["Margin"]) ? $Format["Margin"] : 5;
     $Mode = isset($Format["Mode"]) ? $Format["Mode"] : LEGEND_VERTICAL;
     $XSpacing = isset($Format["XSpacing"]) ? $Format["XSpacing"] : 5;
     $YStep = max($this->pChartObject->FontSize, $BoxSize) + 5;
     $XStep = $BoxSize + 5;
     $X = 100;
     $Y = 100;
     $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 + $BoxSize) < $TopOffset) {
         $Boundaries["B"] = $vY + $BoxSize + $TopOffset;
     }
     $Width = $Boundaries["R"] + $Margin - ($Boundaries["L"] - $Margin);
     $Height = $Boundaries["B"] + $Margin - ($Boundaries["T"] - $Margin);
     return array("Width" => $Width, "Height" => $Height);
 }