1<?php 2 3namespace PhpOffice\PhpSpreadsheet\Chart; 4 5/** 6 * Created by PhpStorm. 7 * User: Wiktor Trzonkowski 8 * Date: 6/17/14 9 * Time: 12:11 PM. 10 */ 11class Axis extends Properties 12{ 13 /** 14 * Axis Number. 15 * 16 * @var array of mixed 17 */ 18 private $axisNumber = [ 19 'format' => self::FORMAT_CODE_GENERAL, 20 'source_linked' => 1, 21 ]; 22 23 /** 24 * Axis Options. 25 * 26 * @var array of mixed 27 */ 28 private $axisOptions = [ 29 'minimum' => null, 30 'maximum' => null, 31 'major_unit' => null, 32 'minor_unit' => null, 33 'orientation' => self::ORIENTATION_NORMAL, 34 'minor_tick_mark' => self::TICK_MARK_NONE, 35 'major_tick_mark' => self::TICK_MARK_NONE, 36 'axis_labels' => self::AXIS_LABELS_NEXT_TO, 37 'horizontal_crosses' => self::HORIZONTAL_CROSSES_AUTOZERO, 38 'horizontal_crosses_value' => null, 39 ]; 40 41 /** 42 * Fill Properties. 43 * 44 * @var array of mixed 45 */ 46 private $fillProperties = [ 47 'type' => self::EXCEL_COLOR_TYPE_ARGB, 48 'value' => null, 49 'alpha' => 0, 50 ]; 51 52 /** 53 * Line Properties. 54 * 55 * @var array of mixed 56 */ 57 private $lineProperties = [ 58 'type' => self::EXCEL_COLOR_TYPE_ARGB, 59 'value' => null, 60 'alpha' => 0, 61 ]; 62 63 /** 64 * Line Style Properties. 65 * 66 * @var array of mixed 67 */ 68 private $lineStyleProperties = [ 69 'width' => '9525', 70 'compound' => self::LINE_STYLE_COMPOUND_SIMPLE, 71 'dash' => self::LINE_STYLE_DASH_SOLID, 72 'cap' => self::LINE_STYLE_CAP_FLAT, 73 'join' => self::LINE_STYLE_JOIN_BEVEL, 74 'arrow' => [ 75 'head' => [ 76 'type' => self::LINE_STYLE_ARROW_TYPE_NOARROW, 77 'size' => self::LINE_STYLE_ARROW_SIZE_5, 78 ], 79 'end' => [ 80 'type' => self::LINE_STYLE_ARROW_TYPE_NOARROW, 81 'size' => self::LINE_STYLE_ARROW_SIZE_8, 82 ], 83 ], 84 ]; 85 86 /** 87 * Shadow Properties. 88 * 89 * @var array of mixed 90 */ 91 private $shadowProperties = [ 92 'presets' => self::SHADOW_PRESETS_NOSHADOW, 93 'effect' => null, 94 'color' => [ 95 'type' => self::EXCEL_COLOR_TYPE_STANDARD, 96 'value' => 'black', 97 'alpha' => 40, 98 ], 99 'size' => [ 100 'sx' => null, 101 'sy' => null, 102 'kx' => null, 103 ], 104 'blur' => null, 105 'direction' => null, 106 'distance' => null, 107 'algn' => null, 108 'rotWithShape' => null, 109 ]; 110 111 /** 112 * Glow Properties. 113 * 114 * @var array of mixed 115 */ 116 private $glowProperties = [ 117 'size' => null, 118 'color' => [ 119 'type' => self::EXCEL_COLOR_TYPE_STANDARD, 120 'value' => 'black', 121 'alpha' => 40, 122 ], 123 ]; 124 125 /** 126 * Soft Edge Properties. 127 * 128 * @var array of mixed 129 */ 130 private $softEdges = [ 131 'size' => null, 132 ]; 133 134 /** 135 * Get Series Data Type. 136 * 137 * @param mixed $format_code 138 * 139 * @return string 140 */ 141 public function setAxisNumberProperties($format_code) 142 { 143 $this->axisNumber['format'] = (string) $format_code; 144 $this->axisNumber['source_linked'] = 0; 145 } 146 147 /** 148 * Get Axis Number Format Data Type. 149 * 150 * @return string 151 */ 152 public function getAxisNumberFormat() 153 { 154 return $this->axisNumber['format']; 155 } 156 157 /** 158 * Get Axis Number Source Linked. 159 * 160 * @return string 161 */ 162 public function getAxisNumberSourceLinked() 163 { 164 return (string) $this->axisNumber['source_linked']; 165 } 166 167 /** 168 * Set Axis Options Properties. 169 * 170 * @param string $axis_labels 171 * @param string $horizontal_crosses_value 172 * @param string $horizontal_crosses 173 * @param string $axis_orientation 174 * @param string $major_tmt 175 * @param string $minor_tmt 176 * @param string $minimum 177 * @param string $maximum 178 * @param string $major_unit 179 * @param string $minor_unit 180 */ 181 public function setAxisOptionsProperties($axis_labels, $horizontal_crosses_value = null, $horizontal_crosses = null, $axis_orientation = null, $major_tmt = null, $minor_tmt = null, $minimum = null, $maximum = null, $major_unit = null, $minor_unit = null): void 182 { 183 $this->axisOptions['axis_labels'] = (string) $axis_labels; 184 ($horizontal_crosses_value !== null) ? $this->axisOptions['horizontal_crosses_value'] = (string) $horizontal_crosses_value : null; 185 ($horizontal_crosses !== null) ? $this->axisOptions['horizontal_crosses'] = (string) $horizontal_crosses : null; 186 ($axis_orientation !== null) ? $this->axisOptions['orientation'] = (string) $axis_orientation : null; 187 ($major_tmt !== null) ? $this->axisOptions['major_tick_mark'] = (string) $major_tmt : null; 188 ($minor_tmt !== null) ? $this->axisOptions['minor_tick_mark'] = (string) $minor_tmt : null; 189 ($minor_tmt !== null) ? $this->axisOptions['minor_tick_mark'] = (string) $minor_tmt : null; 190 ($minimum !== null) ? $this->axisOptions['minimum'] = (string) $minimum : null; 191 ($maximum !== null) ? $this->axisOptions['maximum'] = (string) $maximum : null; 192 ($major_unit !== null) ? $this->axisOptions['major_unit'] = (string) $major_unit : null; 193 ($minor_unit !== null) ? $this->axisOptions['minor_unit'] = (string) $minor_unit : null; 194 } 195 196 /** 197 * Get Axis Options Property. 198 * 199 * @param string $property 200 * 201 * @return string 202 */ 203 public function getAxisOptionsProperty($property) 204 { 205 return $this->axisOptions[$property]; 206 } 207 208 /** 209 * Set Axis Orientation Property. 210 * 211 * @param string $orientation 212 */ 213 public function setAxisOrientation($orientation): void 214 { 215 $this->axisOptions['orientation'] = (string) $orientation; 216 } 217 218 /** 219 * Set Fill Property. 220 * 221 * @param string $color 222 * @param int $alpha 223 * @param string $type 224 */ 225 public function setFillParameters($color, $alpha = 0, $type = self::EXCEL_COLOR_TYPE_ARGB): void 226 { 227 $this->fillProperties = $this->setColorProperties($color, $alpha, $type); 228 } 229 230 /** 231 * Set Line Property. 232 * 233 * @param string $color 234 * @param int $alpha 235 * @param string $type 236 */ 237 public function setLineParameters($color, $alpha = 0, $type = self::EXCEL_COLOR_TYPE_ARGB): void 238 { 239 $this->lineProperties = $this->setColorProperties($color, $alpha, $type); 240 } 241 242 /** 243 * Get Fill Property. 244 * 245 * @param string $property 246 * 247 * @return string 248 */ 249 public function getFillProperty($property) 250 { 251 return $this->fillProperties[$property]; 252 } 253 254 /** 255 * Get Line Property. 256 * 257 * @param string $property 258 * 259 * @return string 260 */ 261 public function getLineProperty($property) 262 { 263 return $this->lineProperties[$property]; 264 } 265 266 /** 267 * Set Line Style Properties. 268 * 269 * @param float $line_width 270 * @param string $compound_type 271 * @param string $dash_type 272 * @param string $cap_type 273 * @param string $join_type 274 * @param string $head_arrow_type 275 * @param string $head_arrow_size 276 * @param string $end_arrow_type 277 * @param string $end_arrow_size 278 */ 279 public function setLineStyleProperties($line_width = null, $compound_type = null, $dash_type = null, $cap_type = null, $join_type = null, $head_arrow_type = null, $head_arrow_size = null, $end_arrow_type = null, $end_arrow_size = null): void 280 { 281 ($line_width !== null) ? $this->lineStyleProperties['width'] = $this->getExcelPointsWidth((float) $line_width) : null; 282 ($compound_type !== null) ? $this->lineStyleProperties['compound'] = (string) $compound_type : null; 283 ($dash_type !== null) ? $this->lineStyleProperties['dash'] = (string) $dash_type : null; 284 ($cap_type !== null) ? $this->lineStyleProperties['cap'] = (string) $cap_type : null; 285 ($join_type !== null) ? $this->lineStyleProperties['join'] = (string) $join_type : null; 286 ($head_arrow_type !== null) ? $this->lineStyleProperties['arrow']['head']['type'] = (string) $head_arrow_type : null; 287 ($head_arrow_size !== null) ? $this->lineStyleProperties['arrow']['head']['size'] = (string) $head_arrow_size : null; 288 ($end_arrow_type !== null) ? $this->lineStyleProperties['arrow']['end']['type'] = (string) $end_arrow_type : null; 289 ($end_arrow_size !== null) ? $this->lineStyleProperties['arrow']['end']['size'] = (string) $end_arrow_size : null; 290 } 291 292 /** 293 * Get Line Style Property. 294 * 295 * @param array|string $elements 296 * 297 * @return string 298 */ 299 public function getLineStyleProperty($elements) 300 { 301 return $this->getArrayElementsValue($this->lineStyleProperties, $elements); 302 } 303 304 /** 305 * Get Line Style Arrow Excel Width. 306 * 307 * @param string $arrow 308 * 309 * @return string 310 */ 311 public function getLineStyleArrowWidth($arrow) 312 { 313 return $this->getLineStyleArrowSize($this->lineStyleProperties['arrow'][$arrow]['size'], 'w'); 314 } 315 316 /** 317 * Get Line Style Arrow Excel Length. 318 * 319 * @param string $arrow 320 * 321 * @return string 322 */ 323 public function getLineStyleArrowLength($arrow) 324 { 325 return $this->getLineStyleArrowSize($this->lineStyleProperties['arrow'][$arrow]['size'], 'len'); 326 } 327 328 /** 329 * Set Shadow Properties. 330 * 331 * @param int $sh_presets 332 * @param string $sh_color_value 333 * @param string $sh_color_type 334 * @param string $sh_color_alpha 335 * @param float $sh_blur 336 * @param int $sh_angle 337 * @param float $sh_distance 338 */ 339 public function setShadowProperties($sh_presets, $sh_color_value = null, $sh_color_type = null, $sh_color_alpha = null, $sh_blur = null, $sh_angle = null, $sh_distance = null): void 340 { 341 $this->setShadowPresetsProperties((int) $sh_presets) 342 ->setShadowColor( 343 $sh_color_value === null ? $this->shadowProperties['color']['value'] : $sh_color_value, 344 $sh_color_alpha === null ? (int) $this->shadowProperties['color']['alpha'] : $sh_color_alpha, 345 $sh_color_type === null ? $this->shadowProperties['color']['type'] : $sh_color_type 346 ) 347 ->setShadowBlur($sh_blur) 348 ->setShadowAngle($sh_angle) 349 ->setShadowDistance($sh_distance); 350 } 351 352 /** 353 * Set Shadow Color. 354 * 355 * @param int $shadow_presets 356 * 357 * @return $this 358 */ 359 private function setShadowPresetsProperties($shadow_presets) 360 { 361 $this->shadowProperties['presets'] = $shadow_presets; 362 $this->setShadowProperiesMapValues($this->getShadowPresetsMap($shadow_presets)); 363 364 return $this; 365 } 366 367 /** 368 * Set Shadow Properties from Mapped Values. 369 * 370 * @param mixed &$reference 371 * 372 * @return $this 373 */ 374 private function setShadowProperiesMapValues(array $properties_map, &$reference = null) 375 { 376 $base_reference = $reference; 377 foreach ($properties_map as $property_key => $property_val) { 378 if (is_array($property_val)) { 379 if ($reference === null) { 380 $reference = &$this->shadowProperties[$property_key]; 381 } else { 382 $reference = &$reference[$property_key]; 383 } 384 $this->setShadowProperiesMapValues($property_val, $reference); 385 } else { 386 if ($base_reference === null) { 387 $this->shadowProperties[$property_key] = $property_val; 388 } else { 389 $reference[$property_key] = $property_val; 390 } 391 } 392 } 393 394 return $this; 395 } 396 397 /** 398 * Set Shadow Color. 399 * 400 * @param string $color 401 * @param int $alpha 402 * @param string $type 403 * 404 * @return $this 405 */ 406 private function setShadowColor($color, $alpha, $type) 407 { 408 $this->shadowProperties['color'] = $this->setColorProperties($color, $alpha, $type); 409 410 return $this; 411 } 412 413 /** 414 * Set Shadow Blur. 415 * 416 * @param float $blur 417 * 418 * @return $this 419 */ 420 private function setShadowBlur($blur) 421 { 422 if ($blur !== null) { 423 $this->shadowProperties['blur'] = (string) $this->getExcelPointsWidth($blur); 424 } 425 426 return $this; 427 } 428 429 /** 430 * Set Shadow Angle. 431 * 432 * @param int $angle 433 * 434 * @return $this 435 */ 436 private function setShadowAngle($angle) 437 { 438 if ($angle !== null) { 439 $this->shadowProperties['direction'] = (string) $this->getExcelPointsAngle($angle); 440 } 441 442 return $this; 443 } 444 445 /** 446 * Set Shadow Distance. 447 * 448 * @param float $distance 449 * 450 * @return $this 451 */ 452 private function setShadowDistance($distance) 453 { 454 if ($distance !== null) { 455 $this->shadowProperties['distance'] = (string) $this->getExcelPointsWidth($distance); 456 } 457 458 return $this; 459 } 460 461 /** 462 * Get Shadow Property. 463 * 464 * @param string|string[] $elements 465 * 466 * @return null|array|int|string 467 */ 468 public function getShadowProperty($elements) 469 { 470 return $this->getArrayElementsValue($this->shadowProperties, $elements); 471 } 472 473 /** 474 * Set Glow Properties. 475 * 476 * @param float $size 477 * @param string $color_value 478 * @param int $color_alpha 479 * @param string $color_type 480 */ 481 public function setGlowProperties($size, $color_value = null, $color_alpha = null, $color_type = null): void 482 { 483 $this->setGlowSize($size) 484 ->setGlowColor( 485 $color_value === null ? $this->glowProperties['color']['value'] : $color_value, 486 $color_alpha === null ? (int) $this->glowProperties['color']['alpha'] : $color_alpha, 487 $color_type === null ? $this->glowProperties['color']['type'] : $color_type 488 ); 489 } 490 491 /** 492 * Get Glow Property. 493 * 494 * @param array|string $property 495 * 496 * @return string 497 */ 498 public function getGlowProperty($property) 499 { 500 return $this->getArrayElementsValue($this->glowProperties, $property); 501 } 502 503 /** 504 * Set Glow Color. 505 * 506 * @param float $size 507 * 508 * @return $this 509 */ 510 private function setGlowSize($size) 511 { 512 if ($size !== null) { 513 $this->glowProperties['size'] = $this->getExcelPointsWidth($size); 514 } 515 516 return $this; 517 } 518 519 /** 520 * Set Glow Color. 521 * 522 * @param string $color 523 * @param int $alpha 524 * @param string $type 525 * 526 * @return $this 527 */ 528 private function setGlowColor($color, $alpha, $type) 529 { 530 $this->glowProperties['color'] = $this->setColorProperties($color, $alpha, $type); 531 532 return $this; 533 } 534 535 /** 536 * Set Soft Edges Size. 537 * 538 * @param float $size 539 */ 540 public function setSoftEdges($size): void 541 { 542 if ($size !== null) { 543 $softEdges['size'] = (string) $this->getExcelPointsWidth($size); 544 } 545 } 546 547 /** 548 * Get Soft Edges Size. 549 * 550 * @return string 551 */ 552 public function getSoftEdgesSize() 553 { 554 return $this->softEdges['size']; 555 } 556} 557