You are here

function pDraw::drawStepChart in Visitors 7.2

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

File

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

Class

pDraw

Code

function drawStepChart($Format = NULL) {
  $BreakVoid = isset($Format["BreakVoid"]) ? $Format["BreakVoid"] : FALSE;
  $ReCenter = isset($Format["ReCenter"]) ? $Format["ReCenter"] : 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;
  $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 (isset($Serie["Description"])) {
        $SerieDescription = $Serie["Description"];
      }
      else {
        $SerieDescription = $SerieName;
      }
      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"];
      $Color = array(
        "R" => $R,
        "G" => $G,
        "B" => $B,
        "Alpha" => $Alpha,
        "Ticks" => $Ticks,
        "Weight" => $Weight,
      );
      $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;
        $Init = FALSE;
        foreach ($PosArray as $Key => $Y) {
          if ($DisplayValues && $Serie["Data"][$Key] != VOID) {
            if ($Y <= $LastY) {
              $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 ($Y != VOID && $LastX != NULL && $LastY != NULL) {
            $this
              ->drawLine($LastX, $LastY, $X, $LastY, $Color);
            $this
              ->drawLine($X, $LastY, $X, $Y, $Color);
            if ($ReCenter && $X + $XStep < $this->GraphAreaX2 - $XMargin) {
              $this
                ->drawLine($X, $Y, $X + $XStep, $Y, $Color);
              if ($RecordImageMap) {
                $this
                  ->addToImageMap("RECT", floor($X - $ImageMapPlotSize) . "," . floor($Y - $ImageMapPlotSize) . "," . floor($X + $XStep + $ImageMapPlotSize) . "," . floor($Y + $ImageMapPlotSize), $this
                  ->toHTMLColor($R, $G, $B), $SerieDescription, $this
                  ->scaleFormat($Serie["Data"][$Key], $Mode, $Format, $Unit));
              }
            }
            else {
              if ($RecordImageMap) {
                $this
                  ->addToImageMap("RECT", floor($LastX - $ImageMapPlotSize) . "," . floor($LastY - $ImageMapPlotSize) . "," . floor($X + $ImageMapPlotSize) . "," . floor($LastY + $ImageMapPlotSize), $this
                  ->toHTMLColor($R, $G, $B), $SerieDescription, $this
                  ->scaleFormat($Serie["Data"][$Key], $Mode, $Format, $Unit));
              }
            }
          }
          if ($Y != VOID && $LastY == NULL && $LastGoodY != NULL && !$BreakVoid) {
            if ($ReCenter) {
              $this
                ->drawLine($LastGoodX + $XStep, $LastGoodY, $X, $LastGoodY, $BreakSettings);
              if ($RecordImageMap) {
                $this
                  ->addToImageMap("RECT", floor($LastGoodX + $XStep - $ImageMapPlotSize) . "," . floor($LastGoodY - $ImageMapPlotSize) . "," . floor($X + $ImageMapPlotSize) . "," . floor($LastGoodY + $ImageMapPlotSize), $this
                  ->toHTMLColor($R, $G, $B), $SerieDescription, $this
                  ->scaleFormat($Serie["Data"][$Key], $Mode, $Format, $Unit));
              }
            }
            else {
              $this
                ->drawLine($LastGoodX, $LastGoodY, $X, $LastGoodY, $BreakSettings);
              if ($RecordImageMap) {
                $this
                  ->addToImageMap("RECT", floor($LastGoodX - $ImageMapPlotSize) . "," . floor($LastGoodY - $ImageMapPlotSize) . "," . floor($X + $ImageMapPlotSize) . "," . floor($LastGoodY + $ImageMapPlotSize), $this
                  ->toHTMLColor($R, $G, $B), $SerieDescription, $this
                  ->scaleFormat($Serie["Data"][$Key], $Mode, $Format, $Unit));
              }
            }
            $this
              ->drawLine($X, $LastGoodY, $X, $Y, $BreakSettings);
            $LastGoodY = NULL;
          }
          elseif (!$BreakVoid && $LastGoodY == NULL && $Y != VOID) {
            $this
              ->drawLine($this->GraphAreaX1 + $XMargin, $Y, $X, $Y, $BreakSettings);
            if ($RecordImageMap) {
              $this
                ->addToImageMap("RECT", floor($this->GraphAreaX1 + $XMargin - $ImageMapPlotSize) . "," . floor($Y - $ImageMapPlotSize) . "," . floor($X + $ImageMapPlotSize) . "," . floor($Y + $ImageMapPlotSize), $this
                ->toHTMLColor($R, $G, $B), $SerieDescription, $this
                ->scaleFormat($Serie["Data"][$Key], $Mode, $Format, $Unit));
            }
          }
          if ($Y != VOID) {
            $LastGoodY = $Y;
            $LastGoodX = $X;
          }
          if ($Y == VOID) {
            $Y = NULL;
          }
          if (!$Init && $ReCenter) {
            $X = $X - $XStep / 2;
            $Init = TRUE;
          }
          $LastX = $X;
          $LastY = $Y;
          if ($LastX < $this->GraphAreaX1 + $XMargin) {
            $LastX = $this->GraphAreaX1 + $XMargin;
          }
          $X = $X + $XStep;
        }
        if ($ReCenter) {
          $this
            ->drawLine($LastX, $LastY, $this->GraphAreaX2 - $XMargin, $LastY, $Color);
          if ($RecordImageMap) {
            $this
              ->addToImageMap("RECT", floor($LastX - $ImageMapPlotSize) . "," . floor($LastY - $ImageMapPlotSize) . "," . floor($this->GraphAreaX2 - $XMargin + $ImageMapPlotSize) . "," . floor($LastY + $ImageMapPlotSize), $this
              ->toHTMLColor($R, $G, $B), $SerieDescription, $this
              ->scaleFormat($Serie["Data"][$Key], $Mode, $Format, $Unit));
          }
        }
      }
      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;
        $Init = FALSE;
        foreach ($PosArray as $Key => $X) {
          if ($DisplayValues && $Serie["Data"][$Key] != VOID) {
            if ($X >= $LastX) {
              $Align = TEXT_ALIGN_MIDDLELEFT;
              $Offset = $DisplayOffset;
            }
            else {
              $Align = TEXT_ALIGN_MIDDLERIGHT;
              $Offset = -$DisplayOffset;
            }
            $this
              ->drawText($X + $Offset + $Weight, $Y, $this
              ->scaleFormat($Serie["Data"][$Key], $Mode, $Format, $Unit), array(
              "R" => $DisplayR,
              "G" => $DisplayG,
              "B" => $DisplayB,
              "Align" => $Align,
            ));
          }
          if ($X != VOID && $LastX != NULL && $LastY != NULL) {
            $this
              ->drawLine($LastX, $LastY, $LastX, $Y, $Color);
            $this
              ->drawLine($LastX, $Y, $X, $Y, $Color);
            if ($RecordImageMap) {
              $this
                ->addToImageMap("RECT", floor($LastX - $ImageMapPlotSize) . "," . floor($LastY - $ImageMapPlotSize) . "," . floor($LastX + $XStep + $ImageMapPlotSize) . "," . floor($Y + $ImageMapPlotSize), $this
                ->toHTMLColor($R, $G, $B), $SerieDescription, $this
                ->scaleFormat($Serie["Data"][$Key], $Mode, $Format, $Unit));
            }
          }
          if ($X != VOID && $LastX == NULL && $LastGoodY != NULL && !$BreakVoid) {
            $this
              ->drawLine($LastGoodX, $LastGoodY, $LastGoodX, $LastGoodY + $YStep, $Color);
            if ($RecordImageMap) {
              $this
                ->addToImageMap("RECT", floor($LastGoodX - $ImageMapPlotSize) . "," . floor($LastGoodY - $ImageMapPlotSize) . "," . floor($LastGoodX + $ImageMapPlotSize) . "," . floor($LastGoodY + $YStep + $ImageMapPlotSize), $this
                ->toHTMLColor($R, $G, $B), $SerieDescription, $this
                ->scaleFormat($Serie["Data"][$Key], $Mode, $Format, $Unit));
            }
            $this
              ->drawLine($LastGoodX, $LastGoodY + $YStep, $LastGoodX, $Y, $BreakSettings);
            if ($RecordImageMap) {
              $this
                ->addToImageMap("RECT", floor($LastGoodX - $ImageMapPlotSize) . "," . floor($LastGoodY + $YStep - $ImageMapPlotSize) . "," . floor($LastGoodX + $ImageMapPlotSize) . "," . floor($YStep + $ImageMapPlotSize), $this
                ->toHTMLColor($R, $G, $B), $SerieDescription, $this
                ->scaleFormat($Serie["Data"][$Key], $Mode, $Format, $Unit));
            }
            $this
              ->drawLine($LastGoodX, $Y, $X, $Y, $BreakSettings);
            $LastGoodY = NULL;
          }
          elseif ($X != VOID && $LastGoodY == NULL && !$BreakVoid) {
            $this
              ->drawLine($X, $this->GraphAreaY1 + $XMargin, $X, $Y, $BreakSettings);
            if ($RecordImageMap) {
              $this
                ->addToImageMap("RECT", floor($X - $ImageMapPlotSize) . "," . floor($this->GraphAreaY1 + $XMargin - $ImageMapPlotSize) . "," . floor($X + $ImageMapPlotSize) . "," . floor($Y + $ImageMapPlotSize), $this
                ->toHTMLColor($R, $G, $B), $SerieDescription, $this
                ->scaleFormat($Serie["Data"][$Key], $Mode, $Format, $Unit));
            }
          }
          if ($X != VOID) {
            $LastGoodY = $Y;
            $LastGoodX = $X;
          }
          if ($X == VOID) {
            $X = NULL;
          }
          if (!$Init && $ReCenter) {
            $Y = $Y - $YStep / 2;
            $Init = TRUE;
          }
          $LastX = $X;
          $LastY = $Y;
          if ($LastY < $this->GraphAreaY1 + $XMargin) {
            $LastY = $this->GraphAreaY1 + $XMargin;
          }
          $Y = $Y + $YStep;
        }
        if ($ReCenter) {
          $this
            ->drawLine($LastX, $LastY, $LastX, $this->GraphAreaY2 - $XMargin, $Color);
          if ($RecordImageMap) {
            $this
              ->addToImageMap("RECT", floor($LastX - $ImageMapPlotSize) . "," . floor($LastY - $ImageMapPlotSize) . "," . floor($LastX + $ImageMapPlotSize) . "," . floor($this->GraphAreaY2 - $XMargin + $ImageMapPlotSize), $this
              ->toHTMLColor($R, $G, $B), $SerieDescription, $this
              ->scaleFormat($Serie["Data"][$Key], $Mode, $Format, $Unit));
          }
        }
      }
    }
  }
}