You are here

function pChart::drawLegend in Visitors 7.0

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

File

pchart/pChart.inc, line 574

Class

pChart

Code

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

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

  /* <-10->[8]<-4->Text<-10-> */
  $MaxWidth = 0;
  $MaxHeight = 8;
  foreach ($DataDescription["Description"] as $Key => $Value) {
    $Position = imageftbbox($this->FontSize, 0, $this->FontName, $Value);
    $TextWidth = $Position[2] - $Position[0];
    if ($TextWidth > $MaxWidth) {
      $MaxWidth = $TextWidth;
    }
    $MaxHeight = $MaxHeight + ($this->FontSize + 6);
  }
  $MaxHeight = $MaxHeight - 5;
  $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 ($DataDescription["Description"] as $Key => $Value) {
    $this
      ->drawFilledRoundedRectangle($XPos + 10, $YPos + $YOffset - 4, $XPos + 14, $YPos + $YOffset - 4, 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, $Value);
    $YOffset = $YOffset + ($this->FontSize + 6);
    $ID++;
  }
}