You are here

function pPie::drawPieLegend in Visitors 7

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

File

pChart/class/pPie.class.php, line 700

Class

pPie

Code

function drawPieLegend($X, $Y, $Format = "") {
  $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;
  $BoxSize = isset($Format["BoxSize"]) ? $Format["BoxSize"] : 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;
  }
  $YStep = max($this->pChartObject->FontSize, $BoxSize) + 5;
  $XStep = $BoxSize + 5;

  /* Data Processing */
  $Data = $this->pDataObject
    ->getData();
  $Palette = $this->pDataObject
    ->getPalette();

  /* Do we have an abscissa serie defined? */
  if ($Data["Abscissa"] == "") {
    return PIE_NO_ABSCISSA;
  }
  $Boundaries = "";
  $Boundaries["L"] = $X;
  $Boundaries["T"] = $Y;
  $Boundaries["R"] = 0;
  $Boundaries["B"] = 0;
  $vY = $Y;
  $vX = $X;
  foreach ($Data["Series"][$Data["Abscissa"]]["Data"] as $Key => $Value) {
    $BoxArray = $this->pChartObject
      ->getTextBox($vX + $BoxSize + 4, $vY + $BoxSize / 2, $FontName, $FontSize, 0, $Value);
    if ($Mode == LEGEND_VERTICAL) {
      if ($Boundaries["T"] > $BoxArray[2]["Y"] + $BoxSize / 2) {
        $Boundaries["T"] = $BoxArray[2]["Y"] + $BoxSize / 2;
      }
      if ($Boundaries["R"] < $BoxArray[1]["X"] + 2) {
        $Boundaries["R"] = $BoxArray[1]["X"] + 2;
      }
      if ($Boundaries["B"] < $BoxArray[1]["Y"] + 2 + $BoxSize / 2) {
        $Boundaries["B"] = $BoxArray[1]["Y"] + 2 + $BoxSize / 2;
      }
      $vY = $vY + $YStep;
    }
    elseif ($Mode == LEGEND_HORIZONTAL) {
      if ($Boundaries["T"] > $BoxArray[2]["Y"] + $BoxSize / 2) {
        $Boundaries["T"] = $BoxArray[2]["Y"] + $BoxSize / 2;
      }
      if ($Boundaries["R"] < $BoxArray[1]["X"] + 2) {
        $Boundaries["R"] = $BoxArray[1]["X"] + 2;
      }
      if ($Boundaries["B"] < $BoxArray[1]["Y"] + 2 + $BoxSize / 2) {
        $Boundaries["B"] = $BoxArray[1]["Y"] + 2 + $BoxSize / 2;
      }
      $vX = $Boundaries["R"] + $XStep;
    }
  }
  $vY = $vY - $YStep;
  $vX = $vX - $XStep;
  $TopOffset = $Y - $Boundaries["T"];
  if ($Boundaries["B"] - ($vY + $BoxSize) < $TopOffset) {
    $Boundaries["B"] = $vY + $BoxSize + $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->pChartObject->Shadow = FALSE;
  foreach ($Data["Series"][$Data["Abscissa"]]["Data"] as $Key => $Value) {
    $R = $Palette[$Key]["R"];
    $G = $Palette[$Key]["G"];
    $B = $Palette[$Key]["B"];
    $this->pChartObject
      ->drawFilledRectangle($X + 1, $Y + 1, $X + $BoxSize + 1, $Y + $BoxSize + 1, array(
      "R" => 0,
      "G" => 0,
      "B" => 0,
      "Alpha" => 20,
    ));
    $this->pChartObject
      ->drawFilledRectangle($X, $Y, $X + $BoxSize, $Y + $BoxSize, array(
      "R" => $R,
      "G" => $G,
      "B" => $B,
      "Surrounding" => 20,
    ));
    if ($Mode == LEGEND_VERTICAL) {
      $this->pChartObject
        ->drawText($X + $BoxSize + 4, $Y + $BoxSize / 2, $Value, array(
        "R" => $FontR,
        "G" => $FontG,
        "B" => $FontB,
        "Align" => TEXT_ALIGN_MIDDLELEFT,
        "FontName" => $FontName,
        "FontSize" => $FontSize,
      ));
      $Y = $Y + $YStep;
    }
    elseif ($Mode == LEGEND_HORIZONTAL) {
      $BoxArray = $this->pChartObject
        ->drawText($X + $BoxSize + 4, $Y + $BoxSize / 2, $Value, array(
        "R" => $FontR,
        "G" => $FontG,
        "B" => $FontB,
        "Align" => TEXT_ALIGN_MIDDLELEFT,
        "FontName" => $FontName,
        "FontSize" => $FontSize,
      ));
      $X = $BoxArray[1]["X"] + 2 + $XStep;
    }
  }
  $this->Shadow = $RestoreShadow;
}