You are here

function pChart::drawPieLegend in Visitors 8

Same name and namespace in other branches
  1. 7.0 pchart/pChart.inc \pChart::drawPieLegend()

File

pchart/pChart.inc, line 611

Class

pChart

Code

function drawPieLegend($XPos, $YPos, &$Data, &$DataDescription, $R, $G, $B) {

  /* Validate the Data and DataDescription array */
  $this
    ->validateDataDescription("drawPieLegend", $DataDescription, FALSE);
  $this
    ->validateData("drawPieLegend", $Data);
  if (!isset($DataDescription["Position"])) {
    return -1;
  }
  $C_TextColor = imagecolorallocate($this->Picture, 0, 0, 0);

  /* <-10->[8]<-4->Text<-10-> */
  $MaxWidth = 0;
  $MaxHeight = 8;
  foreach ($Data as $Key => $Value) {
    $Value2 = $Value[$DataDescription["Position"]];
    $Position = imageftbbox($this->FontSize, 0, $this->FontName, $Value2);
    $TextWidth = $Position[2] - $Position[0];
    if ($TextWidth > $MaxWidth) {
      $MaxWidth = $TextWidth;
    }
    $MaxHeight = $MaxHeight + ($this->FontSize + 6);
  }
  $MaxHeight = $MaxHeight - 3;
  $MaxWidth = $MaxWidth + 32;
  $this
    ->drawFilledRoundedRectangle($XPos + 1, $YPos + 1, $XPos + $MaxWidth + 1, $YPos + $MaxHeight + 1, 5, $R - 30, $G - 30, $B - 30);
  $this
    ->drawFilledRoundedRectangle($XPos, $YPos, $XPos + $MaxWidth, $YPos + $MaxHeight, 5, $R, $G, $B);
  $YOffset = 4 + $this->FontSize;
  $ID = 0;
  foreach ($Data as $Key => $Value) {
    $Value2 = $Value[$DataDescription["Position"]];
    $this
      ->drawFilledRectangle($XPos + 10, $YPos + $YOffset - 6, $XPos + 14, $YPos + $YOffset - 2, $this->Palette[$ID]["R"], $this->Palette[$ID]["G"], $this->Palette[$ID]["B"]);
    imagettftext($this->Picture, $this->FontSize, 0, $XPos + 22, $YPos + $YOffset, $C_TextColor, $this->FontName, $Value2);
    $YOffset = $YOffset + ($this->FontSize + 6);
    $ID++;
  }
}