You are here

function pDraw::drawLineChart in Visitors 7.2

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

File

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

Class

pDraw

Code

function drawLineChart($Format = NULL) {
  $BreakVoid = isset($Format["BreakVoid"]) ? $Format["BreakVoid"] : TRUE;
  $VoidTicks = isset($Format["VoidTicks"]) ? $Format["VoidTicks"] : 4;
  $BreakR = isset($Format["BreakR"]) ? $Format["BreakR"] : NULL;
  $BreakG = isset($Format["BreakG"]) ? $Format["BreakG"] : NULL;
  $BreakB = isset($Format["BreakB"]) ? $Format["BreakB"] : 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;
  $RecordImageMap = isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE;
  $ImageMapPlotSize = isset($Format["ImageMapPlotSize"]) ? $Format["ImageMapPlotSize"] : 5;
  $ForceColor = isset($Format["ForceColor"]) ? $Format["ForceColor"] : FALSE;
  $ForceR = isset($Format["ForceR"]) ? $Format["ForceR"] : 0;
  $ForceG = isset($Format["ForceG"]) ? $Format["ForceG"] : 0;
  $ForceB = isset($Format["ForceB"]) ? $Format["ForceB"] : 0;
  $ForceAlpha = isset($Format["ForceAlpha"]) ? $Format["ForceAlpha"] : 100;
  $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"];
      $Weight = $Serie["Weight"];
      if ($ForceColor) {
        $R = $ForceR;
        $G = $ForceG;
        $B = $ForceB;
        $Alpha = $ForceAlpha;
      }
      if ($BreakR == NULL) {
        $BreakSettings = array(
          "R" => $R,
          "G" => $G,
          "B" => $B,
          "Alpha" => $Alpha,
          "Ticks" => $VoidTicks,
          "Weight" => $Weight,
        );
      }
      else {
        $BreakSettings = array(
          "R" => $BreakR,
          "G" => $BreakG,
          "B" => $BreakB,
          "Alpha" => $Alpha,
          "Ticks" => $VoidTicks,
          "Weight" => $Weight,
        );
      }
      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"];
      if (isset($Serie["Description"])) {
        $SerieDescription = $Serie["Description"];
      }
      else {
        $SerieDescription = $SerieName;
      }
      $PosArray = $this
        ->scaleComputeY($Serie["Data"], 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;
        $LastX = NULL;
        $LastY = NULL;
        if (!is_array($PosArray)) {
          $Value = $PosArray;
          $PosArray = "";
          $PosArray[0] = $Value;
        }
        $LastGoodY = NULL;
        $LastGoodX = NULL;
        foreach ($PosArray as $Key => $Y) {
          if ($DisplayValues && $Serie["Data"][$Key] != VOID) {
            if ($Serie["Data"][$Key] > 0) {
              $Align = TEXT_ALIGN_BOTTOMMIDDLE;
              $Offset = $DisplayOffset;
            }
            else {
              $Align = TEXT_ALIGN_TOPMIDDLE;
              $Offset = -$DisplayOffset;
            }
            $this
              ->drawText($X, $Y - $Offset - $Weight, $this
              ->scaleFormat($Serie["Data"][$Key], $Mode, $Format, $Unit), array(
              "R" => $DisplayR,
              "G" => $DisplayG,
              "B" => $DisplayB,
              "Align" => $Align,
            ));
          }
          if ($RecordImageMap && $Y != VOID) {
            $this
              ->addToImageMap("CIRCLE", floor($X) . "," . floor($Y) . "," . $ImageMapPlotSize, $this
              ->toHTMLColor($R, $G, $B), $SerieDescription, $this
              ->scaleFormat($Serie["Data"][$Key], $Mode, $Format, $Unit));
          }
          if ($Y != VOID && $LastX != NULL && $LastY != NULL) {
            $this
              ->drawLine($LastX, $LastY, $X, $Y, array(
              "R" => $R,
              "G" => $G,
              "B" => $B,
              "Alpha" => $Alpha,
              "Ticks" => $Ticks,
              "Weight" => $Weight,
            ));
          }
          if ($Y != VOID && $LastY == NULL && $LastGoodY != NULL && !$BreakVoid) {
            $this
              ->drawLine($LastGoodX, $LastGoodY, $X, $Y, $BreakSettings);
            $LastGoodY = NULL;
          }
          if ($Y != VOID) {
            $LastGoodY = $Y;
            $LastGoodX = $X;
          }
          if ($Y == VOID) {
            $Y = NULL;
          }
          $LastX = $X;
          $LastY = $Y;
          $X = $X + $XStep;
        }
      }
      else {
        if ($XDivs == 0) {
          $YStep = ($this->GraphAreaY2 - $this->GraphAreaY1) / 4;
        }
        else {
          $YStep = ($this->GraphAreaY2 - $this->GraphAreaY1 - $XMargin * 2) / $XDivs;
        }
        $Y = $this->GraphAreaY1 + $XMargin;
        $LastX = NULL;
        $LastY = NULL;
        if (!is_array($PosArray)) {
          $Value = $PosArray;
          $PosArray = "";
          $PosArray[0] = $Value;
        }
        $LastGoodY = NULL;
        $LastGoodX = NULL;
        foreach ($PosArray as $Key => $X) {
          if ($DisplayValues && $Serie["Data"][$Key] != VOID) {
            $this
              ->drawText($X + $DisplayOffset + $Weight, $Y, $this
              ->scaleFormat($Serie["Data"][$Key], $Mode, $Format, $Unit), array(
              "Angle" => 270,
              "R" => $DisplayR,
              "G" => $DisplayG,
              "B" => $DisplayB,
              "Align" => TEXT_ALIGN_BOTTOMMIDDLE,
            ));
          }
          if ($RecordImageMap && $X != VOID) {
            $this
              ->addToImageMap("CIRCLE", floor($X) . "," . floor($Y) . "," . $ImageMapPlotSize, $this
              ->toHTMLColor($R, $G, $B), $SerieDescription, $this
              ->scaleFormat($Serie["Data"][$Key], $Mode, $Format, $Unit));
          }
          if ($X != VOID && $LastX != NULL && $LastY != NULL) {
            $this
              ->drawLine($LastX, $LastY, $X, $Y, array(
              "R" => $R,
              "G" => $G,
              "B" => $B,
              "Alpha" => $Alpha,
              "Ticks" => $Ticks,
              "Weight" => $Weight,
            ));
          }
          if ($X != VOID && $LastX == NULL && $LastGoodY != NULL && !$BreakVoid) {
            $this
              ->drawLine($LastGoodX, $LastGoodY, $X, $Y, $BreakSettings);
            $LastGoodY = NULL;
          }
          if ($X != VOID) {
            $LastGoodY = $Y;
            $LastGoodX = $X;
          }
          if ($X == VOID) {
            $X = NULL;
          }
          $LastX = $X;
          $LastY = $Y;
          $Y = $Y + $YStep;
        }
      }
    }
  }
}