You are here

function pDraw::drawStackedAreaChart in Visitors 7.2

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

File

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

Class

pDraw

Code

function drawStackedAreaChart($Format = NULL) {
  $DrawLine = isset($Format["DrawLine"]) ? $Format["DrawLine"] : FALSE;
  $LineSurrounding = isset($Format["LineSurrounding"]) ? $Format["LineSurrounding"] : NULL;
  $LineR = isset($Format["LineR"]) ? $Format["LineR"] : VOID;
  $LineG = isset($Format["LineG"]) ? $Format["LineG"] : VOID;
  $LineB = isset($Format["LineB"]) ? $Format["LineB"] : VOID;
  $LineAlpha = isset($Format["LineAlpha"]) ? $Format["LineAlpha"] : 100;
  $DrawPlot = isset($Format["DrawPlot"]) ? $Format["DrawPlot"] : FALSE;
  $PlotRadius = isset($Format["PlotRadius"]) ? $Format["PlotRadius"] : 2;
  $PlotBorder = isset($Format["PlotBorder"]) ? $Format["PlotBorder"] : 1;
  $PlotBorderSurrounding = isset($Format["PlotBorderSurrounding"]) ? $Format["PlotBorderSurrounding"] : NULL;
  $PlotBorderR = isset($Format["PlotBorderR"]) ? $Format["PlotBorderR"] : 0;
  $PlotBorderG = isset($Format["PlotBorderG"]) ? $Format["PlotBorderG"] : 0;
  $PlotBorderB = isset($Format["PlotBorderB"]) ? $Format["PlotBorderB"] : 0;
  $PlotBorderAlpha = isset($Format["PlotBorderAlpha"]) ? $Format["PlotBorderAlpha"] : 50;
  $ForceTransparency = isset($Format["ForceTransparency"]) ? $Format["ForceTransparency"] : NULL;
  $this->LastChartLayout = CHART_LAST_LAYOUT_STACKED;
  $Data = $this->DataSet
    ->getData();
  list($XMargin, $XDivs) = $this
    ->scaleGetXSettings();
  $RestoreShadow = $this->Shadow;
  $this->Shadow = FALSE;

  /* Build the offset data series */
  $OffsetData = "";
  $OverallOffset = "";
  $SerieOrder = "";
  foreach ($Data["Series"] as $SerieName => $Serie) {
    if ($Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"]) {
      $SerieOrder[] = $SerieName;
      foreach ($Serie["Data"] as $Key => $Value) {
        if ($Value == VOID) {
          $Value = 0;
        }
        if ($Value >= 0) {
          $Sign = "+";
        }
        else {
          $Sign = "-";
        }
        if (!isset($OverallOffset[$Key]) || !isset($OverallOffset[$Key][$Sign])) {
          $OverallOffset[$Key][$Sign] = 0;
        }
        if ($Sign == "+") {
          $Data["Series"][$SerieName]["Data"][$Key] = $Value + $OverallOffset[$Key][$Sign];
        }
        else {
          $Data["Series"][$SerieName]["Data"][$Key] = $Value - $OverallOffset[$Key][$Sign];
        }
        $OverallOffset[$Key][$Sign] = $OverallOffset[$Key][$Sign] + abs($Value);
      }
    }
  }
  $SerieOrder = array_reverse($SerieOrder);
  $LastX = "";
  $LastY = "";
  foreach ($SerieOrder as $Key => $SerieName) {
    $Serie = $Data["Series"][$SerieName];
    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 ($ForceTransparency != NULL) {
        $Alpha = $ForceTransparency;
      }
      $Color = array(
        "R" => $R,
        "G" => $G,
        "B" => $B,
        "Alpha" => $Alpha,
      );
      if ($LineSurrounding != NULL) {
        $LineColor = array(
          "R" => $R + $LineSurrounding,
          "G" => $G + $LineSurrounding,
          "B" => $B + $LineSurrounding,
          "Alpha" => $Alpha,
        );
      }
      elseif ($LineR != VOID) {
        $LineColor = array(
          "R" => $LineR,
          "G" => $LineG,
          "B" => $LineB,
          "Alpha" => $LineAlpha,
        );
      }
      else {
        $LineColor = $Color;
      }
      if ($PlotBorderSurrounding != NULL) {
        $PlotBorderColor = array(
          "R" => $R + $PlotBorderSurrounding,
          "G" => $G + $PlotBorderSurrounding,
          "B" => $B + $PlotBorderSurrounding,
          "Alpha" => $PlotBorderAlpha,
        );
      }
      else {
        $PlotBorderColor = array(
          "R" => $PlotBorderR,
          "G" => $PlotBorderG,
          "B" => $PlotBorderB,
          "Alpha" => $PlotBorderAlpha,
        );
      }
      $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"],
      ), TRUE);
      $YZero = $this
        ->scaleComputeY(0, array(
        "AxisID" => $Serie["Axis"],
      ));
      $this->DataSet->Data["Series"][$SerieName]["XOffset"] = 0;
      if ($Data["Orientation"] == SCALE_POS_LEFTRIGHT) {
        if ($YZero < $this->GraphAreaY1 + 1) {
          $YZero = $this->GraphAreaY1 + 1;
        }
        if ($YZero > $this->GraphAreaY2 - 1) {
          $YZero = $this->GraphAreaY2 - 1;
        }
        if ($XDivs == 0) {
          $XStep = ($this->GraphAreaX2 - $this->GraphAreaX1) / 4;
        }
        else {
          $XStep = ($this->GraphAreaX2 - $this->GraphAreaX1 - $XMargin * 2) / $XDivs;
        }
        $X = $this->GraphAreaX1 + $XMargin;
        if (!is_array($PosArray)) {
          $Value = $PosArray;
          $PosArray = "";
          $PosArray[0] = $Value;
        }
        $Plots = "";
        $Plots[] = $X;
        $Plots[] = $YZero;
        foreach ($PosArray as $Key => $Height) {
          if ($Height != VOID) {
            $Plots[] = $X;
            $Plots[] = $YZero - $Height;
          }
          $X = $X + $XStep;
        }
        $Plots[] = $X - $XStep;
        $Plots[] = $YZero;
        $this
          ->drawPolygon($Plots, $Color);
        $this->Shadow = $RestoreShadow;
        if ($DrawLine) {
          for ($i = 2; $i <= count($Plots) - 6; $i = $i + 2) {
            $this
              ->drawLine($Plots[$i], $Plots[$i + 1], $Plots[$i + 2], $Plots[$i + 3], $LineColor);
          }
        }
        if ($DrawPlot) {
          for ($i = 2; $i <= count($Plots) - 4; $i = $i + 2) {
            if ($PlotBorder != 0) {
              $this
                ->drawFilledCircle($Plots[$i], $Plots[$i + 1], $PlotRadius + $PlotBorder, $PlotBorderColor);
            }
            $this
              ->drawFilledCircle($Plots[$i], $Plots[$i + 1], $PlotRadius, $Color);
          }
        }
        $this->Shadow = FALSE;
      }
      elseif ($Data["Orientation"] == SCALE_POS_TOPBOTTOM) {
        if ($YZero < $this->GraphAreaX1 + 1) {
          $YZero = $this->GraphAreaX1 + 1;
        }
        if ($YZero > $this->GraphAreaX2 - 1) {
          $YZero = $this->GraphAreaX2 - 1;
        }
        if ($XDivs == 0) {
          $YStep = ($this->GraphAreaY2 - $this->GraphAreaY1) / 4;
        }
        else {
          $YStep = ($this->GraphAreaY2 - $this->GraphAreaY1 - $XMargin * 2) / $XDivs;
        }
        $Y = $this->GraphAreaY1 + $XMargin;
        if (!is_array($PosArray)) {
          $Value = $PosArray;
          $PosArray = "";
          $PosArray[0] = $Value;
        }
        $Plots = "";
        $Plots[] = $YZero;
        $Plots[] = $Y;
        foreach ($PosArray as $Key => $Height) {
          if ($Height != VOID) {
            $Plots[] = $YZero + $Height;
            $Plots[] = $Y;
          }
          $Y = $Y + $YStep;
        }
        $Plots[] = $YZero;
        $Plots[] = $Y - $YStep;
        $this
          ->drawPolygon($Plots, $Color);
        $this->Shadow = $RestoreShadow;
        if ($DrawLine) {
          for ($i = 2; $i <= count($Plots) - 6; $i = $i + 2) {
            $this
              ->drawLine($Plots[$i], $Plots[$i + 1], $Plots[$i + 2], $Plots[$i + 3], $LineColor);
          }
        }
        if ($DrawPlot) {
          for ($i = 2; $i <= count($Plots) - 4; $i = $i + 2) {
            if ($PlotBorder != 0) {
              $this
                ->drawFilledCircle($Plots[$i], $Plots[$i + 1], $PlotRadius + $PlotBorder, $PlotBorderColor);
            }
            $this
              ->drawFilledCircle($Plots[$i], $Plots[$i + 1], $PlotRadius, $Color);
          }
        }
        $this->Shadow = FALSE;
      }
    }
  }
  $this->Shadow = $RestoreShadow;
}