You are here

function pDraw::getLegendSize in Visitors 7.2

Same name and namespace in other branches
  1. 7 pChart/class/pDraw.class.php \pDraw::getLegendSize()

File

pChart/class/pDraw.class.php, line 1510

Class

pDraw

Code

function getLegendSize($Format = "") {
  $FontName = isset($Format["FontName"]) ? $Format["FontName"] : $this->FontName;
  $FontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : $this->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;
  $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;
  $Data = $this->DataSet
    ->getData();
  foreach ($Data["Series"] as $SerieName => $Serie) {
    if ($Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] && isset($Serie["Picture"])) {
      list($PicWidth, $PicHeight) = $this
        ->getPicInfo($Serie["Picture"]);
      if ($IconAreaWidth < $PicWidth) {
        $IconAreaWidth = $PicWidth;
      }
      if ($IconAreaHeight < $PicHeight) {
        $IconAreaHeight = $PicHeight;
      }
    }
  }
  $YStep = max($this->FontSize, $IconAreaHeight) + 5;
  $XStep = $IconAreaWidth + 5;
  $XStep = $XSpacing;
  $X = 100;
  $Y = 100;
  $Boundaries = "";
  $Boundaries["L"] = $X;
  $Boundaries["T"] = $Y;
  $Boundaries["R"] = 0;
  $Boundaries["B"] = 0;
  $vY = $Y;
  $vX = $X;
  foreach ($Data["Series"] as $SerieName => $Serie) {
    if ($Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"]) {
      if ($Mode == LEGEND_VERTICAL) {
        $BoxArray = $this
          ->getTextBox($vX + $IconAreaWidth + 4, $vY + $IconAreaHeight / 2, $FontName, $FontSize, 0, $Serie["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/", $Serie["Description"]);
        $vY = $vY + max($this->FontSize * count($Lines), $IconAreaHeight) + 5;
      }
      elseif ($Mode == LEGEND_HORIZONTAL) {
        $Lines = preg_split("/\n/", $Serie["Description"]);
        $Width = "";
        foreach ($Lines as $Key => $Value) {
          $BoxArray = $this
            ->getTextBox($vX + $IconAreaWidth + 6, $Y + $IconAreaHeight / 2 + ($this->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;
  }
  $Width = $Boundaries["R"] + $Margin - ($Boundaries["L"] - $Margin);
  $Height = $Boundaries["B"] + $Margin - ($Boundaries["T"] - $Margin);
  return array(
    "Width" => $Width,
    "Height" => $Height,
  );
}