You are here

function pDraw::writeLabel in Visitors 7.2

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

File

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

Class

pDraw

Code

function writeLabel($SeriesName, $Indexes, $Format = "") {
  $OverrideTitle = isset($Format["OverrideTitle"]) ? $Format["OverrideTitle"] : NULL;
  $ForceLabels = isset($Format["ForceLabels"]) ? $Format["ForceLabels"] : NULL;
  $DrawPoint = isset($Format["DrawPoint"]) ? $Format["DrawPoint"] : LABEL_POINT_BOX;
  $DrawVerticalLine = isset($Format["DrawVerticalLine"]) ? $Format["DrawVerticalLine"] : FALSE;
  $VerticalLineR = isset($Format["VerticalLineR"]) ? $Format["VerticalLineR"] : 0;
  $VerticalLineG = isset($Format["VerticalLineG"]) ? $Format["VerticalLineG"] : 0;
  $VerticalLineB = isset($Format["VerticalLineB"]) ? $Format["VerticalLineB"] : 0;
  $VerticalLineAlpha = isset($Format["VerticalLineAlpha"]) ? $Format["VerticalLineAlpha"] : 40;
  $VerticalLineTicks = isset($Format["VerticalLineTicks"]) ? $Format["VerticalLineTicks"] : 2;
  $Data = $this->DataSet
    ->getData();
  list($XMargin, $XDivs) = $this
    ->scaleGetXSettings();
  if (!is_array($Indexes)) {
    $Index = $Indexes;
    $Indexes = "";
    $Indexes[] = $Index;
  }
  if (!is_array($SeriesName)) {
    $SerieName = $SeriesName;
    $SeriesName = "";
    $SeriesName[] = $SerieName;
  }
  if ($ForceLabels != NULL && !is_array($ForceLabels)) {
    $ForceLabel = $ForceLabels;
    $ForceLabels = "";
    $ForceLabels[] = $ForceLabel;
  }
  foreach ($Indexes as $Key => $Index) {
    $Series = "";
    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 + $Index * $XStep;
      if ($DrawVerticalLine) {
        $this
          ->drawLine($X, $this->GraphAreaY1 + $Data["YMargin"], $X, $this->GraphAreaY2 - $Data["YMargin"], array(
          "R" => $VerticalLineR,
          "G" => $VerticalLineG,
          "B" => $VerticalLineB,
          "Alpha" => $VerticalLineAlpha,
          "Ticks" => $VerticalLineTicks,
        ));
      }
      $MinY = $this->GraphAreaY2;
      foreach ($SeriesName as $iKey => $SerieName) {
        if (isset($Data["Series"][$SerieName]["Data"][$Index])) {
          $AxisID = $Data["Series"][$SerieName]["Axis"];
          $XAxisMode = $Data["XAxisDisplay"];
          $XAxisFormat = $Data["XAxisFormat"];
          $XAxisUnit = $Data["XAxisUnit"];
          $AxisMode = $Data["Axis"][$AxisID]["Display"];
          $AxisFormat = $Data["Axis"][$AxisID]["Format"];
          $AxisUnit = $Data["Axis"][$AxisID]["Unit"];
          if (isset($Data["Abscissa"]) && isset($Data["Series"][$Data["Abscissa"]]["Data"][$Index])) {
            $XLabel = $this
              ->scaleFormat($Data["Series"][$Data["Abscissa"]]["Data"][$Index], $XAxisMode, $XAxisFormat, $XAxisUnit);
          }
          else {
            $XLabel = "";
          }
          if ($OverrideTitle != NULL) {
            $Description = $OverrideTitle;
          }
          elseif (count($SeriesName) == 1) {
            $Description = $Data["Series"][$SerieName]["Description"] . " - " . $XLabel;
          }
          elseif (isset($Data["Abscissa"]) && isset($Data["Series"][$Data["Abscissa"]]["Data"][$Index])) {
            $Description = $XLabel;
          }
          $Serie = "";
          $Serie["R"] = $Data["Series"][$SerieName]["Color"]["R"];
          $Serie["G"] = $Data["Series"][$SerieName]["Color"]["G"];
          $Serie["B"] = $Data["Series"][$SerieName]["Color"]["B"];
          $Serie["Alpha"] = $Data["Series"][$SerieName]["Color"]["Alpha"];
          if (count($SeriesName) == 1 && isset($Data["Series"][$SerieName]["XOffset"])) {
            $SerieOffset = $Data["Series"][$SerieName]["XOffset"];
          }
          else {
            $SerieOffset = 0;
          }
          $Value = $Data["Series"][$SerieName]["Data"][$Index];
          if ($Value == VOID) {
            $Value = "NaN";
          }
          if ($ForceLabels != NULL) {
            $Caption = isset($ForceLabels[$Key]) ? $ForceLabels[$Key] : "Not set";
          }
          else {
            $Caption = $this
              ->scaleFormat($Value, $AxisMode, $AxisFormat, $AxisUnit);
          }
          if ($this->LastChartLayout == CHART_LAST_LAYOUT_STACKED) {
            if ($Value >= 0) {
              $LookFor = "+";
            }
            else {
              $LookFor = "-";
            }
            $Value = 0;
            $Done = FALSE;
            foreach ($Data["Series"] as $Name => $SerieLookup) {
              if ($SerieLookup["isDrawable"] == TRUE && $Name != $Data["Abscissa"] && !$Done) {
                if (isset($Data["Series"][$Name]["Data"][$Index]) && $Data["Series"][$Name]["Data"][$Index] != VOID) {
                  if ($Data["Series"][$Name]["Data"][$Index] >= 0 && $LookFor == "+") {
                    $Value = $Value + $Data["Series"][$Name]["Data"][$Index];
                  }
                  if ($Data["Series"][$Name]["Data"][$Index] < 0 && $LookFor == "-") {
                    $Value = $Value - $Data["Series"][$Name]["Data"][$Index];
                  }
                  if ($Name == $SerieName) {
                    $Done = TRUE;
                  }
                }
              }
            }
          }
          $X = floor($this->GraphAreaX1 + $XMargin + $Index * $XStep + $SerieOffset);
          $Y = floor($this
            ->scaleComputeY($Value, array(
            "AxisID" => $AxisID,
          )));
          if ($Y < $MinY) {
            $MinY = $Y;
          }
          if ($DrawPoint == LABEL_POINT_CIRCLE) {
            $this
              ->drawFilledCircle($X, $Y, 3, array(
              "R" => 255,
              "G" => 255,
              "B" => 255,
              "BorderR" => 0,
              "BorderG" => 0,
              "BorderB" => 0,
            ));
          }
          elseif ($DrawPoint == LABEL_POINT_BOX) {
            $this
              ->drawFilledRectangle($X - 2, $Y - 2, $X + 2, $Y + 2, array(
              "R" => 255,
              "G" => 255,
              "B" => 255,
              "BorderR" => 0,
              "BorderG" => 0,
              "BorderB" => 0,
            ));
          }
          $Series[] = array(
            "Format" => $Serie,
            "Caption" => $Caption,
          );
        }
      }
      $this
        ->drawLabelBox($X, $MinY - 3, $Description, $Series, $Format);
    }
    else {
      if ($XDivs == 0) {
        $XStep = ($this->GraphAreaY2 - $this->GraphAreaY1) / 4;
      }
      else {
        $XStep = ($this->GraphAreaY2 - $this->GraphAreaY1 - $XMargin * 2) / $XDivs;
      }
      $Y = $this->GraphAreaY1 + $XMargin + $Index * $XStep;
      if ($DrawVerticalLine) {
        $this
          ->drawLine($this->GraphAreaX1 + $Data["YMargin"], $Y, $this->GraphAreaX2 - $Data["YMargin"], $Y, array(
          "R" => $VerticalLineR,
          "G" => $VerticalLineG,
          "B" => $VerticalLineB,
          "Alpha" => $VerticalLineAlpha,
          "Ticks" => $VerticalLineTicks,
        ));
      }
      $MinX = $this->GraphAreaX2;
      foreach ($SeriesName as $Key => $SerieName) {
        if (isset($Data["Series"][$SerieName]["Data"][$Index])) {
          $AxisID = $Data["Series"][$SerieName]["Axis"];
          $XAxisMode = $Data["XAxisDisplay"];
          $XAxisFormat = $Data["XAxisFormat"];
          $XAxisUnit = $Data["XAxisUnit"];
          $AxisMode = $Data["Axis"][$AxisID]["Display"];
          $AxisFormat = $Data["Axis"][$AxisID]["Format"];
          $AxisUnit = $Data["Axis"][$AxisID]["Unit"];
          if (isset($Data["Abscissa"]) && isset($Data["Series"][$Data["Abscissa"]]["Data"][$Index])) {
            $XLabel = $this
              ->scaleFormat($Data["Series"][$Data["Abscissa"]]["Data"][$Index], $XAxisMode, $XAxisFormat, $XAxisUnit);
          }
          else {
            $XLabel = "";
          }
          if ($OverrideTitle != NULL) {
            $Description = $OverrideTitle;
          }
          elseif (count($SeriesName) == 1) {
            if (isset($Data["Abscissa"]) && isset($Data["Series"][$Data["Abscissa"]]["Data"][$Index])) {
              $Description = $Data["Series"][$SerieName]["Description"] . " - " . $XLabel;
            }
          }
          elseif (isset($Data["Abscissa"]) && isset($Data["Series"][$Data["Abscissa"]]["Data"][$Index])) {
            $Description = $XLabel;
          }
          $Serie = "";
          if (isset($Data["Extended"]["Palette"][$Index])) {
            $Serie["R"] = $Data["Extended"]["Palette"][$Index]["R"];
            $Serie["G"] = $Data["Extended"]["Palette"][$Index]["G"];
            $Serie["B"] = $Data["Extended"]["Palette"][$Index]["B"];
            $Serie["Alpha"] = $Data["Extended"]["Palette"][$Index]["Alpha"];
          }
          else {
            $Serie["R"] = $Data["Series"][$SerieName]["Color"]["R"];
            $Serie["G"] = $Data["Series"][$SerieName]["Color"]["G"];
            $Serie["B"] = $Data["Series"][$SerieName]["Color"]["B"];
            $Serie["Alpha"] = $Data["Series"][$SerieName]["Color"]["Alpha"];
          }
          if (count($SeriesName) == 1 && isset($Data["Series"][$SerieName]["XOffset"])) {
            $SerieOffset = $Data["Series"][$SerieName]["XOffset"];
          }
          else {
            $SerieOffset = 0;
          }
          $Value = $Data["Series"][$SerieName]["Data"][$Index];
          if ($ForceLabels != NULL) {
            $Caption = isset($ForceLabels[$Key]) ? $ForceLabels[$Key] : "Not set";
          }
          else {
            $Caption = $this
              ->scaleFormat($Value, $AxisMode, $AxisFormat, $AxisUnit);
          }
          if ($Value == VOID) {
            $Value = "NaN";
          }
          if ($this->LastChartLayout == CHART_LAST_LAYOUT_STACKED) {
            if ($Value >= 0) {
              $LookFor = "+";
            }
            else {
              $LookFor = "-";
            }
            $Value = 0;
            $Done = FALSE;
            foreach ($Data["Series"] as $Name => $SerieLookup) {
              if ($SerieLookup["isDrawable"] == TRUE && $Name != $Data["Abscissa"] && !$Done) {
                if (isset($Data["Series"][$Name]["Data"][$Index]) && $Data["Series"][$Name]["Data"][$Index] != VOID) {
                  if ($Data["Series"][$Name]["Data"][$Index] >= 0 && $LookFor == "+") {
                    $Value = $Value + $Data["Series"][$Name]["Data"][$Index];
                  }
                  if ($Data["Series"][$Name]["Data"][$Index] < 0 && $LookFor == "-") {
                    $Value = $Value - $Data["Series"][$Name]["Data"][$Index];
                  }
                  if ($Name == $SerieName) {
                    $Done = TRUE;
                  }
                }
              }
            }
          }
          $X = floor($this
            ->scaleComputeY($Value, array(
            "AxisID" => $AxisID,
          )));
          $Y = floor($this->GraphAreaY1 + $XMargin + $Index * $XStep + $SerieOffset);
          if ($X < $MinX) {
            $MinX = $X;
          }
          if ($DrawPoint == LABEL_POINT_CIRCLE) {
            $this
              ->drawFilledCircle($X, $Y, 3, array(
              "R" => 255,
              "G" => 255,
              "B" => 255,
              "BorderR" => 0,
              "BorderG" => 0,
              "BorderB" => 0,
            ));
          }
          elseif ($DrawPoint == LABEL_POINT_BOX) {
            $this
              ->drawFilledRectangle($X - 2, $Y - 2, $X + 2, $Y + 2, array(
              "R" => 255,
              "G" => 255,
              "B" => 255,
              "BorderR" => 0,
              "BorderG" => 0,
              "BorderB" => 0,
            ));
          }
          $Series[] = array(
            "Format" => $Serie,
            "Caption" => $Caption,
          );
        }
      }
      $this
        ->drawLabelBox($MinX, $Y - 3, $Description, $Series, $Format);
    }
  }
}