You are here

function pDraw::drawFilledSplineChart in Visitors 7.2

Same name and namespace in other branches
  1. 7 pChart/class/pDraw.class.php \pDraw::drawFilledSplineChart()

File

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

Class

pDraw

Code

function drawFilledSplineChart($Format = NULL) {
  $DisplayValues = isset($Format["DisplayValues"]) ? $Format["DisplayValues"] : FALSE;
  $DisplayOffset = isset($Format["DisplayOffset"]) ? $Format["DisplayOffset"] : 2;
  $DisplayColor = isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
  $DisplayR = isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
  $DisplayG = isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
  $DisplayB = isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
  $AroundZero = isset($Format["AroundZero"]) ? $Format["AroundZero"] : TRUE;
  $Threshold = isset($Format["Threshold"]) ? $Format["Threshold"] : NULL;
  $this->LastChartLayout = CHART_LAST_LAYOUT_REGULAR;
  $Data = $this->DataSet
    ->getData();
  list($XMargin, $XDivs) = $this
    ->scaleGetXSettings();
  foreach ($Data["Series"] as $SerieName => $Serie) {
    if ($Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"]) {
      $R = $Serie["Color"]["R"];
      $G = $Serie["Color"]["G"];
      $B = $Serie["Color"]["B"];
      $Alpha = $Serie["Color"]["Alpha"];
      $Ticks = $Serie["Ticks"];
      if ($DisplayColor == DISPLAY_AUTO) {
        $DisplayR = $R;
        $DisplayG = $G;
        $DisplayB = $B;
      }
      $AxisID = $Serie["Axis"];
      $Mode = $Data["Axis"][$AxisID]["Display"];
      $Format = $Data["Axis"][$AxisID]["Format"];
      $Unit = $Data["Axis"][$AxisID]["Unit"];
      $PosArray = $this
        ->scaleComputeY($Serie["Data"], array(
        "AxisID" => $Serie["Axis"],
      ));
      if ($AroundZero) {
        $YZero = $this
          ->scaleComputeY(0, array(
          "AxisID" => $Serie["Axis"],
        ));
      }
      if ($Threshold != NULL) {
        foreach ($Threshold as $Key => $Params) {
          $Threshold[$Key]["MinX"] = $this
            ->scaleComputeY($Params["Min"], array(
            "AxisID" => $Serie["Axis"],
          ));
          $Threshold[$Key]["MaxX"] = $this
            ->scaleComputeY($Params["Max"], array(
            "AxisID" => $Serie["Axis"],
          ));
        }
      }
      $this->DataSet->Data["Series"][$SerieName]["XOffset"] = 0;
      if ($Data["Orientation"] == SCALE_POS_LEFTRIGHT) {
        if ($XDivs == 0) {
          $XStep = ($this->GraphAreaX2 - $this->GraphAreaX1) / 4;
        }
        else {
          $XStep = ($this->GraphAreaX2 - $this->GraphAreaX1 - $XMargin * 2) / $XDivs;
        }
        $X = $this->GraphAreaX1 + $XMargin;
        $WayPoints = "";
        $Force = $XStep / 5;
        if (!$AroundZero) {
          $YZero = $this->GraphAreaY2 - 1;
        }
        if ($YZero > $this->GraphAreaY2 - 1) {
          $YZero = $this->GraphAreaY2 - 1;
        }
        if ($YZero < $this->GraphAreaY1 + 1) {
          $YZero = $this->GraphAreaY1 + 1;
        }
        $LastX = "";
        $LastY = "";
        if (!is_array($PosArray)) {
          $Value = $PosArray;
          $PosArray = "";
          $PosArray[0] = $Value;
        }
        foreach ($PosArray as $Key => $Y) {
          if ($DisplayValues) {
            $this
              ->drawText($X, $Y - $DisplayOffset, $this
              ->scaleFormat($Serie["Data"][$Key], $Mode, $Format, $Unit), array(
              "R" => $DisplayR,
              "G" => $DisplayG,
              "B" => $DisplayB,
              "Align" => TEXT_ALIGN_BOTTOMMIDDLE,
            ));
          }
          if ($Y == VOID) {
            $Area = $this
              ->drawSpline($WayPoints, array(
              "Force" => $Force,
              "PathOnly" => TRUE,
            ));
            if ($Area != "") {
              foreach ($Area as $key => $Points) {
                $Corners = "";
                $Corners[] = $Area[$key][0]["X"];
                $Corners[] = $YZero;
                foreach ($Points as $subKey => $Point) {
                  if ($subKey == count($Points) - 1) {
                    $Corners[] = $Point["X"] - 1;
                  }
                  else {
                    $Corners[] = $Point["X"];
                  }
                  $Corners[] = $Point["Y"] + 1;
                }
                $Corners[] = $Points[$subKey]["X"] - 1;
                $Corners[] = $YZero;
                $this
                  ->drawPolygonChart($Corners, array(
                  "R" => $R,
                  "G" => $G,
                  "B" => $B,
                  "Alpha" => $Alpha / 2,
                  "NoBorder" => TRUE,
                  "Threshold" => $Threshold,
                ));
              }
              $this
                ->drawSpline($WayPoints, array(
                "Force" => $Force,
                "R" => $R,
                "G" => $G,
                "B" => $B,
                "Alpha" => $Alpha,
                "Ticks" => $Ticks,
              ));
            }
            $WayPoints = "";
          }
          else {
            $WayPoints[] = array(
              $X,
              $Y - 0.5,
            );
          }

          /* -.5 for AA visual fix */
          $X = $X + $XStep;
        }
        $Area = $this
          ->drawSpline($WayPoints, array(
          "Force" => $Force,
          "PathOnly" => TRUE,
        ));
        if ($Area != "") {
          foreach ($Area as $key => $Points) {
            $Corners = "";
            $Corners[] = $Area[$key][0]["X"];
            $Corners[] = $YZero;
            foreach ($Points as $subKey => $Point) {
              if ($subKey == count($Points) - 1) {
                $Corners[] = $Point["X"] - 1;
              }
              else {
                $Corners[] = $Point["X"];
              }
              $Corners[] = $Point["Y"] + 1;
            }
            $Corners[] = $Points[$subKey]["X"] - 1;
            $Corners[] = $YZero;
            $this
              ->drawPolygonChart($Corners, array(
              "R" => $R,
              "G" => $G,
              "B" => $B,
              "Alpha" => $Alpha / 2,
              "NoBorder" => TRUE,
              "Threshold" => $Threshold,
            ));
          }
          $this
            ->drawSpline($WayPoints, array(
            "Force" => $Force,
            "R" => $R,
            "G" => $G,
            "B" => $B,
            "Alpha" => $Alpha,
            "Ticks" => $Ticks,
          ));
        }
      }
      else {
        if ($XDivs == 0) {
          $YStep = ($this->GraphAreaY2 - $this->GraphAreaY1) / 4;
        }
        else {
          $YStep = ($this->GraphAreaY2 - $this->GraphAreaY1 - $XMargin * 2) / $XDivs;
        }
        $Y = $this->GraphAreaY1 + $XMargin;
        $WayPoints = "";
        $Force = $YStep / 5;
        if (!$AroundZero) {
          $YZero = $this->GraphAreaX1 + 1;
        }
        if ($YZero > $this->GraphAreaX2 - 1) {
          $YZero = $this->GraphAreaX2 - 1;
        }
        if ($YZero < $this->GraphAreaX1 + 1) {
          $YZero = $this->GraphAreaX1 + 1;
        }
        if (!is_array($PosArray)) {
          $Value = $PosArray;
          $PosArray = "";
          $PosArray[0] = $Value;
        }
        foreach ($PosArray as $Key => $X) {
          if ($DisplayValues) {
            $this
              ->drawText($X + $DisplayOffset, $Y, $this
              ->scaleFormat($Serie["Data"][$Key], $Mode, $Format, $Unit), array(
              "Angle" => 270,
              "R" => $DisplayR,
              "G" => $DisplayG,
              "B" => $DisplayB,
              "Align" => TEXT_ALIGN_BOTTOMMIDDLE,
            ));
          }
          if ($X == VOID) {
            $Area = $this
              ->drawSpline($WayPoints, array(
              "Force" => $Force,
              "PathOnly" => TRUE,
            ));
            if ($Area != "") {
              foreach ($Area as $key => $Points) {
                $Corners = "";
                $Corners[] = $YZero;
                $Corners[] = $Area[$key][0]["Y"];
                foreach ($Points as $subKey => $Point) {
                  if ($subKey == count($Points) - 1) {
                    $Corners[] = $Point["X"] - 1;
                  }
                  else {
                    $Corners[] = $Point["X"];
                  }
                  $Corners[] = $Point["Y"];
                }
                $Corners[] = $YZero;
                $Corners[] = $Points[$subKey]["Y"] - 1;
                $this
                  ->drawPolygonChart($Corners, array(
                  "R" => $R,
                  "G" => $G,
                  "B" => $B,
                  "Alpha" => $Alpha / 2,
                  "NoBorder" => TRUE,
                  "Threshold" => $Threshold,
                ));
              }
              $this
                ->drawSpline($WayPoints, array(
                "Force" => $Force,
                "R" => $R,
                "G" => $G,
                "B" => $B,
                "Alpha" => $Alpha,
                "Ticks" => $Ticks,
              ));
            }
            $WayPoints = "";
          }
          else {
            $WayPoints[] = array(
              $X,
              $Y,
            );
          }
          $Y = $Y + $YStep;
        }
        $Area = $this
          ->drawSpline($WayPoints, array(
          "Force" => $Force,
          "PathOnly" => TRUE,
        ));
        if ($Area != "") {
          foreach ($Area as $key => $Points) {
            $Corners = "";
            $Corners[] = $YZero;
            $Corners[] = $Area[$key][0]["Y"];
            foreach ($Points as $subKey => $Point) {
              if ($subKey == count($Points) - 1) {
                $Corners[] = $Point["X"] - 1;
              }
              else {
                $Corners[] = $Point["X"];
              }
              $Corners[] = $Point["Y"];
            }
            $Corners[] = $YZero;
            $Corners[] = $Points[$subKey]["Y"] - 1;
            $this
              ->drawPolygonChart($Corners, array(
              "R" => $R,
              "G" => $G,
              "B" => $B,
              "Alpha" => $Alpha / 2,
              "NoBorder" => TRUE,
              "Threshold" => $Threshold,
            ));
          }
          $this
            ->drawSpline($WayPoints, array(
            "Force" => $Force,
            "R" => $R,
            "G" => $G,
            "B" => $B,
            "Alpha" => $Alpha,
            "Ticks" => $Ticks,
          ));
        }
      }
    }
  }
}