Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401] [Versions 401 and 402] [Versions 401 and 403]

   1  <?php
   2  
   3  namespace PhpOffice\PhpSpreadsheet\Chart;
   4  
   5  /**
   6   * Created by PhpStorm.
   7   * User: Wiktor Trzonkowski
   8   * Date: 6/17/14
   9   * Time: 12:11 PM.
  10   */
  11  class Axis extends Properties
  12  {
  13      const AXIS_TYPE_CATEGORY = 'catAx';
  14      const AXIS_TYPE_DATE = 'dateAx';
  15      const AXIS_TYPE_VALUE = 'valAx';
  16  
  17      const TIME_UNIT_DAYS = 'days';
  18      const TIME_UNIT_MONTHS = 'months';
  19      const TIME_UNIT_YEARS = 'years';
  20  
  21      public function __construct()
  22      {
  23          parent::__construct();
  24          $this->fillColor = new ChartColor();
  25      }
  26  
  27      /**
  28       * Chart Major Gridlines as.
  29       *
  30       * @var ?GridLines
  31       */
  32      private $majorGridlines;
  33  
  34      /**
  35       * Chart Minor Gridlines as.
  36       *
  37       * @var ?GridLines
  38       */
  39      private $minorGridlines;
  40  
  41      /**
  42       * Axis Number.
  43       *
  44       * @var mixed[]
  45       */
  46      private $axisNumber = [
  47          'format' => self::FORMAT_CODE_GENERAL,
  48          'source_linked' => 1,
  49          'numeric' => null,
  50      ];
  51  
  52      /** @var string */
  53      private $axisType = '';
  54  
  55      /**
  56       * Axis Options.
  57       *
  58       * @var mixed[]
  59       */
  60      private $axisOptions = [
  61          'minimum' => null,
  62          'maximum' => null,
  63          'major_unit' => null,
  64          'minor_unit' => null,
  65          'orientation' => self::ORIENTATION_NORMAL,
  66          'minor_tick_mark' => self::TICK_MARK_NONE,
  67          'major_tick_mark' => self::TICK_MARK_NONE,
  68          'axis_labels' => self::AXIS_LABELS_NEXT_TO,
  69          'horizontal_crosses' => self::HORIZONTAL_CROSSES_AUTOZERO,
  70          'horizontal_crosses_value' => null,
  71          'textRotation' => null,
  72          'hidden' => null,
  73          'majorTimeUnit' => self::TIME_UNIT_YEARS,
  74          'minorTimeUnit' => self::TIME_UNIT_MONTHS,
  75          'baseTimeUnit' => self::TIME_UNIT_DAYS,
  76      ];
  77  
  78      /**
  79       * Fill Properties.
  80       *
  81       * @var ChartColor
  82       */
  83      private $fillColor;
  84  
  85      private const NUMERIC_FORMAT = [
  86          Properties::FORMAT_CODE_NUMBER,
  87          Properties::FORMAT_CODE_DATE,
  88          Properties::FORMAT_CODE_DATE_ISO8601,
  89      ];
  90  
  91      /**
  92       * Get Series Data Type.
  93       *
  94       * @param mixed $format_code
  95       */
  96      public function setAxisNumberProperties($format_code, ?bool $numeric = null, int $sourceLinked = 0): void
  97      {
  98          $format = (string) $format_code;
  99          $this->axisNumber['format'] = $format;
 100          $this->axisNumber['source_linked'] = $sourceLinked;
 101          if (is_bool($numeric)) {
 102              $this->axisNumber['numeric'] = $numeric;
 103          } elseif (in_array($format, self::NUMERIC_FORMAT, true)) {
 104              $this->axisNumber['numeric'] = true;
 105          }
 106      }
 107  
 108      /**
 109       * Get Axis Number Format Data Type.
 110       *
 111       * @return string
 112       */
 113      public function getAxisNumberFormat()
 114      {
 115          return $this->axisNumber['format'];
 116      }
 117  
 118      /**
 119       * Get Axis Number Source Linked.
 120       *
 121       * @return string
 122       */
 123      public function getAxisNumberSourceLinked()
 124      {
 125          return (string) $this->axisNumber['source_linked'];
 126      }
 127  
 128      public function getAxisIsNumericFormat(): bool
 129      {
 130          return $this->axisType === self::AXIS_TYPE_DATE || (bool) $this->axisNumber['numeric'];
 131      }
 132  
 133      public function setAxisOption(string $key, ?string $value): void
 134      {
 135          if ($value !== null && $value !== '') {
 136              $this->axisOptions[$key] = $value;
 137          }
 138      }
 139  
 140      /**
 141       * Set Axis Options Properties.
 142       */
 143      public function setAxisOptionsProperties(
 144          string $axisLabels,
 145          ?string $horizontalCrossesValue = null,
 146          ?string $horizontalCrosses = null,
 147          ?string $axisOrientation = null,
 148          ?string $majorTmt = null,
 149          ?string $minorTmt = null,
 150          ?string $minimum = null,
 151          ?string $maximum = null,
 152          ?string $majorUnit = null,
 153          ?string $minorUnit = null,
 154          ?string $textRotation = null,
 155          ?string $hidden = null,
 156          ?string $baseTimeUnit = null,
 157          ?string $majorTimeUnit = null,
 158          ?string $minorTimeUnit = null
 159      ): void {
 160          $this->axisOptions['axis_labels'] = $axisLabels;
 161          $this->setAxisOption('horizontal_crosses_value', $horizontalCrossesValue);
 162          $this->setAxisOption('horizontal_crosses', $horizontalCrosses);
 163          $this->setAxisOption('orientation', $axisOrientation);
 164          $this->setAxisOption('major_tick_mark', $majorTmt);
 165          $this->setAxisOption('minor_tick_mark', $minorTmt);
 166          $this->setAxisOption('minimum', $minimum);
 167          $this->setAxisOption('maximum', $maximum);
 168          $this->setAxisOption('major_unit', $majorUnit);
 169          $this->setAxisOption('minor_unit', $minorUnit);
 170          $this->setAxisOption('textRotation', $textRotation);
 171          $this->setAxisOption('hidden', $hidden);
 172          $this->setAxisOption('baseTimeUnit', $baseTimeUnit);
 173          $this->setAxisOption('majorTimeUnit', $majorTimeUnit);
 174          $this->setAxisOption('minorTimeUnit', $minorTimeUnit);
 175      }
 176  
 177      /**
 178       * Get Axis Options Property.
 179       *
 180       * @param string $property
 181       *
 182       * @return ?string
 183       */
 184      public function getAxisOptionsProperty($property)
 185      {
 186          return $this->axisOptions[$property];
 187      }
 188  
 189      /**
 190       * Set Axis Orientation Property.
 191       *
 192       * @param string $orientation
 193       */
 194      public function setAxisOrientation($orientation): void
 195      {
 196          $this->axisOptions['orientation'] = (string) $orientation;
 197      }
 198  
 199      public function getAxisType(): string
 200      {
 201          return $this->axisType;
 202      }
 203  
 204      public function setAxisType(string $type): self
 205      {
 206          if ($type === self::AXIS_TYPE_CATEGORY || $type === self::AXIS_TYPE_VALUE || $type === self::AXIS_TYPE_DATE) {
 207              $this->axisType = $type;
 208          } else {
 209              $this->axisType = '';
 210          }
 211  
 212          return $this;
 213      }
 214  
 215      /**
 216       * Set Fill Property.
 217       *
 218       * @param ?string $color
 219       * @param ?int $alpha
 220       * @param ?string $AlphaType
 221       */
 222      public function setFillParameters($color, $alpha = null, $AlphaType = ChartColor::EXCEL_COLOR_TYPE_RGB): void
 223      {
 224          $this->fillColor->setColorProperties($color, $alpha, $AlphaType);
 225      }
 226  
 227      /**
 228       * Get Fill Property.
 229       *
 230       * @param string $property
 231       *
 232       * @return string
 233       */
 234      public function getFillProperty($property)
 235      {
 236          return (string) $this->fillColor->getColorProperty($property);
 237      }
 238  
 239      public function getFillColorObject(): ChartColor
 240      {
 241          return $this->fillColor;
 242      }
 243  
 244      /**
 245       * Get Line Color Property.
 246       *
 247       * @Deprecated 1.24.0
 248       *
 249       * @See Properties::getLineColorProperty()
 250       *      Use the getLineColor property in the Properties class instead
 251       *
 252       * @param string $propertyName
 253       *
 254       * @return null|int|string
 255       */
 256      public function getLineProperty($propertyName)
 257      {
 258          return $this->getLineColorProperty($propertyName);
 259      }
 260  
 261      /** @var string */
 262      private $crossBetween = ''; // 'between' or 'midCat' might be better
 263  
 264      public function setCrossBetween(string $crossBetween): self
 265      {
 266          $this->crossBetween = $crossBetween;
 267  
 268          return $this;
 269      }
 270  
 271      public function getCrossBetween(): string
 272      {
 273          return $this->crossBetween;
 274      }
 275  
 276      public function getMajorGridlines(): ?GridLines
 277      {
 278          return $this->majorGridlines;
 279      }
 280  
 281      public function getMinorGridlines(): ?GridLines
 282      {
 283          return $this->minorGridlines;
 284      }
 285  
 286      public function setMajorGridlines(?GridLines $gridlines): self
 287      {
 288          $this->majorGridlines = $gridlines;
 289  
 290          return $this;
 291      }
 292  
 293      public function setMinorGridlines(?GridLines $gridlines): self
 294      {
 295          $this->minorGridlines = $gridlines;
 296  
 297          return $this;
 298      }
 299  }