You are here

function pScatter::getScatterLegendSize in Visitors 7

Same name and namespace in other branches
  1. 7.2 pChart/class/pScatter.class.php \pScatter::getScatterLegendSize()

File

pChart/class/pScatter.class.php, line 747

Class

pScatter

Code

function getScatterLegendSize($Format = "") {
  $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;
  $Style = isset($Format["Style"]) ? $Format["Style"] : LEGEND_ROUND;
  $Mode = isset($Format["Mode"]) ? $Format["Mode"] : LEGEND_VERTICAL;
  $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 = $IconAreaWidth + 5;
  $XStep = $XSpacing;
  $Boundaries = "";
  $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 = "";
        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,
  );
}