You are here

function pScatter::writeScatterLabel in Visitors 7

Same name and namespace in other branches
  1. 7.2 pChart/class/pScatter.class.php \pScatter::writeScatterLabel()

File

pChart/class/pScatter.class.php, line 886

Class

pScatter

Code

function writeScatterLabel($ScatterSerieID, $Points, $Format = "") {
  $OverrideTitle = isset($Format["OverrideTitle"]) ? $Format["OverrideTitle"] : NULL;
  $DrawPoint = isset($Format["DrawPoint"]) ? $Format["DrawPoint"] : LABEL_POINT_BOX;
  $Decimals = isset($Format["Decimals"]) ? $Format["Decimals"] : NULL;
  $Data = $this->pDataObject
    ->getData();
  $Palette = $this->pDataObject
    ->getPalette();
  if (!is_array($Points)) {
    $Point = $Points;
    $Points = "";
    $Points[0] = $Point;
  }
  if (!isset($Data["ScatterSeries"][$ScatterSerieID])) {
    return 0;
  }
  $Series = $Data["ScatterSeries"][$ScatterSerieID];
  $SerieX = $Series["X"];
  $SerieValuesX = $Data["Series"][$SerieX]["Data"];
  $SerieXAxis = $Data["Series"][$SerieX]["Axis"];
  $SerieY = $Series["Y"];
  $SerieValuesY = $Data["Series"][$SerieY]["Data"];
  $SerieYAxis = $Data["Series"][$SerieY]["Axis"];
  $PosArrayX = $this
    ->getPosArray($SerieValuesX, $SerieXAxis);
  if (!is_array($PosArrayX)) {
    $Value = $PosArrayX;
    $PosArrayX = "";
    $PosArrayX[0] = $Value;
  }
  $PosArrayY = $this
    ->getPosArray($SerieValuesY, $SerieYAxis);
  if (!is_array($PosArrayY)) {
    $Value = $PosArrayY;
    $PosArrayY = "";
    $PosArrayY[0] = $Value;
  }
  foreach ($Points as $Key => $Point) {
    if (isset($PosArrayX[$Point]) && isset($PosArrayY[$Point])) {
      $X = floor($PosArrayX[$Point]);
      $Y = floor($PosArrayY[$Point]);
      if ($DrawPoint == LABEL_POINT_CIRCLE) {
        $this->pChartObject
          ->drawFilledCircle($X, $Y, 3, array(
          "R" => 255,
          "G" => 255,
          "B" => 255,
          "BorderR" => 0,
          "BorderG" => 0,
          "BorderB" => 0,
        ));
      }
      elseif ($DrawPoint == LABEL_POINT_BOX) {
        $this->pChartObject
          ->drawFilledRectangle($X - 2, $Y - 2, $X + 2, $Y + 2, array(
          "R" => 255,
          "G" => 255,
          "B" => 255,
          "BorderR" => 0,
          "BorderG" => 0,
          "BorderB" => 0,
        ));
      }
      $Serie = "";
      $Serie["R"] = $Series["Color"]["R"];
      $Serie["G"] = $Series["Color"]["G"];
      $Serie["B"] = $Series["Color"]["B"];
      $Serie["Alpha"] = $Series["Color"]["Alpha"];
      $XAxisMode = $Data["Axis"][$SerieXAxis]["Display"];
      $XAxisFormat = $Data["Axis"][$SerieXAxis]["Format"];
      $XAxisUnit = $Data["Axis"][$SerieXAxis]["Unit"];
      if ($Decimals == NULL) {
        $XValue = $SerieValuesX[$Point];
      }
      else {
        $XValue = round($SerieValuesX[$Point], $Decimals);
      }
      $XValue = $this->pChartObject
        ->scaleFormat($XValue, $XAxisMode, $XAxisFormat, $XAxisUnit);
      $YAxisMode = $Data["Axis"][$SerieYAxis]["Display"];
      $YAxisFormat = $Data["Axis"][$SerieYAxis]["Format"];
      $YAxisUnit = $Data["Axis"][$SerieYAxis]["Unit"];
      if ($Decimals == NULL) {
        $YValue = $SerieValuesY[$Point];
      }
      else {
        $YValue = round($SerieValuesY[$Point], $Decimals);
      }
      $YValue = $this->pChartObject
        ->scaleFormat($YValue, $YAxisMode, $YAxisFormat, $YAxisUnit);
      $Caption = $XValue . " / " . $YValue;
      if (isset($Series["Description"])) {
        $Description = $Series["Description"];
      }
      else {
        $Description = "No description";
      }
      $Series = "";
      $Series[] = array(
        "Format" => $Serie,
        "Caption" => $Caption,
      );
      $this->pChartObject
        ->drawLabelBox($X, $Y - 3, $Description, $Series, $Format);
    }
  }
}