You are here

function pChart::drawCubicCurve in Visitors 8

Same name and namespace in other branches
  1. 7.0 pchart/pChart.inc \pChart::drawCubicCurve()
1 call to pChart::drawCubicCurve()
pChart::drawFilledCubicCurve in pchart/pChart.inc

File

pchart/pChart.inc, line 918

Class

pChart

Code

function drawCubicCurve(&$Data, &$DataDescription, $Accuracy = 0.1, $SerieName = "") {

  /* Validate the Data and DataDescription array */
  $this
    ->validateDataDescription("drawCubicCurve", $DataDescription);
  $this
    ->validateData("drawCubicCurve", $Data);
  $GraphID = 0;
  foreach ($DataDescription["Values"] as $Key2 => $ColName) {
    if ($SerieName == "" || $SerieName == $ColName) {
      $XIn = "";
      $Yin = "";
      $Yt = "";
      $U = "";
      $XIn[0] = 0;
      $YIn[0] = 0;
      $ID = 0;
      foreach ($DataDescription["Description"] as $keyI => $ValueI) {
        if ($keyI == $ColName) {
          $ColorID = $ID;
        }
        $ID++;
      }
      $Index = 1;
      $XLast = -1;
      $Missing = "";
      foreach ($Data as $Key => $Values) {
        if (isset($Data[$Key][$ColName])) {
          $Value = $Data[$Key][$ColName];
          $XIn[$Index] = $Index;
          $YIn[$Index] = $Value;
          if (!is_numeric($Value)) {
            $Missing[$Index] = TRUE;
          }
          $Index++;
        }
      }
      $Index--;
      $Yt[0] = 0;
      $Yt[1] = 0;
      $U[1] = 0;
      for ($i = 2; $i <= $Index - 1; $i++) {
        $Sig = ($XIn[$i] - $XIn[$i - 1]) / ($XIn[$i + 1] - $XIn[$i - 1]);
        $p = $Sig * $Yt[$i - 1] + 2;
        $Yt[$i] = ($Sig - 1) / $p;
        $U[$i] = ($YIn[$i + 1] - $YIn[$i]) / ($XIn[$i + 1] - $XIn[$i]) - ($YIn[$i] - $YIn[$i - 1]) / ($XIn[$i] - $XIn[$i - 1]);
        $U[$i] = (6 * $U[$i] / ($XIn[$i + 1] - $XIn[$i - 1]) - $Sig * $U[$i - 1]) / $p;
      }
      $qn = 0;
      $un = 0;
      $Yt[$Index] = ($un - $qn * $U[$Index - 1]) / ($qn * $Yt[$Index - 1] + 1);
      for ($k = $Index - 1; $k >= 1; $k--) {
        $Yt[$k] = $Yt[$k] * $Yt[$k + 1] + $U[$k];
      }
      $XPos = $this->GArea_X1 + $this->GAreaXOffset;
      for ($X = 1; $X <= $Index; $X = $X + $Accuracy) {
        $klo = 1;
        $khi = $Index;
        $k = $khi - $klo;
        while ($k > 1) {
          $k = $khi - $klo;
          if ($XIn[$k] >= $X) {
            $khi = $k;
          }
          else {
            $klo = $k;
          }
        }
        $klo = $khi - 1;
        $h = $XIn[$khi] - $XIn[$klo];
        $a = ($XIn[$khi] - $X) / $h;
        $b = ($X - $XIn[$klo]) / $h;
        $Value = $a * $YIn[$klo] + $b * $YIn[$khi] + (($a * $a * $a - $a) * $Yt[$klo] + ($b * $b * $b - $b) * $Yt[$khi]) * ($h * $h) / 6;
        $YPos = $this->GArea_Y2 - ($Value - $this->VMin) * $this->DivisionRatio;
        if ($XLast != -1 && !isset($Missing[floor($X)]) && !isset($Missing[floor($X + 1)])) {
          $this
            ->drawLine($XLast, $YLast, $XPos, $YPos, $this->Palette[$ColorID]["R"], $this->Palette[$ColorID]["G"], $this->Palette[$ColorID]["B"], TRUE);
        }
        $XLast = $XPos;
        $YLast = $YPos;
        $XPos = $XPos + $this->DivisionWidth * $Accuracy;
      }

      // Add potentialy missing values
      $XPos = $XPos - $this->DivisionWidth * $Accuracy;
      if ($XPos < $this->GArea_X2 - $this->GAreaXOffset) {
        $YPos = $this->GArea_Y2 - ($YIn[$Index] - $this->VMin) * $this->DivisionRatio;
        $this
          ->drawLine($XLast, $YLast, $this->GArea_X2 - $this->GAreaXOffset, $YPos, $this->Palette[$ColorID]["R"], $this->Palette[$ColorID]["G"], $this->Palette[$ColorID]["B"], TRUE);
      }
      $GraphID++;
    }
  }
}