You are here

function pDraw::drawLabelBox in Visitors 7

Same name and namespace in other branches
  1. 7.2 pChart/class/pDraw.class.php \pDraw::drawLabelBox()
1 call to pDraw::drawLabelBox()
pDraw::writeLabel in pChart/class/pDraw.class.php

File

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

Class

pDraw

Code

function drawLabelBox($X, $Y, $Title, $Captions, $Format = "") {
  $NoTitle = isset($Format["NoTitle"]) ? $Format["NoTitle"] : NULL;
  $BoxWidth = isset($Format["BoxWidth"]) ? $Format["BoxWidth"] : 50;
  $DrawSerieColor = isset($Format["DrawSerieColor"]) ? $Format["DrawSerieColor"] : TRUE;
  $SerieR = isset($Format["SerieR"]) ? $Format["SerieR"] : NULL;
  $SerieG = isset($Format["SerieG"]) ? $Format["SerieG"] : NULL;
  $SerieB = isset($Format["SerieB"]) ? $Format["SerieB"] : NULL;
  $SerieAlpha = isset($Format["SerieAlpha"]) ? $Format["SerieAlpha"] : NULL;
  $SerieBoxSize = isset($Format["SerieBoxSize"]) ? $Format["SerieBoxSize"] : 6;
  $SerieBoxSpacing = isset($Format["SerieBoxSpacing"]) ? $Format["SerieBoxSpacing"] : 4;
  $VerticalMargin = isset($Format["VerticalMargin"]) ? $Format["VerticalMargin"] : 10;
  $HorizontalMargin = isset($Format["HorizontalMargin"]) ? $Format["HorizontalMargin"] : 8;
  $R = isset($Format["R"]) ? $Format["R"] : $this->FontColorR;
  $G = isset($Format["G"]) ? $Format["G"] : $this->FontColorG;
  $B = isset($Format["B"]) ? $Format["B"] : $this->FontColorB;
  $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : $this->FontColorA;
  $FontName = isset($Format["FontName"]) ? $Format["FontName"] : $this->FontName;
  $FontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : $this->FontSize;
  $TitleMode = isset($Format["TitleMode"]) ? $Format["TitleMode"] : LABEL_TITLE_NOBACKGROUND;
  $TitleR = isset($Format["TitleR"]) ? $Format["TitleR"] : $R;
  $TitleG = isset($Format["TitleG"]) ? $Format["TitleG"] : $G;
  $TitleB = isset($Format["TitleB"]) ? $Format["TitleB"] : $B;
  $TitleAlpha = isset($Format["TitleAlpha"]) ? $Format["TitleAlpha"] : 100;
  $TitleBackgroundR = isset($Format["TitleBackgroundR"]) ? $Format["TitleBackgroundR"] : 0;
  $TitleBackgroundG = isset($Format["TitleBackgroundG"]) ? $Format["TitleBackgroundG"] : 0;
  $TitleBackgroundB = isset($Format["TitleBackgroundB"]) ? $Format["TitleBackgroundB"] : 0;
  $TitleBackgroundAlpha = isset($Format["TitleBackgroundAlpha"]) ? $Format["TitleBackgroundAlpha"] : 100;
  $GradientStartR = isset($Format["GradientStartR"]) ? $Format["GradientStartR"] : 255;
  $GradientStartG = isset($Format["GradientStartG"]) ? $Format["GradientStartG"] : 255;
  $GradientStartB = isset($Format["GradientStartB"]) ? $Format["GradientStartB"] : 255;
  $GradientEndR = isset($Format["GradientEndR"]) ? $Format["GradientEndR"] : 220;
  $GradientEndG = isset($Format["GradientEndG"]) ? $Format["GradientEndG"] : 220;
  $GradientEndB = isset($Format["GradientEndB"]) ? $Format["GradientEndB"] : 220;
  $BoxAlpha = isset($Format["BoxAlpha"]) ? $Format["BoxAlpha"] : 100;
  if (!$DrawSerieColor) {
    $SerieBoxSize = 0;
    $SerieBoxSpacing = 0;
  }
  $TxtPos = $this
    ->getTextBox($X, $Y, $FontName, $FontSize, 0, $Title);
  $TitleWidth = $TxtPos[1]["X"] - $TxtPos[0]["X"] + $VerticalMargin * 2;
  $TitleHeight = $TxtPos[0]["Y"] - $TxtPos[2]["Y"];
  if ($NoTitle) {
    $TitleWidth = 0;
    $TitleHeight = 0;
  }
  $CaptionWidth = 0;
  $CaptionHeight = -$HorizontalMargin;
  foreach ($Captions as $Key => $Caption) {
    $TxtPos = $this
      ->getTextBox($X, $Y, $FontName, $FontSize, 0, $Caption["Caption"]);
    $CaptionWidth = max($CaptionWidth, $TxtPos[1]["X"] - $TxtPos[0]["X"] + $VerticalMargin * 2);
    $CaptionHeight = $CaptionHeight + max($TxtPos[0]["Y"] - $TxtPos[2]["Y"], $SerieBoxSize + 2) + $HorizontalMargin;
  }
  if ($CaptionHeight <= 5) {
    $CaptionHeight = $CaptionHeight + $HorizontalMargin / 2;
  }
  if ($DrawSerieColor) {
    $CaptionWidth = $CaptionWidth + $SerieBoxSize + $SerieBoxSpacing;
  }
  $BoxWidth = max($BoxWidth, $TitleWidth, $CaptionWidth);
  $XMin = $X - 5 - floor(($BoxWidth - 10) / 2);
  $XMax = $X + 5 + floor(($BoxWidth - 10) / 2);
  $RestoreShadow = $this->Shadow;
  if ($this->Shadow == TRUE) {
    $this->Shadow = FALSE;
    $Poly = "";
    $Poly[] = $X + $this->ShadowX;
    $Poly[] = $Y + $this->ShadowX;
    $Poly[] = $X + 5 + $this->ShadowX;
    $Poly[] = $Y - 5 + $this->ShadowX;
    $Poly[] = $XMax + $this->ShadowX;
    $Poly[] = $Y - 5 + $this->ShadowX;
    if ($NoTitle) {
      $Poly[] = $XMax + $this->ShadowX;
      $Poly[] = $Y - 5 - $TitleHeight - $CaptionHeight - $HorizontalMargin * 2 + $this->ShadowX;
      $Poly[] = $XMin + $this->ShadowX;
      $Poly[] = $Y - 5 - $TitleHeight - $CaptionHeight - $HorizontalMargin * 2 + $this->ShadowX;
    }
    else {
      $Poly[] = $XMax + $this->ShadowX;
      $Poly[] = $Y - 5 - $TitleHeight - $CaptionHeight - $HorizontalMargin * 3 + $this->ShadowX;
      $Poly[] = $XMin + $this->ShadowX;
      $Poly[] = $Y - 5 - $TitleHeight - $CaptionHeight - $HorizontalMargin * 3 + $this->ShadowX;
    }
    $Poly[] = $XMin + $this->ShadowX;
    $Poly[] = $Y - 5 + $this->ShadowX;
    $Poly[] = $X - 5 + $this->ShadowX;
    $Poly[] = $Y - 5 + $this->ShadowX;
    $this
      ->drawPolygon($Poly, array(
      "R" => $this->ShadowR,
      "G" => $this->ShadowG,
      "B" => $this->ShadowB,
      "Alpha" => $this->Shadowa,
    ));
  }

  /* Draw the background */
  $GradientSettings = array(
    "StartR" => $GradientStartR,
    "StartG" => $GradientStartG,
    "StartB" => $GradientStartB,
    "EndR" => $GradientEndR,
    "EndG" => $GradientEndG,
    "EndB" => $GradientEndB,
    "Alpha" => $BoxAlpha,
  );
  if ($NoTitle) {
    $this
      ->drawGradientArea($XMin, $Y - 5 - $TitleHeight - $CaptionHeight - $HorizontalMargin * 2, $XMax, $Y - 6, DIRECTION_VERTICAL, $GradientSettings);
  }
  else {
    $this
      ->drawGradientArea($XMin, $Y - 5 - $TitleHeight - $CaptionHeight - $HorizontalMargin * 3, $XMax, $Y - 6, DIRECTION_VERTICAL, $GradientSettings);
  }
  $Poly = "";
  $Poly[] = $X;
  $Poly[] = $Y;
  $Poly[] = $X - 5;
  $Poly[] = $Y - 5;
  $Poly[] = $X + 5;
  $Poly[] = $Y - 5;
  $this
    ->drawPolygon($Poly, array(
    "R" => $GradientEndR,
    "G" => $GradientEndG,
    "B" => $GradientEndB,
    "Alpha" => $BoxAlpha,
    "NoBorder" => TRUE,
  ));

  /* Outer border */
  $OuterBorderColor = $this
    ->allocateColor($this->Picture, 100, 100, 100, $BoxAlpha);
  imageline($this->Picture, $XMin, $Y - 5, $X - 5, $Y - 5, $OuterBorderColor);
  imageline($this->Picture, $X, $Y, $X - 5, $Y - 5, $OuterBorderColor);
  imageline($this->Picture, $X, $Y, $X + 5, $Y - 5, $OuterBorderColor);
  imageline($this->Picture, $X + 5, $Y - 5, $XMax, $Y - 5, $OuterBorderColor);
  if ($NoTitle) {
    imageline($this->Picture, $XMin, $Y - 5 - $TitleHeight - $CaptionHeight - $HorizontalMargin * 2, $XMin, $Y - 5, $OuterBorderColor);
    imageline($this->Picture, $XMax, $Y - 5 - $TitleHeight - $CaptionHeight - $HorizontalMargin * 2, $XMax, $Y - 5, $OuterBorderColor);
    imageline($this->Picture, $XMin, $Y - 5 - $TitleHeight - $CaptionHeight - $HorizontalMargin * 2, $XMax, $Y - 5 - $TitleHeight - $CaptionHeight - $HorizontalMargin * 2, $OuterBorderColor);
  }
  else {
    imageline($this->Picture, $XMin, $Y - 5 - $TitleHeight - $CaptionHeight - $HorizontalMargin * 3, $XMin, $Y - 5, $OuterBorderColor);
    imageline($this->Picture, $XMax, $Y - 5 - $TitleHeight - $CaptionHeight - $HorizontalMargin * 3, $XMax, $Y - 5, $OuterBorderColor);
    imageline($this->Picture, $XMin, $Y - 5 - $TitleHeight - $CaptionHeight - $HorizontalMargin * 3, $XMax, $Y - 5 - $TitleHeight - $CaptionHeight - $HorizontalMargin * 3, $OuterBorderColor);
  }

  /* Inner border */
  $InnerBorderColor = $this
    ->allocateColor($this->Picture, 255, 255, 255, $BoxAlpha);
  imageline($this->Picture, $XMin + 1, $Y - 6, $X - 5, $Y - 6, $InnerBorderColor);
  imageline($this->Picture, $X, $Y - 1, $X - 5, $Y - 6, $InnerBorderColor);
  imageline($this->Picture, $X, $Y - 1, $X + 5, $Y - 6, $InnerBorderColor);
  imageline($this->Picture, $X + 5, $Y - 6, $XMax - 1, $Y - 6, $InnerBorderColor);
  if ($NoTitle) {
    imageline($this->Picture, $XMin + 1, $Y - 4 - $TitleHeight - $CaptionHeight - $HorizontalMargin * 2, $XMin + 1, $Y - 6, $InnerBorderColor);
    imageline($this->Picture, $XMax - 1, $Y - 4 - $TitleHeight - $CaptionHeight - $HorizontalMargin * 2, $XMax - 1, $Y - 6, $InnerBorderColor);
    imageline($this->Picture, $XMin + 1, $Y - 4 - $TitleHeight - $CaptionHeight - $HorizontalMargin * 2, $XMax - 1, $Y - 4 - $TitleHeight - $CaptionHeight - $HorizontalMargin * 2, $InnerBorderColor);
  }
  else {
    imageline($this->Picture, $XMin + 1, $Y - 4 - $TitleHeight - $CaptionHeight - $HorizontalMargin * 3, $XMin + 1, $Y - 6, $InnerBorderColor);
    imageline($this->Picture, $XMax - 1, $Y - 4 - $TitleHeight - $CaptionHeight - $HorizontalMargin * 3, $XMax - 1, $Y - 6, $InnerBorderColor);
    imageline($this->Picture, $XMin + 1, $Y - 4 - $TitleHeight - $CaptionHeight - $HorizontalMargin * 3, $XMax - 1, $Y - 4 - $TitleHeight - $CaptionHeight - $HorizontalMargin * 3, $InnerBorderColor);
  }

  /* Draw the separator line */
  if ($TitleMode == LABEL_TITLE_NOBACKGROUND && !$NoTitle) {
    $YPos = $Y - 7 - $CaptionHeight - $HorizontalMargin - $HorizontalMargin / 2;
    $XMargin = $VerticalMargin / 2;
    $this
      ->drawLine($XMin + $XMargin, $YPos + 1, $XMax - $XMargin, $YPos + 1, array(
      "R" => $GradientEndR,
      "G" => $GradientEndG,
      "B" => $GradientEndB,
      "Alpha" => $BoxAlpha,
    ));
    $this
      ->drawLine($XMin + $XMargin, $YPos, $XMax - $XMargin, $YPos, array(
      "R" => $GradientStartR,
      "G" => $GradientStartG,
      "B" => $GradientStartB,
      "Alpha" => $BoxAlpha,
    ));
  }
  elseif ($TitleMode == LABEL_TITLE_BACKGROUND) {
    $this
      ->drawFilledRectangle($XMin, $Y - 5 - $TitleHeight - $CaptionHeight - $HorizontalMargin * 3, $XMax, $Y - 5 - $TitleHeight - $CaptionHeight - $HorizontalMargin + $HorizontalMargin / 2, array(
      "R" => $TitleBackgroundR,
      "G" => $TitleBackgroundG,
      "B" => $TitleBackgroundB,
      "Alpha" => $BoxAlpha,
    ));
    imageline($this->Picture, $XMin + 1, $Y - 5 - $TitleHeight - $CaptionHeight - $HorizontalMargin + $HorizontalMargin / 2 + 1, $XMax - 1, $Y - 5 - $TitleHeight - $CaptionHeight - $HorizontalMargin + $HorizontalMargin / 2 + 1, $InnerBorderColor);
  }

  /* Write the description */
  if (!$NoTitle) {
    $this
      ->drawText($XMin + $VerticalMargin, $Y - 7 - $CaptionHeight - $HorizontalMargin * 2, $Title, array(
      "Align" => TEXT_ALIGN_BOTTOMLEFT,
      "R" => $TitleR,
      "G" => $TitleG,
      "B" => $TitleB,
    ));
  }

  /* Write the value */
  $YPos = $Y - 5 - $HorizontalMargin;
  $XPos = $XMin + $VerticalMargin + $SerieBoxSize + $SerieBoxSpacing;
  foreach ($Captions as $Key => $Caption) {
    $CaptionTxt = $Caption["Caption"];
    $TxtPos = $this
      ->getTextBox($XPos, $YPos, $FontName, $FontSize, 0, $CaptionTxt);
    $CaptionHeight = $TxtPos[0]["Y"] - $TxtPos[2]["Y"];

    /* Write the serie color if needed */
    if ($DrawSerieColor) {
      $BoxSettings = array(
        "R" => $Caption["Format"]["R"],
        "G" => $Caption["Format"]["G"],
        "B" => $Caption["Format"]["B"],
        "Alpha" => $Caption["Format"]["Alpha"],
        "BorderR" => 0,
        "BorderG" => 0,
        "BorderB" => 0,
      );
      $this
        ->drawFilledRectangle($XMin + $VerticalMargin, $YPos - $SerieBoxSize, $XMin + $VerticalMargin + $SerieBoxSize, $YPos, $BoxSettings);
    }
    $this
      ->drawText($XPos, $YPos, $CaptionTxt, array(
      "Align" => TEXT_ALIGN_BOTTOMLEFT,
    ));
    $YPos = $YPos - $CaptionHeight - $HorizontalMargin;
  }
  $this->Shadow = $RestoreShadow;
}