function pDraw::drawArrowLabel

5.x pDraw.class.php pDraw::drawArrowLabel($X1, $Y1, $Text, $Format = "")

File

inc/pchart/pchart/class/pDraw.class.php, line 1363

Class

pDraw

Code

function drawArrowLabel($X1, $Y1, $Text, $Format = "") 
 {
  $FillR = isset($Format ["FillR"]) ? $Format ["FillR"] : 0;
  $FillG = isset($Format ["FillG"]) ? $Format ["FillG"] : 0;
  $FillB = isset($Format ["FillB"]) ? $Format ["FillB"] : 0;
  $BorderR = isset($Format ["BorderR"]) ? $Format ["BorderR"] : $FillR;
  $BorderG = isset($Format ["BorderG"]) ? $Format ["BorderG"] : $FillG;
  $BorderB = isset($Format ["BorderB"]) ? $Format ["BorderB"] : $FillB;
  $FontName = isset($Format ["FontName"]) ? $Format ["FontName"] : $this->FontName;
  $FontSize = isset($Format ["FontSize"]) ? $Format ["FontSize"] : $this->FontSize;
  $Alpha = isset($Format ["Alpha"]) ? $Format ["Alpha"] : 100;
  $Length = isset($Format ["Length"]) ? $Format ["Length"] : 50;
  $Angle = isset($Format ["Angle"]) ? $Format ["Angle"] : 315;
  $Size = isset($Format ["Size"]) ? $Format ["Size"] : 10;
  $Position = isset($Format ["Position"]) ? $Format ["Position"] : POSITION_TOP;
  $RoundPos = isset($Format ["RoundPos"]) ? $Format ["RoundPos"] : FALSE;
  $Ticks = isset($Format ["Ticks"]) ? $Format ["Ticks"] : NULL;

  $Angle = $Angle % 360;

  $X2 = sin(($Angle + 180) * PI / 180) * $Length + $X1;
  $Y2 = cos(($Angle + 180) * PI / 180) * $Length + $Y1;

  if ($RoundPos && $Angle > 0 && $Angle < 180) {
    $Y2 = ceil($Y2);
  }
  if ($RoundPos && $Angle > 180) {
    $Y2 = floor($Y2);
  }

  $this->drawArrow($X2, $Y2, $X1, $Y1, $Format);

  $Size = imagettfbbox($FontSize, 0, $FontName, $Text);
  $TxtWidth = max(abs($Size [2] -$Size [0]), abs($Size [0] -$Size [6]));
  $TxtHeight = max(abs($Size [1] -$Size [7]), abs($Size [3] -$Size [1]));

  if ($Angle > 0 && $Angle < 180) 
   {
    $this->drawLine($X2, $Y2, $X2 -$TxtWidth, $Y2, array("R" => $BorderR, "G" => $BorderG, "B" => $BorderB, "Alpha" => $Alpha, "Ticks" => $Ticks));
    if ($Position == POSITION_TOP) {
      $this->drawText($X2, $Y2 -2, $Text, array("R" => $BorderR, "G" => $BorderG, "B" => $BorderB, "Alpha" => $Alpha, "Align" => TEXT_ALIGN_BOTTOMRIGHT));
    }
    else {
      $this->drawText($X2, $Y2 + 4, $Text, array("R" => $BorderR, "G" => $BorderG, "B" => $BorderB, "Alpha" => $Alpha, "Align" => TEXT_ALIGN_TOPRIGHT));
    }
  }
  else 
   {
    $this->drawLine($X2, $Y2, $X2 + $TxtWidth, $Y2, array("R" => $BorderR, "G" => $BorderG, "B" => $BorderB, "Alpha" => $Alpha, "Ticks" => $Ticks));
    if ($Position == POSITION_TOP) {
      $this->drawText($X2, $Y2 -2, $Text, array("R" => $BorderR, "G" => $BorderG, "B" => $BorderB, "Alpha" => $Alpha));
    }
    else {
      $this->drawText($X2, $Y2 + 4, $Text, array("R" => $BorderR, "G" => $BorderG, "B" => $BorderB, "Alpha" => $Alpha, "Align" => TEXT_ALIGN_TOPLEFT));
    }
  }
}