You are here

function pBubble::bubbleScale in Visitors 7.2

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

File

pChart/class/pBubble.class.php, line 33

Class

pBubble

Code

function bubbleScale($DataSeries, $WeightSeries) {
  if (!is_array($DataSeries)) {
    $DataSeries = array(
      $DataSeries,
    );
  }
  if (!is_array($WeightSeries)) {
    $WeightSeries = array(
      $WeightSeries,
    );
  }

  /* Parse each data series to find the new min & max boundaries to scale */
  $NewPositiveSerie = "";
  $NewNegativeSerie = "";
  $MaxValues = 0;
  $LastPositive = 0;
  $LastNegative = 0;
  foreach ($DataSeries as $Key => $SerieName) {
    $SerieWeightName = $WeightSeries[$Key];
    $this->pDataObject
      ->setSerieDrawable($SerieWeightName, FALSE);
    if (count($this->pDataObject->Data["Series"][$SerieName]["Data"]) > $MaxValues) {
      $MaxValues = count($this->pDataObject->Data["Series"][$SerieName]["Data"]);
    }
    foreach ($this->pDataObject->Data["Series"][$SerieName]["Data"] as $Key => $Value) {
      if ($Value >= 0) {
        $BubbleBounds = $Value + $this->pDataObject->Data["Series"][$SerieWeightName]["Data"][$Key];
        if (!isset($NewPositiveSerie[$Key])) {
          $NewPositiveSerie[$Key] = $BubbleBounds;
        }
        elseif ($NewPositiveSerie[$Key] < $BubbleBounds) {
          $NewPositiveSerie[$Key] = $BubbleBounds;
        }
        $LastPositive = $BubbleBounds;
      }
      else {
        $BubbleBounds = $Value - $this->pDataObject->Data["Series"][$SerieWeightName]["Data"][$Key];
        if (!isset($NewNegativeSerie[$Key])) {
          $NewNegativeSerie[$Key] = $BubbleBounds;
        }
        elseif ($NewNegativeSerie[$Key] > $BubbleBounds) {
          $NewNegativeSerie[$Key] = $BubbleBounds;
        }
        $LastNegative = $BubbleBounds;
      }
    }
  }

  /* Check for missing values and all the fake positive serie */
  if ($NewPositiveSerie != "") {
    for ($i = 0; $i < $MaxValues; $i++) {
      if (!isset($NewPositiveSerie[$i])) {
        $NewPositiveSerie[$i] = $LastPositive;
      }
    }
    $this->pDataObject
      ->addPoints($NewPositiveSerie, "BubbleFakePositiveSerie");
  }

  /* Check for missing values and all the fake negative serie */
  if ($NewNegativeSerie != "") {
    for ($i = 0; $i < $MaxValues; $i++) {
      if (!isset($NewNegativeSerie[$i])) {
        $NewNegativeSerie[$i] = $LastNegative;
      }
    }
    $this->pDataObject
      ->addPoints($NewNegativeSerie, "BubbleFakeNegativeSerie");
  }
}