| 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 |
/** @var ?AxisText */ |
| 56 |
private $axisText; |
| 57 |
|
| 58 |
/** |
| 59 |
* Axis Options. |
| 60 |
* |
| 61 |
* @var mixed[] |
| 62 |
*/ |
| 63 |
private $axisOptions = [ |
| 64 |
'minimum' => null, |
| 65 |
'maximum' => null, |
| 66 |
'major_unit' => null, |
| 67 |
'minor_unit' => null, |
| 68 |
'orientation' => self::ORIENTATION_NORMAL, |
| 69 |
'minor_tick_mark' => self::TICK_MARK_NONE, |
| 70 |
'major_tick_mark' => self::TICK_MARK_NONE, |
| 71 |
'axis_labels' => self::AXIS_LABELS_NEXT_TO, |
| 72 |
'horizontal_crosses' => self::HORIZONTAL_CROSSES_AUTOZERO, |
| 73 |
'horizontal_crosses_value' => null, |
| 74 |
'textRotation' => null, |
| 75 |
'hidden' => null, |
| 76 |
'majorTimeUnit' => self::TIME_UNIT_YEARS, |
| 77 |
'minorTimeUnit' => self::TIME_UNIT_MONTHS, |
| 78 |
'baseTimeUnit' => self::TIME_UNIT_DAYS, |
| 79 |
]; |
| 80 |
|
| 81 |
/** |
| 82 |
* Fill Properties. |
| 83 |
* |
| 84 |
* @var ChartColor |
| 85 |
*/ |
| 86 |
private $fillColor; |
| 87 |
|
| 88 |
private const NUMERIC_FORMAT = [ |
| 89 |
Properties::FORMAT_CODE_NUMBER, |
| 90 |
Properties::FORMAT_CODE_DATE, |
| 91 |
Properties::FORMAT_CODE_DATE_ISO8601, |
| 92 |
]; |
| 93 |
|
| 94 |
/** @var bool */ |
| 95 |
private $noFill = false; |
| 96 |
|
| 97 |
/** |
| 98 |
* Get Series Data Type. |
| 99 |
* |
| 100 |
* @param mixed $format_code |
| 101 |
*/ |
| 102 |
public function setAxisNumberProperties($format_code, ?bool $numeric = null, int $sourceLinked = 0): void |
| 103 |
{ |
| 104 |
$format = (string) $format_code; |
| 105 |
$this->axisNumber['format'] = $format; |
| 106 |
$this->axisNumber['source_linked'] = $sourceLinked; |
| 107 |
if (is_bool($numeric)) { |
| 108 |
$this->axisNumber['numeric'] = $numeric; |
| 109 |
} elseif (in_array($format, self::NUMERIC_FORMAT, true)) { |
| 110 |
$this->axisNumber['numeric'] = true; |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
/** |
| 115 |
* Get Axis Number Format Data Type. |
| 116 |
* |
| 117 |
* @return string |
| 118 |
*/ |
| 119 |
public function getAxisNumberFormat() |
| 120 |
{ |
| 121 |
return $this->axisNumber['format']; |
| 122 |
} |
| 123 |
|
| 124 |
/** |
| 125 |
* Get Axis Number Source Linked. |
| 126 |
* |
| 127 |
* @return string |
| 128 |
*/ |
| 129 |
public function getAxisNumberSourceLinked() |
| 130 |
{ |
| 131 |
return (string) $this->axisNumber['source_linked']; |
| 132 |
} |
| 133 |
|
| 134 |
public function getAxisIsNumericFormat(): bool |
| 135 |
{ |
| 136 |
return $this->axisType === self::AXIS_TYPE_DATE || (bool) $this->axisNumber['numeric']; |
| 137 |
} |
| 138 |
|
| 139 |
public function setAxisOption(string $key, ?string $value): void |
| 140 |
{ |
| 141 |
if ($value !== null && $value !== '') { |
| 142 |
$this->axisOptions[$key] = $value; |
| 143 |
} |
| 144 |
} |
| 145 |
|
| 146 |
/** |
| 147 |
* Set Axis Options Properties. |
| 148 |
*/ |
| 149 |
public function setAxisOptionsProperties( |
| 150 |
string $axisLabels, |
| 151 |
?string $horizontalCrossesValue = null, |
| 152 |
?string $horizontalCrosses = null, |
| 153 |
?string $axisOrientation = null, |
| 154 |
?string $majorTmt = null, |
| 155 |
?string $minorTmt = null, |
| 156 |
?string $minimum = null, |
| 157 |
?string $maximum = null, |
| 158 |
?string $majorUnit = null, |
| 159 |
?string $minorUnit = null, |
| 160 |
?string $textRotation = null, |
| 161 |
?string $hidden = null, |
| 162 |
?string $baseTimeUnit = null, |
| 163 |
?string $majorTimeUnit = null, |
| 164 |
?string $minorTimeUnit = null |
| 165 |
): void { |
| 166 |
$this->axisOptions['axis_labels'] = $axisLabels; |
| 167 |
$this->setAxisOption('horizontal_crosses_value', $horizontalCrossesValue); |
| 168 |
$this->setAxisOption('horizontal_crosses', $horizontalCrosses); |
| 169 |
$this->setAxisOption('orientation', $axisOrientation); |
| 170 |
$this->setAxisOption('major_tick_mark', $majorTmt); |
| 171 |
$this->setAxisOption('minor_tick_mark', $minorTmt); |
| 172 |
$this->setAxisOption('minimum', $minimum); |
| 173 |
$this->setAxisOption('maximum', $maximum); |
| 174 |
$this->setAxisOption('major_unit', $majorUnit); |
| 175 |
$this->setAxisOption('minor_unit', $minorUnit); |
| 176 |
$this->setAxisOption('textRotation', $textRotation); |
| 177 |
$this->setAxisOption('hidden', $hidden); |
| 178 |
$this->setAxisOption('baseTimeUnit', $baseTimeUnit); |
| 179 |
$this->setAxisOption('majorTimeUnit', $majorTimeUnit); |
| 180 |
$this->setAxisOption('minorTimeUnit', $minorTimeUnit); |
| 181 |
} |
| 182 |
|
| 183 |
/** |
| 184 |
* Get Axis Options Property. |
| 185 |
* |
| 186 |
* @param string $property |
| 187 |
* |
| 188 |
* @return ?string |
| 189 |
*/ |
| 190 |
public function getAxisOptionsProperty($property) |
| 191 |
{ |
| 192 |
if ($property === 'textRotation') { |
| 193 |
if ($this->axisText !== null) { |
| 194 |
if ($this->axisText->getRotation() !== null) { |
| 195 |
return (string) $this->axisText->getRotation(); |
| 196 |
} |
| 197 |
} |
| 198 |
} |
| 199 |
|
| 200 |
return $this->axisOptions[$property]; |
| 201 |
} |
| 202 |
|
| 203 |
/** |
| 204 |
* Set Axis Orientation Property. |
| 205 |
* |
| 206 |
* @param string $orientation |
| 207 |
*/ |
| 208 |
public function setAxisOrientation($orientation): void |
| 209 |
{ |
| 210 |
$this->axisOptions['orientation'] = (string) $orientation; |
| 211 |
} |
| 212 |
|
| 213 |
public function getAxisType(): string |
| 214 |
{ |
| 215 |
return $this->axisType; |
| 216 |
} |
| 217 |
|
| 218 |
public function setAxisType(string $type): self |
| 219 |
{ |
| 220 |
if ($type === self::AXIS_TYPE_CATEGORY || $type === self::AXIS_TYPE_VALUE || $type === self::AXIS_TYPE_DATE) { |
| 221 |
$this->axisType = $type; |
| 222 |
} else { |
| 223 |
$this->axisType = ''; |
| 224 |
} |
| 225 |
|
| 226 |
return $this; |
| 227 |
} |
| 228 |
|
| 229 |
/** |
| 230 |
* Set Fill Property. |
| 231 |
* |
| 232 |
* @param ?string $color |
| 233 |
* @param ?int $alpha |
| 234 |
* @param ?string $AlphaType |
| 235 |
*/ |
| 236 |
public function setFillParameters($color, $alpha = null, $AlphaType = ChartColor::EXCEL_COLOR_TYPE_RGB): void |
| 237 |
{ |
| 238 |
$this->fillColor->setColorProperties($color, $alpha, $AlphaType); |
| 239 |
} |
| 240 |
|
| 241 |
/** |
| 242 |
* Get Fill Property. |
| 243 |
* |
| 244 |
* @param string $property |
| 245 |
* |
| 246 |
* @return string |
| 247 |
*/ |
| 248 |
public function getFillProperty($property) |
| 249 |
{ |
| 250 |
return (string) $this->fillColor->getColorProperty($property); |
| 251 |
} |
| 252 |
|
| 253 |
public function getFillColorObject(): ChartColor |
| 254 |
{ |
| 255 |
return $this->fillColor; |
| 256 |
} |
| 257 |
|
| 258 |
/** |
| 259 |
* Get Line Color Property. |
| 260 |
* |
| 261 |
* @deprecated 1.24.0 |
| 262 |
* Use the getLineColor property in the Properties class instead |
| 263 |
* @see Properties::getLineColorProperty() |
| 264 |
* |
| 265 |
* @param string $propertyName |
| 266 |
* |
| 267 |
* @return null|int|string |
| 268 |
*/ |
| 269 |
public function getLineProperty($propertyName) |
| 270 |
{ |
| 271 |
return $this->getLineColorProperty($propertyName); |
| 272 |
} |
| 273 |
|
| 274 |
/** @var string */ |
| 275 |
private $crossBetween = ''; // 'between' or 'midCat' might be better |
| 276 |
|
| 277 |
public function setCrossBetween(string $crossBetween): self |
| 278 |
{ |
| 279 |
$this->crossBetween = $crossBetween; |
| 280 |
|
| 281 |
return $this; |
| 282 |
} |
| 283 |
|
| 284 |
public function getCrossBetween(): string |
| 285 |
{ |
| 286 |
return $this->crossBetween; |
| 287 |
} |
| 288 |
|
| 289 |
public function getMajorGridlines(): ?GridLines |
| 290 |
{ |
| 291 |
return $this->majorGridlines; |
| 292 |
} |
| 293 |
|
| 294 |
public function getMinorGridlines(): ?GridLines |
| 295 |
{ |
| 296 |
return $this->minorGridlines; |
| 297 |
} |
| 298 |
|
| 299 |
public function setMajorGridlines(?GridLines $gridlines): self |
| 300 |
{ |
| 301 |
$this->majorGridlines = $gridlines; |
| 302 |
|
| 303 |
return $this; |
| 304 |
} |
| 305 |
|
| 306 |
public function setMinorGridlines(?GridLines $gridlines): self |
| 307 |
{ |
| 308 |
$this->minorGridlines = $gridlines; |
| 309 |
|
| 310 |
return $this; |
| 311 |
} |
| 312 |
|
| 313 |
public function getAxisText(): ?AxisText |
| 314 |
{ |
| 315 |
return $this->axisText; |
| 316 |
} |
| 317 |
|
| 318 |
public function setAxisText(?AxisText $axisText): self |
| 319 |
{ |
| 320 |
$this->axisText = $axisText; |
| 321 |
|
| 322 |
return $this; |
| 323 |
} |
| 324 |
|
| 325 |
public function setNoFill(bool $noFill): self |
| 326 |
{ |
| 327 |
$this->noFill = $noFill; |
| 328 |
|
| 329 |
return $this; |
| 330 |
} |
| 331 |
|
| 332 |
public function getNoFill(): bool |
| 333 |
{ |
| 334 |
return $this->noFill; |
| 335 |
} |
| 336 |
} |
| 337 |
|