You are here

function pDraw::drawLine in Visitors 7.2

Same name and namespace in other branches
  1. 7 pChart/class/pDraw.class.php \pDraw::drawLine()
25 calls to pDraw::drawLine()
pDraw::drawArrow in pChart/class/pDraw.class.php
pDraw::drawArrowLabel in pChart/class/pDraw.class.php
pDraw::drawBarChart in pChart/class/pDraw.class.php
pDraw::drawBestFit in pChart/class/pDraw.class.php
pDraw::drawBezier in pChart/class/pDraw.class.php

... See full list

File

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

Class

pDraw

Code

function drawLine($X1, $Y1, $X2, $Y2, $Format = "") {
  $R = isset($Format["R"]) ? $Format["R"] : 0;
  $G = isset($Format["G"]) ? $Format["G"] : 0;
  $B = isset($Format["B"]) ? $Format["B"] : 0;
  $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : NULL;
  $Cpt = isset($Format["Cpt"]) ? $Format["Cpt"] : 1;
  $Mode = isset($Format["Mode"]) ? $Format["Mode"] : 1;
  $Weight = isset($Format["Weight"]) ? $Format["Weight"] : NULL;
  $Threshold = isset($Format["Threshold"]) ? $Format["Threshold"] : NULL;
  if ($this->Antialias == FALSE && $Ticks == NULL) {
    if ($this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0) {
      $ShadowColor = $this
        ->allocateColor($this->Picture, $this->ShadowR, $this->ShadowG, $this->ShadowB, $this->Shadowa);
      imageline($this->Picture, $X1 + $this->ShadowX, $Y1 + $this->ShadowY, $X2 + $this->ShadowX, $Y2 + $this->ShadowY, $ShadowColor);
    }
    $Color = $this
      ->allocateColor($this->Picture, $R, $G, $B, $Alpha);
    imageline($this->Picture, $X1, $Y1, $X2, $Y2, $Color);
    return 0;
  }
  $Distance = sqrt(($X2 - $X1) * ($X2 - $X1) + ($Y2 - $Y1) * ($Y2 - $Y1));
  if ($Distance == 0) {
    return -1;
  }

  /* Derivative algorithm for overweighted lines, re-route to polygons primitives */
  if ($Weight != NULL) {
    $Angle = $this
      ->getAngle($X1, $Y1, $X2, $Y2);
    $PolySettings = array(
      "R" => $R,
      "G" => $G,
      "B" => $B,
      "Alpha" => $Alpha,
      "BorderAlpha" => $Alpha,
    );
    if ($Ticks == NULL) {
      $Points = "";
      $Points[] = cos(deg2rad($Angle - 90)) * $Weight + $X1;
      $Points[] = sin(deg2rad($Angle - 90)) * $Weight + $Y1;
      $Points[] = cos(deg2rad($Angle + 90)) * $Weight + $X1;
      $Points[] = sin(deg2rad($Angle + 90)) * $Weight + $Y1;
      $Points[] = cos(deg2rad($Angle + 90)) * $Weight + $X2;
      $Points[] = sin(deg2rad($Angle + 90)) * $Weight + $Y2;
      $Points[] = cos(deg2rad($Angle - 90)) * $Weight + $X2;
      $Points[] = sin(deg2rad($Angle - 90)) * $Weight + $Y2;
      $this
        ->drawPolygon($Points, $PolySettings);
    }
    else {
      for ($i = 0; $i <= $Distance; $i = $i + $Ticks * 2) {
        $Xa = ($X2 - $X1) / $Distance * $i + $X1;
        $Ya = ($Y2 - $Y1) / $Distance * $i + $Y1;
        $Xb = ($X2 - $X1) / $Distance * ($i + $Ticks) + $X1;
        $Yb = ($Y2 - $Y1) / $Distance * ($i + $Ticks) + $Y1;
        $Points = "";
        $Points[] = cos(deg2rad($Angle - 90)) * $Weight + $Xa;
        $Points[] = sin(deg2rad($Angle - 90)) * $Weight + $Ya;
        $Points[] = cos(deg2rad($Angle + 90)) * $Weight + $Xa;
        $Points[] = sin(deg2rad($Angle + 90)) * $Weight + $Ya;
        $Points[] = cos(deg2rad($Angle + 90)) * $Weight + $Xb;
        $Points[] = sin(deg2rad($Angle + 90)) * $Weight + $Yb;
        $Points[] = cos(deg2rad($Angle - 90)) * $Weight + $Xb;
        $Points[] = sin(deg2rad($Angle - 90)) * $Weight + $Yb;
        $this
          ->drawPolygon($Points, $PolySettings);
      }
    }
    return 1;
  }
  $XStep = ($X2 - $X1) / $Distance;
  $YStep = ($Y2 - $Y1) / $Distance;
  for ($i = 0; $i <= $Distance; $i++) {
    $X = $i * $XStep + $X1;
    $Y = $i * $YStep + $Y1;
    $Color = array(
      "R" => $R,
      "G" => $G,
      "B" => $B,
      "Alpha" => $Alpha,
    );
    if ($Threshold != NULL) {
      foreach ($Threshold as $Key => $Parameters) {
        if ($Y <= $Parameters["MinX"] && $Y >= $Parameters["MaxX"]) {
          if (isset($Parameters["R"])) {
            $RT = $Parameters["R"];
          }
          else {
            $RT = 0;
          }
          if (isset($Parameters["G"])) {
            $GT = $Parameters["G"];
          }
          else {
            $GT = 0;
          }
          if (isset($Parameters["B"])) {
            $BT = $Parameters["B"];
          }
          else {
            $BT = 0;
          }
          if (isset($Parameters["Alpha"])) {
            $AlphaT = $Parameters["Alpha"];
          }
          else {
            $AlphaT = 0;
          }
          $Color = array(
            "R" => $RT,
            "G" => $GT,
            "B" => $BT,
            "Alpha" => $AlphaT,
          );
        }
      }
    }
    if ($Ticks != NULL) {
      if ($Cpt % $Ticks == 0) {
        $Cpt = 0;
        if ($Mode == 1) {
          $Mode = 0;
        }
        else {
          $Mode = 1;
        }
      }
      if ($Mode == 1) {
        $this
          ->drawAntialiasPixel($X, $Y, $Color);
      }
      $Cpt++;
    }
    else {
      $this
        ->drawAntialiasPixel($X, $Y, $Color);
    }
  }
  return array(
    $Cpt,
    $Mode,
  );
}