| 1 |
<?php |
| 2 |
|
| 3 |
namespace TablePress\PhpOffice\PhpSpreadsheet\Chart; |
| 4 |
|
| 5 |
use TablePress\PhpOffice\PhpSpreadsheet\Style\Font; |
| 6 |
|
| 7 |
class Layout |
| 8 |
{ |
| 9 |
/** |
| 10 |
* layoutTarget. |
| 11 |
*/ |
| 12 |
private ?string $layoutTarget = null; |
| 13 |
|
| 14 |
/** |
| 15 |
* X Mode. |
| 16 |
*/ |
| 17 |
private ?string $xMode = null; |
| 18 |
|
| 19 |
/** |
| 20 |
* Y Mode. |
| 21 |
*/ |
| 22 |
private ?string $yMode = null; |
| 23 |
|
| 24 |
/** |
| 25 |
* X-Position. |
| 26 |
*/ |
| 27 |
private ?float $xPos = null; |
| 28 |
|
| 29 |
/** |
| 30 |
* Y-Position. |
| 31 |
*/ |
| 32 |
private ?float $yPos = null; |
| 33 |
|
| 34 |
/** |
| 35 |
* width. |
| 36 |
*/ |
| 37 |
private ?float $width = null; |
| 38 |
|
| 39 |
/** |
| 40 |
* height. |
| 41 |
*/ |
| 42 |
private ?float $height = null; |
| 43 |
|
| 44 |
/** |
| 45 |
* Position - t=top. |
| 46 |
*/ |
| 47 |
private string $dLblPos = ''; |
| 48 |
|
| 49 |
private string $numFmtCode = ''; |
| 50 |
|
| 51 |
private bool $numFmtLinked = false; |
| 52 |
|
| 53 |
/** |
| 54 |
* show legend key |
| 55 |
* Specifies that legend keys should be shown in data labels. |
| 56 |
*/ |
| 57 |
private ?bool $showLegendKey = null; |
| 58 |
|
| 59 |
/** |
| 60 |
* show value |
| 61 |
* Specifies that the value should be shown in a data label. |
| 62 |
*/ |
| 63 |
private ?bool $showVal = null; |
| 64 |
|
| 65 |
/** |
| 66 |
* show category name |
| 67 |
* Specifies that the category name should be shown in the data label. |
| 68 |
*/ |
| 69 |
private ?bool $showCatName = null; |
| 70 |
|
| 71 |
/** |
| 72 |
* show data series name |
| 73 |
* Specifies that the series name should be shown in the data label. |
| 74 |
*/ |
| 75 |
private ?bool $showSerName = null; |
| 76 |
|
| 77 |
/** |
| 78 |
* show percentage |
| 79 |
* Specifies that the percentage should be shown in the data label. |
| 80 |
*/ |
| 81 |
private ?bool $showPercent = null; |
| 82 |
|
| 83 |
/** |
| 84 |
* show bubble size. |
| 85 |
*/ |
| 86 |
private ?bool $showBubbleSize = null; |
| 87 |
|
| 88 |
/** |
| 89 |
* show leader lines |
| 90 |
* Specifies that leader lines should be shown for the data label. |
| 91 |
*/ |
| 92 |
private ?bool $showLeaderLines = null; |
| 93 |
|
| 94 |
private ?ChartColor $labelFillColor = null; |
| 95 |
|
| 96 |
private ?ChartColor $labelBorderColor = null; |
| 97 |
|
| 98 |
private ?Font $labelFont = null; |
| 99 |
|
| 100 |
private ?Properties $labelEffects = null; |
| 101 |
|
| 102 |
/** @var array{ |
| 103 |
* vertOverflow?: string, |
| 104 |
* horzOverflow?: string, |
| 105 |
* wrap?: string, |
| 106 |
* lIns?: numeric-string, |
| 107 |
* tIns?: numeric-string, |
| 108 |
* rIns?: numeric-string, |
| 109 |
* bIns?: numeric-string, |
| 110 |
* anchor?: string, |
| 111 |
* } |
| 112 |
*/ |
| 113 |
private array $bodyPr = [ |
| 114 |
'wrap' => 'square', |
| 115 |
'lIns' => '38100', |
| 116 |
'tIns' => '19050', |
| 117 |
'rIns' => '38100', |
| 118 |
'bIns' => '19050', |
| 119 |
'anchor' => 'ctr', |
| 120 |
]; |
| 121 |
|
| 122 |
/** |
| 123 |
* Create a new Layout. |
| 124 |
* |
| 125 |
* @param array<mixed> $layout |
| 126 |
*/ |
| 127 |
public function __construct(array $layout = []) |
| 128 |
{ |
| 129 |
/** @var array{ |
| 130 |
* layoutTarget?: string, |
| 131 |
* xMode?: string, |
| 132 |
* yMode?: string, |
| 133 |
* x?: float, |
| 134 |
* y?: float, |
| 135 |
* w?:float, |
| 136 |
* h?:float, |
| 137 |
* dLblPos?: string, |
| 138 |
* labelFont?: ?mixed, |
| 139 |
* labelFontColor?: ?mixed, |
| 140 |
* labelEffects?: ?mixed, |
| 141 |
* numFmtCode?: string, |
| 142 |
* bodyPr?: mixed, |
| 143 |
* } $layout |
| 144 |
*/ |
| 145 |
if (isset($layout['layoutTarget'])) { |
| 146 |
$this->layoutTarget = $layout['layoutTarget']; |
| 147 |
} |
| 148 |
if (isset($layout['xMode'])) { |
| 149 |
$this->xMode = $layout['xMode']; |
| 150 |
} |
| 151 |
if (isset($layout['yMode'])) { |
| 152 |
$this->yMode = $layout['yMode']; |
| 153 |
} |
| 154 |
if (isset($layout['x'])) { |
| 155 |
$this->xPos = (float) $layout['x']; |
| 156 |
} |
| 157 |
if (isset($layout['y'])) { |
| 158 |
$this->yPos = (float) $layout['y']; |
| 159 |
} |
| 160 |
if (isset($layout['w'])) { |
| 161 |
$this->width = (float) $layout['w']; |
| 162 |
} |
| 163 |
if (isset($layout['h'])) { |
| 164 |
$this->height = (float) $layout['h']; |
| 165 |
} |
| 166 |
if (isset($layout['dLblPos'])) { |
| 167 |
$this->dLblPos = (string) $layout['dLblPos']; |
| 168 |
} |
| 169 |
if (isset($layout['numFmtCode'])) { |
| 170 |
$this->numFmtCode = (string) $layout['numFmtCode']; |
| 171 |
} |
| 172 |
$this->initBoolean($layout, 'showLegendKey'); |
| 173 |
$this->initBoolean($layout, 'showVal'); |
| 174 |
$this->initBoolean($layout, 'showCatName'); |
| 175 |
$this->initBoolean($layout, 'showSerName'); |
| 176 |
$this->initBoolean($layout, 'showPercent'); |
| 177 |
$this->initBoolean($layout, 'showBubbleSize'); |
| 178 |
$this->initBoolean($layout, 'showLeaderLines'); |
| 179 |
$this->initBoolean($layout, 'numFmtLinked'); |
| 180 |
$this->initColor($layout, 'labelFillColor'); |
| 181 |
$this->initColor($layout, 'labelBorderColor'); |
| 182 |
$labelFont = $layout['labelFont'] ?? null; |
| 183 |
if ($labelFont instanceof Font) { |
| 184 |
$this->labelFont = $labelFont; |
| 185 |
} |
| 186 |
$labelFontColor = $layout['labelFontColor'] ?? null; |
| 187 |
if ($labelFontColor instanceof ChartColor) { |
| 188 |
$this->setLabelFontColor($labelFontColor); |
| 189 |
} |
| 190 |
$labelEffects = $layout['labelEffects'] ?? null; |
| 191 |
if ($labelEffects instanceof Properties) { |
| 192 |
$this->labelEffects = $labelEffects; |
| 193 |
} |
| 194 |
$bodyPr = $layout['bodyPr'] ?? null; |
| 195 |
if (is_array($bodyPr)) { |
| 196 |
$this->setBodyPr($bodyPr); |
| 197 |
} |
| 198 |
} |
| 199 |
|
| 200 |
/** @param mixed[] $layout */ |
| 201 |
private function initBoolean(array $layout, string $name): void |
| 202 |
{ |
| 203 |
if (isset($layout[$name])) { |
| 204 |
$this->$name = (bool) $layout[$name]; |
| 205 |
} |
| 206 |
} |
| 207 |
|
| 208 |
/** @param mixed[] $layout */ |
| 209 |
private function initColor(array $layout, string $name): void |
| 210 |
{ |
| 211 |
if (isset($layout[$name]) && $layout[$name] instanceof ChartColor) { |
| 212 |
$this->$name = $layout[$name]; |
| 213 |
} |
| 214 |
} |
| 215 |
|
| 216 |
/** |
| 217 |
* Get Layout Target. |
| 218 |
*/ |
| 219 |
public function getLayoutTarget(): ?string |
| 220 |
{ |
| 221 |
return $this->layoutTarget; |
| 222 |
} |
| 223 |
|
| 224 |
/** |
| 225 |
* Set Layout Target. |
| 226 |
* |
| 227 |
* @return $this |
| 228 |
*/ |
| 229 |
public function setLayoutTarget(?string $target) |
| 230 |
{ |
| 231 |
$this->layoutTarget = $target; |
| 232 |
|
| 233 |
return $this; |
| 234 |
} |
| 235 |
|
| 236 |
/** |
| 237 |
* Get X-Mode. |
| 238 |
*/ |
| 239 |
public function getXMode(): ?string |
| 240 |
{ |
| 241 |
return $this->xMode; |
| 242 |
} |
| 243 |
|
| 244 |
/** |
| 245 |
* Set X-Mode. |
| 246 |
* |
| 247 |
* @return $this |
| 248 |
*/ |
| 249 |
public function setXMode(?string $mode) |
| 250 |
{ |
| 251 |
$this->xMode = (string) $mode; |
| 252 |
|
| 253 |
return $this; |
| 254 |
} |
| 255 |
|
| 256 |
/** |
| 257 |
* Get Y-Mode. |
| 258 |
*/ |
| 259 |
public function getYMode(): ?string |
| 260 |
{ |
| 261 |
return $this->yMode; |
| 262 |
} |
| 263 |
|
| 264 |
/** |
| 265 |
* Set Y-Mode. |
| 266 |
* |
| 267 |
* @return $this |
| 268 |
*/ |
| 269 |
public function setYMode(?string $mode) |
| 270 |
{ |
| 271 |
$this->yMode = (string) $mode; |
| 272 |
|
| 273 |
return $this; |
| 274 |
} |
| 275 |
|
| 276 |
/** |
| 277 |
* Get X-Position. |
| 278 |
* @return null|float|int |
| 279 |
*/ |
| 280 |
public function getXPosition() |
| 281 |
{ |
| 282 |
return $this->xPos; |
| 283 |
} |
| 284 |
|
| 285 |
/** |
| 286 |
* Set X-Position. |
| 287 |
* |
| 288 |
* @return $this |
| 289 |
*/ |
| 290 |
public function setXPosition(float $position) |
| 291 |
{ |
| 292 |
$this->xPos = $position; |
| 293 |
|
| 294 |
return $this; |
| 295 |
} |
| 296 |
|
| 297 |
/** |
| 298 |
* Get Y-Position. |
| 299 |
*/ |
| 300 |
public function getYPosition(): ?float |
| 301 |
{ |
| 302 |
return $this->yPos; |
| 303 |
} |
| 304 |
|
| 305 |
/** |
| 306 |
* Set Y-Position. |
| 307 |
* |
| 308 |
* @return $this |
| 309 |
*/ |
| 310 |
public function setYPosition(float $position) |
| 311 |
{ |
| 312 |
$this->yPos = $position; |
| 313 |
|
| 314 |
return $this; |
| 315 |
} |
| 316 |
|
| 317 |
/** |
| 318 |
* Get Width. |
| 319 |
*/ |
| 320 |
public function getWidth(): ?float |
| 321 |
{ |
| 322 |
return $this->width; |
| 323 |
} |
| 324 |
|
| 325 |
/** |
| 326 |
* Set Width. |
| 327 |
* |
| 328 |
* @return $this |
| 329 |
*/ |
| 330 |
public function setWidth(?float $width) |
| 331 |
{ |
| 332 |
$this->width = $width; |
| 333 |
|
| 334 |
return $this; |
| 335 |
} |
| 336 |
|
| 337 |
/** |
| 338 |
* Get Height. |
| 339 |
*/ |
| 340 |
public function getHeight(): ?float |
| 341 |
{ |
| 342 |
return $this->height; |
| 343 |
} |
| 344 |
|
| 345 |
/** |
| 346 |
* Set Height. |
| 347 |
* |
| 348 |
* @return $this |
| 349 |
*/ |
| 350 |
public function setHeight(?float $height) |
| 351 |
{ |
| 352 |
$this->height = $height; |
| 353 |
|
| 354 |
return $this; |
| 355 |
} |
| 356 |
|
| 357 |
public function getShowLegendKey(): ?bool |
| 358 |
{ |
| 359 |
return $this->showLegendKey; |
| 360 |
} |
| 361 |
|
| 362 |
/** |
| 363 |
* Set show legend key |
| 364 |
* Specifies that legend keys should be shown in data labels. |
| 365 |
*/ |
| 366 |
public function setShowLegendKey(?bool $showLegendKey): self |
| 367 |
{ |
| 368 |
$this->showLegendKey = $showLegendKey; |
| 369 |
|
| 370 |
return $this; |
| 371 |
} |
| 372 |
|
| 373 |
public function getShowVal(): ?bool |
| 374 |
{ |
| 375 |
return $this->showVal; |
| 376 |
} |
| 377 |
|
| 378 |
/** |
| 379 |
* Set show val |
| 380 |
* Specifies that the value should be shown in data labels. |
| 381 |
*/ |
| 382 |
public function setShowVal(?bool $showDataLabelValues): self |
| 383 |
{ |
| 384 |
$this->showVal = $showDataLabelValues; |
| 385 |
|
| 386 |
return $this; |
| 387 |
} |
| 388 |
|
| 389 |
public function getShowCatName(): ?bool |
| 390 |
{ |
| 391 |
return $this->showCatName; |
| 392 |
} |
| 393 |
|
| 394 |
/** |
| 395 |
* Set show cat name |
| 396 |
* Specifies that the category name should be shown in data labels. |
| 397 |
*/ |
| 398 |
public function setShowCatName(?bool $showCategoryName): self |
| 399 |
{ |
| 400 |
$this->showCatName = $showCategoryName; |
| 401 |
|
| 402 |
return $this; |
| 403 |
} |
| 404 |
|
| 405 |
public function getShowSerName(): ?bool |
| 406 |
{ |
| 407 |
return $this->showSerName; |
| 408 |
} |
| 409 |
|
| 410 |
/** |
| 411 |
* Set show data series name. |
| 412 |
* Specifies that the series name should be shown in data labels. |
| 413 |
*/ |
| 414 |
public function setShowSerName(?bool $showSeriesName): self |
| 415 |
{ |
| 416 |
$this->showSerName = $showSeriesName; |
| 417 |
|
| 418 |
return $this; |
| 419 |
} |
| 420 |
|
| 421 |
public function getShowPercent(): ?bool |
| 422 |
{ |
| 423 |
return $this->showPercent; |
| 424 |
} |
| 425 |
|
| 426 |
/** |
| 427 |
* Set show percentage. |
| 428 |
* Specifies that the percentage should be shown in data labels. |
| 429 |
*/ |
| 430 |
public function setShowPercent(?bool $showPercentage): self |
| 431 |
{ |
| 432 |
$this->showPercent = $showPercentage; |
| 433 |
|
| 434 |
return $this; |
| 435 |
} |
| 436 |
|
| 437 |
public function getShowBubbleSize(): ?bool |
| 438 |
{ |
| 439 |
return $this->showBubbleSize; |
| 440 |
} |
| 441 |
|
| 442 |
/** |
| 443 |
* Set show bubble size. |
| 444 |
* Specifies that the bubble size should be shown in data labels. |
| 445 |
*/ |
| 446 |
public function setShowBubbleSize(?bool $showBubbleSize): self |
| 447 |
{ |
| 448 |
$this->showBubbleSize = $showBubbleSize; |
| 449 |
|
| 450 |
return $this; |
| 451 |
} |
| 452 |
|
| 453 |
public function getShowLeaderLines(): ?bool |
| 454 |
{ |
| 455 |
return $this->showLeaderLines; |
| 456 |
} |
| 457 |
|
| 458 |
/** |
| 459 |
* Set show leader lines. |
| 460 |
* Specifies that leader lines should be shown in data labels. |
| 461 |
*/ |
| 462 |
public function setShowLeaderLines(?bool $showLeaderLines): self |
| 463 |
{ |
| 464 |
$this->showLeaderLines = $showLeaderLines; |
| 465 |
|
| 466 |
return $this; |
| 467 |
} |
| 468 |
|
| 469 |
public function getLabelFillColor(): ?ChartColor |
| 470 |
{ |
| 471 |
return $this->labelFillColor; |
| 472 |
} |
| 473 |
|
| 474 |
public function setLabelFillColor(?ChartColor $chartColor): self |
| 475 |
{ |
| 476 |
$this->labelFillColor = $chartColor; |
| 477 |
|
| 478 |
return $this; |
| 479 |
} |
| 480 |
|
| 481 |
public function getLabelBorderColor(): ?ChartColor |
| 482 |
{ |
| 483 |
return $this->labelBorderColor; |
| 484 |
} |
| 485 |
|
| 486 |
public function setLabelBorderColor(?ChartColor $chartColor): self |
| 487 |
{ |
| 488 |
$this->labelBorderColor = $chartColor; |
| 489 |
|
| 490 |
return $this; |
| 491 |
} |
| 492 |
|
| 493 |
public function getLabelFont(): ?Font |
| 494 |
{ |
| 495 |
return $this->labelFont; |
| 496 |
} |
| 497 |
|
| 498 |
public function setLabelFont(?Font $labelFont): self |
| 499 |
{ |
| 500 |
$this->labelFont = $labelFont; |
| 501 |
|
| 502 |
return $this; |
| 503 |
} |
| 504 |
|
| 505 |
public function getLabelEffects(): ?Properties |
| 506 |
{ |
| 507 |
return $this->labelEffects; |
| 508 |
} |
| 509 |
|
| 510 |
public function getLabelFontColor(): ?ChartColor |
| 511 |
{ |
| 512 |
return ($nullsafeVariable1 = $this->labelFont) ? $nullsafeVariable1->getChartColor() : null; |
| 513 |
} |
| 514 |
|
| 515 |
public function setLabelFontColor(?ChartColor $chartColor): self |
| 516 |
{ |
| 517 |
if ($this->labelFont === null) { |
| 518 |
$this->labelFont = new Font(); |
| 519 |
$this->labelFont->setSize(null, true); |
| 520 |
} |
| 521 |
$this->labelFont->setChartColorFromObject($chartColor); |
| 522 |
|
| 523 |
return $this; |
| 524 |
} |
| 525 |
|
| 526 |
public function getDLblPos(): string |
| 527 |
{ |
| 528 |
return $this->dLblPos; |
| 529 |
} |
| 530 |
|
| 531 |
public function setDLblPos(string $dLblPos): self |
| 532 |
{ |
| 533 |
$this->dLblPos = $dLblPos; |
| 534 |
|
| 535 |
return $this; |
| 536 |
} |
| 537 |
|
| 538 |
public function getNumFmtCode(): string |
| 539 |
{ |
| 540 |
return $this->numFmtCode; |
| 541 |
} |
| 542 |
|
| 543 |
public function setNumFmtCode(string $numFmtCode): self |
| 544 |
{ |
| 545 |
$this->numFmtCode = $numFmtCode; |
| 546 |
|
| 547 |
return $this; |
| 548 |
} |
| 549 |
|
| 550 |
public function getNumFmtLinked(): bool |
| 551 |
{ |
| 552 |
return $this->numFmtLinked; |
| 553 |
} |
| 554 |
|
| 555 |
public function setNumFmtLinked(bool $numFmtLinked): self |
| 556 |
{ |
| 557 |
$this->numFmtLinked = $numFmtLinked; |
| 558 |
|
| 559 |
return $this; |
| 560 |
} |
| 561 |
|
| 562 |
/** @return array{ |
| 563 |
* vertOverflow?: string, |
| 564 |
* horzOverflow?: string, |
| 565 |
* wrap?: string, |
| 566 |
* lIns?: numeric-string, |
| 567 |
* tIns?: numeric-string, |
| 568 |
* rIns?: numeric-string, |
| 569 |
* bIns?: numeric-string, |
| 570 |
* anchor?: string, |
| 571 |
* } |
| 572 |
*/ |
| 573 |
public function getBodyPr(): array |
| 574 |
{ |
| 575 |
return $this->bodyPr; |
| 576 |
} |
| 577 |
|
| 578 |
/** |
| 579 |
* @param mixed $bodyPr expect array matching $this->bodyPr |
| 580 |
*/ |
| 581 |
public function setBodyPr($bodyPr): self |
| 582 |
{ |
| 583 |
if (is_array($bodyPr)) { |
| 584 |
foreach (['vertOverflow', 'horzOverflow', 'wrap', 'anchor'] as $key) { |
| 585 |
$value = $bodyPr[$key] ?? null; |
| 586 |
if (is_string($value)) { |
| 587 |
$this->bodyPr[$key] = "$value"; |
| 588 |
} |
| 589 |
} |
| 590 |
foreach (['lIns', 'tIns', 'rIns', 'bIns'] as $key) { |
| 591 |
$value = $bodyPr[$key] ?? null; |
| 592 |
if (is_string($value) && is_numeric($value)) { |
| 593 |
$this->bodyPr[$key] = "$value"; |
| 594 |
} |
| 595 |
} |
| 596 |
} |
| 597 |
|
| 598 |
return $this; |
| 599 |
} |
| 600 |
|
| 601 |
/** |
| 602 |
* Implement PHP __clone to create a deep clone, not just a shallow copy. |
| 603 |
*/ |
| 604 |
public function __clone() |
| 605 |
{ |
| 606 |
$this->labelFillColor = ($this->labelFillColor === null) ? null : clone $this->labelFillColor; |
| 607 |
$this->labelBorderColor = ($this->labelBorderColor === null) ? null : clone $this->labelBorderColor; |
| 608 |
$this->labelFont = ($this->labelFont === null) ? null : clone $this->labelFont; |
| 609 |
$this->labelEffects = ($this->labelEffects === null) ? null : clone $this->labelEffects; |
| 610 |
} |
| 611 |
} |
| 612 |
|