function pData::normalize

5.x pData.class.php pData::normalize($NormalizationFactor = 100, $UnitChange = NULL, $Round = 1)

File

inc/pchart/pchart/class/pData.class.php, line 610

Class

pData

Code

function normalize($NormalizationFactor = 100, $UnitChange = NULL, $Round = 1) 
 {
  $Abscissa = $this->Data ["Abscissa"];

  $SelectedSeries = "";
  $MaxVal = 0;
  foreach ($this->Data ["Axis"] as $AxisID => $Axis) 
   {
    if ($UnitChange != NULL) {
      $this->Data ["Axis"][$AxisID]["Unit"] = $UnitChange;
    }

    foreach ($this->Data ["Series"] as $SerieName => $Serie) 
     {
      if ($Serie ["Axis"] == $AxisID && $Serie ["isDrawable"] == TRUE && $SerieName != $Abscissa) 
       {
        $SelectedSeries [$SerieName] = $SerieName;

        if (count($Serie ["Data"]) > $MaxVal) {
          $MaxVal = count($Serie ["Data"]);
        }
      }
    }
  }

  for ($i = 0; $i <= $MaxVal -1; $i++) 
   {
    $Factor = 0;
    foreach ($SelectedSeries as $Key => $SerieName) 
     {
      $Value = $this->Data ["Series"][$SerieName]["Data"][$i];
      if ($Value != VOID) {
        $Factor = $Factor + abs($Value);
      }
    }

    if ($Factor != 0) 
     {
      $Factor = $NormalizationFactor / $Factor;

      foreach ($SelectedSeries as $Key => $SerieName) 
       {
        $Value = $this->Data ["Series"][$SerieName]["Data"][$i];

        if ($Value != VOID && $Factor != $NormalizationFactor) {
          $this->Data ["Series"][$SerieName]["Data"][$i] = round(abs($Value) * $Factor, $Round);
        }
        elseif ($Value == VOID || $Value == 0) {
          $this->Data ["Series"][$SerieName]["Data"][$i] = VOID;
        }
        elseif ($Factor == $NormalizationFactor) {
          $this->Data ["Series"][$SerieName]["Data"][$i] = $NormalizationFactor;
        }
      }
    }
  }

  foreach ($SelectedSeries as $Key => $SerieName) 
   {
    $this->Data ["Series"][$SerieName]["Max"] = max($this->stripVOID($this->Data ["Series"][$SerieName]["Data"]));
    $this->Data ["Series"][$SerieName]["Min"] = min($this->stripVOID($this->Data ["Series"][$SerieName]["Data"]));
  }
}