[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/phpexcel/PHPExcel/Chart/ -> DataSeriesValues.php (source)

   1  <?php
   2  
   3  /**
   4   * PHPExcel_Chart_DataSeriesValues
   5   *
   6   * Copyright (c) 2006 - 2015 PHPExcel
   7   *
   8   * This library is free software; you can redistribute it and/or
   9   * modify it under the terms of the GNU Lesser General Public
  10   * License as published by the Free Software Foundation; either
  11   * version 2.1 of the License, or (at your option) any later version.
  12   *
  13   * This library is distributed in the hope that it will be useful,
  14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16   * Lesser General Public License for more details.
  17   *
  18   * You should have received a copy of the GNU Lesser General Public
  19   * License along with this library; if not, write to the Free Software
  20   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  21   *
  22   * @category    PHPExcel
  23   * @package        PHPExcel_Chart
  24   * @copyright    Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
  25   * @license        http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
  26   * @version        ##VERSION##, ##DATE##
  27   */
  28  class PHPExcel_Chart_DataSeriesValues
  29  {
  30  
  31      const DATASERIES_TYPE_STRING    = 'String';
  32      const DATASERIES_TYPE_NUMBER    = 'Number';
  33  
  34      private static $dataTypeValues = array(
  35          self::DATASERIES_TYPE_STRING,
  36          self::DATASERIES_TYPE_NUMBER,
  37      );
  38  
  39      /**
  40       * Series Data Type
  41       *
  42       * @var    string
  43       */
  44      private $dataType;
  45  
  46      /**
  47       * Series Data Source
  48       *
  49       * @var    string
  50       */
  51      private $dataSource;
  52  
  53      /**
  54       * Format Code
  55       *
  56       * @var    string
  57       */
  58      private $formatCode;
  59  
  60      /**
  61       * Series Point Marker
  62       *
  63       * @var    string
  64       */
  65      private $pointMarker;
  66  
  67      /**
  68       * Point Count (The number of datapoints in the dataseries)
  69       *
  70       * @var    integer
  71       */
  72      private $pointCount = 0;
  73  
  74      /**
  75       * Data Values
  76       *
  77       * @var    array of mixed
  78       */
  79      private $dataValues = array();
  80  
  81      /**
  82       * Create a new PHPExcel_Chart_DataSeriesValues object
  83       */
  84      public function __construct($dataType = self::DATASERIES_TYPE_NUMBER, $dataSource = null, $formatCode = null, $pointCount = 0, $dataValues = array(), $marker = null)
  85      {
  86          $this->setDataType($dataType);
  87          $this->dataSource = $dataSource;
  88          $this->formatCode = $formatCode;
  89          $this->pointCount = $pointCount;
  90          $this->dataValues = $dataValues;
  91          $this->pointMarker = $marker;
  92      }
  93  
  94      /**
  95       * Get Series Data Type
  96       *
  97       * @return    string
  98       */
  99      public function getDataType()
 100      {
 101          return $this->dataType;
 102      }
 103  
 104      /**
 105       * Set Series Data Type
 106       *
 107       * @param    string    $dataType    Datatype of this data series
 108       *                                Typical values are:
 109       *                                    PHPExcel_Chart_DataSeriesValues::DATASERIES_TYPE_STRING
 110       *                                        Normally used for axis point values
 111       *                                    PHPExcel_Chart_DataSeriesValues::DATASERIES_TYPE_NUMBER
 112       *                                        Normally used for chart data values
 113       * @return    PHPExcel_Chart_DataSeriesValues
 114       */
 115      public function setDataType($dataType = self::DATASERIES_TYPE_NUMBER)
 116      {
 117          if (!in_array($dataType, self::$dataTypeValues)) {
 118              throw new PHPExcel_Chart_Exception('Invalid datatype for chart data series values');
 119          }
 120          $this->dataType = $dataType;
 121  
 122          return $this;
 123      }
 124  
 125      /**
 126       * Get Series Data Source (formula)
 127       *
 128       * @return    string
 129       */
 130      public function getDataSource()
 131      {
 132          return $this->dataSource;
 133      }
 134  
 135      /**
 136       * Set Series Data Source (formula)
 137       *
 138       * @param    string    $dataSource
 139       * @return    PHPExcel_Chart_DataSeriesValues
 140       */
 141      public function setDataSource($dataSource = null, $refreshDataValues = true)
 142      {
 143          $this->dataSource = $dataSource;
 144  
 145          if ($refreshDataValues) {
 146              //    TO DO
 147          }
 148  
 149          return $this;
 150      }
 151  
 152      /**
 153       * Get Point Marker
 154       *
 155       * @return string
 156       */
 157      public function getPointMarker()
 158      {
 159          return $this->pointMarker;
 160      }
 161  
 162      /**
 163       * Set Point Marker
 164       *
 165       * @param    string    $marker
 166       * @return    PHPExcel_Chart_DataSeriesValues
 167       */
 168      public function setPointMarker($marker = null)
 169      {
 170          $this->pointMarker = $marker;
 171  
 172          return $this;
 173      }
 174  
 175      /**
 176       * Get Series Format Code
 177       *
 178       * @return    string
 179       */
 180      public function getFormatCode()
 181      {
 182          return $this->formatCode;
 183      }
 184  
 185      /**
 186       * Set Series Format Code
 187       *
 188       * @param    string    $formatCode
 189       * @return    PHPExcel_Chart_DataSeriesValues
 190       */
 191      public function setFormatCode($formatCode = null)
 192      {
 193          $this->formatCode = $formatCode;
 194  
 195          return $this;
 196      }
 197  
 198      /**
 199       * Get Series Point Count
 200       *
 201       * @return    integer
 202       */
 203      public function getPointCount()
 204      {
 205          return $this->pointCount;
 206      }
 207  
 208      /**
 209       * Identify if the Data Series is a multi-level or a simple series
 210       *
 211       * @return    boolean
 212       */
 213      public function isMultiLevelSeries()
 214      {
 215          if (count($this->dataValues) > 0) {
 216              return is_array($this->dataValues[0]);
 217          }
 218          return null;
 219      }
 220  
 221      /**
 222       * Return the level count of a multi-level Data Series
 223       *
 224       * @return    boolean
 225       */
 226      public function multiLevelCount()
 227      {
 228          $levelCount = 0;
 229          foreach ($this->dataValues as $dataValueSet) {
 230              $levelCount = max($levelCount, count($dataValueSet));
 231          }
 232          return $levelCount;
 233      }
 234  
 235      /**
 236       * Get Series Data Values
 237       *
 238       * @return    array of mixed
 239       */
 240      public function getDataValues()
 241      {
 242          return $this->dataValues;
 243      }
 244  
 245      /**
 246       * Get the first Series Data value
 247       *
 248       * @return    mixed
 249       */
 250      public function getDataValue()
 251      {
 252          $count = count($this->dataValues);
 253          if ($count == 0) {
 254              return null;
 255          } elseif ($count == 1) {
 256              return $this->dataValues[0];
 257          }
 258          return $this->dataValues;
 259      }
 260  
 261      /**
 262       * Set Series Data Values
 263       *
 264       * @param    array    $dataValues
 265       * @param    boolean    $refreshDataSource
 266       *                    TRUE - refresh the value of dataSource based on the values of $dataValues
 267       *                    FALSE - don't change the value of dataSource
 268       * @return    PHPExcel_Chart_DataSeriesValues
 269       */
 270      public function setDataValues($dataValues = array(), $refreshDataSource = true)
 271      {
 272          $this->dataValues = PHPExcel_Calculation_Functions::flattenArray($dataValues);
 273          $this->pointCount = count($dataValues);
 274  
 275          if ($refreshDataSource) {
 276              //    TO DO
 277          }
 278  
 279          return $this;
 280      }
 281  
 282      private function stripNulls($var)
 283      {
 284          return $var !== null;
 285      }
 286  
 287      public function refresh(PHPExcel_Worksheet $worksheet, $flatten = true)
 288      {
 289          if ($this->dataSource !== null) {
 290              $calcEngine = PHPExcel_Calculation::getInstance($worksheet->getParent());
 291              $newDataValues = PHPExcel_Calculation::unwrapResult(
 292                  $calcEngine->_calculateFormulaValue(
 293                      '='.$this->dataSource,
 294                      null,
 295                      $worksheet->getCell('A1')
 296                  )
 297              );
 298              if ($flatten) {
 299                  $this->dataValues = PHPExcel_Calculation_Functions::flattenArray($newDataValues);
 300                  foreach ($this->dataValues as &$dataValue) {
 301                      if ((!empty($dataValue)) && ($dataValue[0] == '#')) {
 302                          $dataValue = 0.0;
 303                      }
 304                  }
 305                  unset($dataValue);
 306              } else {
 307                  $cellRange = explode('!', $this->dataSource);
 308                  if (count($cellRange) > 1) {
 309                      list(, $cellRange) = $cellRange;
 310                  }
 311  
 312                  $dimensions = PHPExcel_Cell::rangeDimension(str_replace('$', '', $cellRange));
 313                  if (($dimensions[0] == 1) || ($dimensions[1] == 1)) {
 314                      $this->dataValues = PHPExcel_Calculation_Functions::flattenArray($newDataValues);
 315                  } else {
 316                      $newArray = array_values(array_shift($newDataValues));
 317                      foreach ($newArray as $i => $newDataSet) {
 318                          $newArray[$i] = array($newDataSet);
 319                      }
 320  
 321                      foreach ($newDataValues as $newDataSet) {
 322                          $i = 0;
 323                          foreach ($newDataSet as $newDataVal) {
 324                              array_unshift($newArray[$i++], $newDataVal);
 325                          }
 326                      }
 327                      $this->dataValues = $newArray;
 328                  }
 329              }
 330              $this->pointCount = count($this->dataValues);
 331          }
 332      }
 333  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1