function pDraw::drawArrow

5.x pDraw.class.php pDraw::drawArrow($X1, $Y1, $X2, $Y2, $Format = "")
3 calls to pDraw::drawArrow()
pDraw::drawArrowLabel in inc/pchart/pchart/class/pDraw.class.php
pDraw::drawBezier in inc/pchart/pchart/class/pDraw.class.php
pDraw::drawScale in inc/pchart/pchart/class/pDraw.class.php

File

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

Class

pDraw

Code

function drawArrow($X1, $Y1, $X2, $Y2, $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;
  $Alpha = isset($Format ["Alpha"]) ? $Format ["Alpha"] : 100;
  $Size = isset($Format ["Size"]) ? $Format ["Size"] : 10;
  $Ratio = isset($Format ["Ratio"]) ? $Format ["Ratio"] : .5;
  $TwoHeads = isset($Format ["TwoHeads"]) ? $Format ["TwoHeads"] : FALSE;
  $Ticks = isset($Format ["Ticks"]) ? $Format ["Ticks"] : FALSE;

  /* Calculate the line angle */
  $Angle = $this->getAngle($X1, $Y1, $X2, $Y2);

  /* Override Shadow support, this will be managed internally */
  $RestoreShadow = $this->Shadow;
  if ($this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0) 
   {
    $this->Shadow = FALSE;
    $this->drawArrow($X1 + $this->ShadowX, $Y1 + $this->ShadowY, $X2 + $this->ShadowX, $Y2 + $this->ShadowY, array("FillR" => $this->ShadowR, "FillG" => $this->ShadowG, "FillB" => $this->ShadowB, "Alpha" => $this->Shadowa, "Size" => $Size, "Ratio" => $Ratio, "TwoHeads" => $TwoHeads, "Ticks" => $Ticks));
  }

  /* Draw the 1st Head */
  $TailX = cos(($Angle -180) * PI / 180) * $Size + $X2;
  $TailY = sin(($Angle -180) * PI / 180) * $Size + $Y2;

  $Points = "";
  $Points [] = $X2;
  $Points [] = $Y2;
  $Points [] = cos(($Angle -90) * PI / 180) * $Size * $Ratio + $TailX;
  $Points [] = sin(($Angle -90) * PI / 180) * $Size * $Ratio + $TailY;
  $Points [] = cos(($Angle -270) * PI / 180) * $Size * $Ratio + $TailX;
  $Points [] = sin(($Angle -270) * PI / 180) * $Size * $Ratio + $TailY;
  $Points [] = $X2;
  $Points [] = $Y2;

  /* Visual correction */
  if ($Angle == 180 || $Angle == 360) {
    $Points [4] = $Points [2];
  }
  if ($Angle == 90 || $Angle == 270) {
    $Points [5] = $Points [3];
  }

  $ArrowColor = $this->allocateColor($this->Picture, $FillR, $FillG, $FillB, $Alpha);
  ImageFilledPolygon($this->Picture, $Points, 4, $ArrowColor);

  $this->drawLine($Points [0], $Points [1], $Points [2], $Points [3], array("R" => $BorderR, "G" => $BorderG, "B" => $BorderB, "Alpha" => $Alpha));
  $this->drawLine($Points [2], $Points [3], $Points [4], $Points [5], array("R" => $BorderR, "G" => $BorderG, "B" => $BorderB, "Alpha" => $Alpha));
  $this->drawLine($Points [0], $Points [1], $Points [4], $Points [5], array("R" => $BorderR, "G" => $BorderG, "B" => $BorderB, "Alpha" => $Alpha));

  /* Draw the second head */
  if ($TwoHeads) 
   {
    $Angle = $this->getAngle($X2, $Y2, $X1, $Y1);

    $TailX2 = cos(($Angle -180) * PI / 180) * $Size + $X1;
    $TailY2 = sin(($Angle -180) * PI / 180) * $Size + $Y1;

    $Points = "";
    $Points [] = $X1;
    $Points [] = $Y1;
    $Points [] = cos(($Angle -90) * PI / 180) * $Size * $Ratio + $TailX2;
    $Points [] = sin(($Angle -90) * PI / 180) * $Size * $Ratio + $TailY2;
    $Points [] = cos(($Angle -270) * PI / 180) * $Size * $Ratio + $TailX2;
    $Points [] = sin(($Angle -270) * PI / 180) * $Size * $Ratio + $TailY2;
    $Points [] = $X1;
    $Points [] = $Y1;

    /* Visual correction */
    if ($Angle == 180 || $Angle == 360) {
      $Points [4] = $Points [2];
    }
    if ($Angle == 90 || $Angle == 270) {
      $Points [5] = $Points [3];
    }

    $ArrowColor = $this->allocateColor($this->Picture, $FillR, $FillG, $FillB, $Alpha);
    ImageFilledPolygon($this->Picture, $Points, 4, $ArrowColor);

    $this->drawLine($Points [0], $Points [1], $Points [2], $Points [3], array("R" => $BorderR, "G" => $BorderG, "B" => $BorderB, "Alpha" => $Alpha));
    $this->drawLine($Points [2], $Points [3], $Points [4], $Points [5], array("R" => $BorderR, "G" => $BorderG, "B" => $BorderB, "Alpha" => $Alpha));
    $this->drawLine($Points [0], $Points [1], $Points [4], $Points [5], array("R" => $BorderR, "G" => $BorderG, "B" => $BorderB, "Alpha" => $Alpha));

    $this->drawLine($TailX, $TailY, $TailX2, $TailY2, array("R" => $BorderR, "G" => $BorderG, "B" => $BorderB, "Alpha" => $Alpha, "Ticks" => $Ticks));
  }
  else {
    $this->drawLine($X1, $Y1, $TailX, $TailY, array("R" => $BorderR, "G" => $BorderG, "B" => $BorderB, "Alpha" => $Alpha, "Ticks" => $Ticks));
  }

  /* Re-enable shadows */
  $this->Shadow = $RestoreShadow;
}