function pDraw::drawGradientArea

5.x pDraw.class.php pDraw::drawGradientArea($X1, $Y1, $X2, $Y2, $Direction, $Format = "")
5 calls to pDraw::drawGradientArea()
pDraw::drawBarChart in inc/pchart/pchart/class/pDraw.class.php
pDraw::drawDerivative in inc/pchart/pchart/class/pDraw.class.php
pDraw::drawLabelBox in inc/pchart/pchart/class/pDraw.class.php
pDraw::drawProgress in inc/pchart/pchart/class/pDraw.class.php
pDraw::drawStackedBarChart in inc/pchart/pchart/class/pDraw.class.php

File

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

Class

pDraw

Code

function drawGradientArea($X1, $Y1, $X2, $Y2, $Direction, $Format = "") 
 {
  $StartR = isset($Format ["StartR"]) ? $Format ["StartR"] : 90;
  $StartG = isset($Format ["StartG"]) ? $Format ["StartG"] : 90;
  $StartB = isset($Format ["StartB"]) ? $Format ["StartB"] : 90;
  $EndR = isset($Format ["EndR"]) ? $Format ["EndR"] : 0;
  $EndG = isset($Format ["EndG"]) ? $Format ["EndG"] : 0;
  $EndB = isset($Format ["EndB"]) ? $Format ["EndB"] : 0;
  $Alpha = isset($Format ["Alpha"]) ? $Format ["Alpha"] : 100;
  $Levels = isset($Format ["Levels"]) ? $Format ["Levels"] : NULL;

  $Shadow = $this->Shadow;
  $this->Shadow = FALSE;

  if ($StartR == $EndR && $StartG == $EndG && $StartB == $EndB) 
   {
    $this->drawFilledRectangle($X1, $Y1, $X2, $Y2, array("R" => $StartR, "G" => $StartG, "B" => $StartB, "Alpha" => $Alpha));
    return (0);
  }

  if ($Levels != NULL) 
   {
    $EndR = $StartR + $Levels;
    $EndG = $StartG + $Levels;
    $EndB = $StartB + $Levels;
  }

  if ($X1 > $X2) {
    list($X1, $X2) = array($X2, $X1);
  }
  if ($Y1 > $Y2) {
    list($Y1, $Y2) = array($Y2, $Y1);
  }

  if ($Direction == DIRECTION_VERTICAL) {
    $Width = abs($Y2 -$Y1);
  }
  if ($Direction == DIRECTION_HORIZONTAL) {
    $Width = abs($X2 -$X1);
  }

  $Step = max(abs($EndR -$StartR), abs($EndG -$StartG), abs($EndB -$StartB));
  $StepSize = $Width / $Step;
  $RStep = ($EndR -$StartR) / $Step;
  $GStep = ($EndG -$StartG) / $Step;
  $BStep = ($EndB -$StartB) / $Step;

  $R = $StartR;
  $G = $StartG;
  $B = $StartB;
  switch ($Direction) 
   {
    case DIRECTION_VERTICAL:
      $StartY = $Y1;
      $EndY = floor($Y2) + 1;
      $LastY2 = $StartY;
      for ($i = 0; $i <= $Step; $i++) 
       {
        $Y2 = floor($StartY + ($i * $StepSize));

        if ($Y2 > $EndY) {
          $Y2 = $EndY;
        }
        if (($Y1 != $Y2 && $Y1 < $Y2) || $Y2 == $EndY) 
         {
          $Color = array("R" => $R, "G" => $G, "B" => $B, "Alpha" => $Alpha);
          $this->drawFilledRectangle($X1, $Y1, $X2, $Y2, $Color);
          $LastY2 = max($LastY2, $Y2);
          $Y1 = $Y2 + 1;
        }
        $R = $R + $RStep;
        $G = $G + $GStep;
        $B = $B + $BStep;
      }
      if ($LastY2 < $EndY && isset($Color)) {
        for ($i = $LastY2 + 1; $i <= $EndY; $i++) {
          $this->drawLine($X1, $i, $X2, $i, $Color);
        }
      }
      break;

    case DIRECTION_HORIZONTAL:
      $StartX = $X1;
      $EndX = $X2;
      for ($i = 0; $i <= $Step; $i++) 
       {
        $X2 = floor($StartX + ($i * $StepSize));

        if ($X2 > $EndX) {
          $X2 = $EndX;
        }
        if (($X1 != $X2 && $X1 < $X2) || $X2 == $EndX) 
         {
          $Color = array("R" => $R, "G" => $G, "B" => $B, "Alpha" => $Alpha);
          $this->drawFilledRectangle($X1, $Y1, $X2, $Y2, $Color);
          $X1 = $X2 + 1;
        }
        $R = $R + $RStep;
        $G = $G + $GStep;
        $B = $B + $BStep;
      }
      if ($X2 < $EndX && isset($Color)) {
        $this->drawFilledRectangle($X2, $Y1, $EndX, $Y2, $Color);
      }
      break;
  }

  $this->Shadow = $Shadow;

}