You are here

public function PHPExcel_Chart_DataSeriesValues::refresh in Loft Data Grids 7.2

Same name and namespace in other branches
  1. 6.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Chart/DataSeriesValues.php \PHPExcel_Chart_DataSeriesValues::refresh()

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Chart/DataSeriesValues.php, line 280

Class

PHPExcel_Chart_DataSeriesValues
PHPExcel_Chart_DataSeriesValues

Code

public function refresh(PHPExcel_Worksheet $worksheet, $flatten = TRUE) {
  if ($this->_dataSource !== NULL) {
    $calcEngine = PHPExcel_Calculation::getInstance($worksheet
      ->getParent());
    $newDataValues = PHPExcel_Calculation::_unwrapResult($calcEngine
      ->_calculateFormulaValue('=' . $this->_dataSource, NULL, $worksheet
      ->getCell('A1')));
    if ($flatten) {
      $this->_dataValues = PHPExcel_Calculation_Functions::flattenArray($newDataValues);
      foreach ($this->_dataValues as &$dataValue) {
        if (!empty($dataValue) && $dataValue[0] == '#') {
          $dataValue = 0.0;
        }
      }
      unset($dataValue);
    }
    else {
      $cellRange = explode('!', $this->_dataSource);
      if (count($cellRange) > 1) {
        list(, $cellRange) = $cellRange;
      }
      $dimensions = PHPExcel_Cell::rangeDimension(str_replace('$', '', $cellRange));
      if ($dimensions[0] == 1 || $dimensions[1] == 1) {
        $this->_dataValues = PHPExcel_Calculation_Functions::flattenArray($newDataValues);
      }
      else {
        $newArray = array_values(array_shift($newDataValues));
        foreach ($newArray as $i => $newDataSet) {
          $newArray[$i] = array(
            $newDataSet,
          );
        }
        foreach ($newDataValues as $newDataSet) {
          $i = 0;
          foreach ($newDataSet as $newDataVal) {
            array_unshift($newArray[$i++], $newDataVal);
          }
        }
        $this->_dataValues = $newArray;
      }
    }
    $this->_pointCount = count($this->_dataValues);
  }
}