PluginProbe
TablePress – Tables in WordPress made easy / 3.4
TablePress – Tables in WordPress made easy v3.4
3.4 3.3.4 3.3.3 3.3.2 3.3.1 trunk 1.12 1.14 1.9.2 2.0.4 2.1.7 2.1.8 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3 2.3.1 2.3.2 2.4 2.4.1 2.4.2 2.4.3 All 45 releases
tablepress / libraries / vendor / PhpSpreadsheet / Chart / Properties.php

Properties.php in TablePress – Tables in WordPress made easy 3.4, at libraries/vendor/PhpSpreadsheet/Chart/Properties.php

946 lines 26.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace TablePress\PhpOffice\PhpSpreadsheet\Chart;
4
5 /**
6 * Created by PhpStorm.
7 * User: nhw2h8s
8 * Date: 7/2/14
9 * Time: 5:45 PM.
10 */
11 abstract class Properties
12 {
13 const AXIS_LABELS_LOW = 'low';
14 const AXIS_LABELS_HIGH = 'high';
15 const AXIS_LABELS_NEXT_TO = 'nextTo';
16 const AXIS_LABELS_NONE = 'none';
17
18 const TICK_MARK_NONE = 'none';
19 const TICK_MARK_INSIDE = 'in';
20 const TICK_MARK_OUTSIDE = 'out';
21 const TICK_MARK_CROSS = 'cross';
22
23 const HORIZONTAL_CROSSES_AUTOZERO = 'autoZero';
24 const HORIZONTAL_CROSSES_MAXIMUM = 'max';
25
26 const FORMAT_CODE_GENERAL = 'General';
27 const FORMAT_CODE_NUMBER = '#,##0.00';
28 const FORMAT_CODE_CURRENCY = '$#,##0.00';
29 const FORMAT_CODE_ACCOUNTING = '_($* #,##0.00_);_($* (#,##0.00);_($* "-"??_);_(@_)';
30 const FORMAT_CODE_DATE = 'm/d/yyyy';
31 const FORMAT_CODE_DATE_ISO8601 = 'yyyy-mm-dd';
32 const FORMAT_CODE_TIME = '[$-F400]h:mm:ss AM/PM';
33 const FORMAT_CODE_PERCENTAGE = '0.00%';
34 const FORMAT_CODE_FRACTION = '# ?/?';
35 const FORMAT_CODE_SCIENTIFIC = '0.00E+00';
36 const FORMAT_CODE_TEXT = '@';
37 const FORMAT_CODE_SPECIAL = '00000';
38
39 const ORIENTATION_NORMAL = 'minMax';
40 const ORIENTATION_REVERSED = 'maxMin';
41
42 const LINE_STYLE_COMPOUND_SIMPLE = 'sng';
43 const LINE_STYLE_COMPOUND_DOUBLE = 'dbl';
44 const LINE_STYLE_COMPOUND_THICKTHIN = 'thickThin';
45 const LINE_STYLE_COMPOUND_THINTHICK = 'thinThick';
46 const LINE_STYLE_COMPOUND_TRIPLE = 'tri';
47 const LINE_STYLE_DASH_SOLID = 'solid';
48 const LINE_STYLE_DASH_ROUND_DOT = 'sysDot';
49 const LINE_STYLE_DASH_SQUARE_DOT = 'sysDash';
50 const LINE_STYPE_DASH_DASH = 'dash';
51 const LINE_STYLE_DASH_DASH_DOT = 'dashDot';
52 const LINE_STYLE_DASH_LONG_DASH = 'lgDash';
53 const LINE_STYLE_DASH_LONG_DASH_DOT = 'lgDashDot';
54 const LINE_STYLE_DASH_LONG_DASH_DOT_DOT = 'lgDashDotDot';
55 const LINE_STYLE_CAP_SQUARE = 'sq';
56 const LINE_STYLE_CAP_ROUND = 'rnd';
57 const LINE_STYLE_CAP_FLAT = 'flat';
58 const LINE_STYLE_JOIN_ROUND = 'round';
59 const LINE_STYLE_JOIN_MITER = 'miter';
60 const LINE_STYLE_JOIN_BEVEL = 'bevel';
61 const LINE_STYLE_ARROW_TYPE_NOARROW = null;
62 const LINE_STYLE_ARROW_TYPE_ARROW = 'triangle';
63 const LINE_STYLE_ARROW_TYPE_OPEN = 'arrow';
64 const LINE_STYLE_ARROW_TYPE_STEALTH = 'stealth';
65 const LINE_STYLE_ARROW_TYPE_DIAMOND = 'diamond';
66 const LINE_STYLE_ARROW_TYPE_OVAL = 'oval';
67 const LINE_STYLE_ARROW_SIZE_1 = 1;
68 const LINE_STYLE_ARROW_SIZE_2 = 2;
69 const LINE_STYLE_ARROW_SIZE_3 = 3;
70 const LINE_STYLE_ARROW_SIZE_4 = 4;
71 const LINE_STYLE_ARROW_SIZE_5 = 5;
72 const LINE_STYLE_ARROW_SIZE_6 = 6;
73 const LINE_STYLE_ARROW_SIZE_7 = 7;
74 const LINE_STYLE_ARROW_SIZE_8 = 8;
75 const LINE_STYLE_ARROW_SIZE_9 = 9;
76
77 const SHADOW_PRESETS_NOSHADOW = null;
78 const SHADOW_PRESETS_OUTER_BOTTTOM_RIGHT = 1;
79 const SHADOW_PRESETS_OUTER_BOTTOM = 2;
80 const SHADOW_PRESETS_OUTER_BOTTOM_LEFT = 3;
81 const SHADOW_PRESETS_OUTER_RIGHT = 4;
82 const SHADOW_PRESETS_OUTER_CENTER = 5;
83 const SHADOW_PRESETS_OUTER_LEFT = 6;
84 const SHADOW_PRESETS_OUTER_TOP_RIGHT = 7;
85 const SHADOW_PRESETS_OUTER_TOP = 8;
86 const SHADOW_PRESETS_OUTER_TOP_LEFT = 9;
87 const SHADOW_PRESETS_INNER_BOTTTOM_RIGHT = 10;
88 const SHADOW_PRESETS_INNER_BOTTOM = 11;
89 const SHADOW_PRESETS_INNER_BOTTOM_LEFT = 12;
90 const SHADOW_PRESETS_INNER_RIGHT = 13;
91 const SHADOW_PRESETS_INNER_CENTER = 14;
92 const SHADOW_PRESETS_INNER_LEFT = 15;
93 const SHADOW_PRESETS_INNER_TOP_RIGHT = 16;
94 const SHADOW_PRESETS_INNER_TOP = 17;
95 const SHADOW_PRESETS_INNER_TOP_LEFT = 18;
96 const SHADOW_PRESETS_PERSPECTIVE_BELOW = 19;
97 const SHADOW_PRESETS_PERSPECTIVE_UPPER_RIGHT = 20;
98 const SHADOW_PRESETS_PERSPECTIVE_UPPER_LEFT = 21;
99 const SHADOW_PRESETS_PERSPECTIVE_LOWER_RIGHT = 22;
100 const SHADOW_PRESETS_PERSPECTIVE_LOWER_LEFT = 23;
101
102 const POINTS_WIDTH_MULTIPLIER = 12_700;
103 const ANGLE_MULTIPLIER = 60_000; // direction and size-kx size-ky
104 const PERCENTAGE_MULTIPLIER = 100_000; // size sx and sy, and gradient pos
105 const MAX_SKEW_ANGLE_XML = 90 * self::ANGLE_MULTIPLIER - 1;
106 const MAX_SKEW_ANGLE_DEGREES = self::MAX_SKEW_ANGLE_XML / self::ANGLE_MULTIPLIER; // max for size-kx size-ky
107
108 protected bool $objectState = false; // used only for minor gridlines
109
110 protected ?float $glowSize = null;
111
112 protected ChartColor $glowColor;
113
114 /** @var array{size: ?float} */
115 protected array $softEdges = [
116 'size' => null,
117 ];
118
119 /** @var mixed[] */
120 protected array $shadowProperties = self::PRESETS_OPTIONS[0];
121
122 protected ChartColor $shadowColor;
123
124 public function __construct()
125 {
126 $this->lineColor = new ChartColor();
127 $this->glowColor = new ChartColor();
128 $this->shadowColor = new ChartColor();
129 $this->shadowColor->setType(ChartColor::EXCEL_COLOR_TYPE_STANDARD);
130 $this->shadowColor->setValue('black');
131 $this->shadowColor->setAlpha(40);
132 }
133
134 /**
135 * Get Object State.
136 */
137 public function getObjectState(): bool
138 {
139 return $this->objectState;
140 }
141
142 /**
143 * Change Object State to True.
144 *
145 * @return $this
146 */
147 public function activateObject()
148 {
149 $this->objectState = true;
150
151 return $this;
152 }
153
154 public static function pointsToXml(float $width): string
155 {
156 return (string) (int) ($width * self::POINTS_WIDTH_MULTIPLIER);
157 }
158
159 public static function xmlToPoints(string $width): float
160 {
161 return ((float) $width) / self::POINTS_WIDTH_MULTIPLIER;
162 }
163
164 public static function angleToXml(float $angle): string
165 {
166 return (string) (int) ($angle * self::ANGLE_MULTIPLIER);
167 }
168
169 public static function xmlToAngle(string $angle): float
170 {
171 return ((float) $angle) / self::ANGLE_MULTIPLIER;
172 }
173
174 public static function tenthOfPercentToXml(float $value): string
175 {
176 return (string) (int) ($value * self::PERCENTAGE_MULTIPLIER);
177 }
178
179 public static function xmlToTenthOfPercent(string $value): float
180 {
181 return ((float) $value) / self::PERCENTAGE_MULTIPLIER;
182 }
183
184 /** @return array{type: ?string, value: ?string, alpha: ?int}
185 * @param null|float|int|string $alpha */
186 protected function setColorProperties(?string $color, $alpha, ?string $colorType): array
187 {
188 return [
189 'type' => $colorType,
190 'value' => $color,
191 'alpha' => ($alpha === null) ? null : (int) $alpha,
192 ];
193 }
194
195 protected const PRESETS_OPTIONS = [
196 //NONE
197 0 => [
198 'presets' => self::SHADOW_PRESETS_NOSHADOW,
199 'effect' => null,
200 //'color' => [
201 // 'type' => ChartColor::EXCEL_COLOR_TYPE_STANDARD,
202 // 'value' => 'black',
203 // 'alpha' => 40,
204 //],
205 'size' => [
206 'sx' => null,
207 'sy' => null,
208 'kx' => null,
209 'ky' => null,
210 ],
211 'blur' => null,
212 'direction' => null,
213 'distance' => null,
214 'algn' => null,
215 'rotWithShape' => null,
216 ],
217 //OUTER
218 1 => [
219 'effect' => 'outerShdw',
220 'blur' => 50800 / self::POINTS_WIDTH_MULTIPLIER,
221 'distance' => 38100 / self::POINTS_WIDTH_MULTIPLIER,
222 'direction' => 2700000 / self::ANGLE_MULTIPLIER,
223 'algn' => 'tl',
224 'rotWithShape' => '0',
225 ],
226 2 => [
227 'effect' => 'outerShdw',
228 'blur' => 50800 / self::POINTS_WIDTH_MULTIPLIER,
229 'distance' => 38100 / self::POINTS_WIDTH_MULTIPLIER,
230 'direction' => 5400000 / self::ANGLE_MULTIPLIER,
231 'algn' => 't',
232 'rotWithShape' => '0',
233 ],
234 3 => [
235 'effect' => 'outerShdw',
236 'blur' => 50800 / self::POINTS_WIDTH_MULTIPLIER,
237 'distance' => 38100 / self::POINTS_WIDTH_MULTIPLIER,
238 'direction' => 8100000 / self::ANGLE_MULTIPLIER,
239 'algn' => 'tr',
240 'rotWithShape' => '0',
241 ],
242 4 => [
243 'effect' => 'outerShdw',
244 'blur' => 50800 / self::POINTS_WIDTH_MULTIPLIER,
245 'distance' => 38100 / self::POINTS_WIDTH_MULTIPLIER,
246 'algn' => 'l',
247 'rotWithShape' => '0',
248 ],
249 5 => [
250 'effect' => 'outerShdw',
251 'size' => [
252 'sx' => 102000 / self::PERCENTAGE_MULTIPLIER,
253 'sy' => 102000 / self::PERCENTAGE_MULTIPLIER,
254 ],
255 'blur' => 63500 / self::POINTS_WIDTH_MULTIPLIER,
256 'distance' => 38100 / self::POINTS_WIDTH_MULTIPLIER,
257 'algn' => 'ctr',
258 'rotWithShape' => '0',
259 ],
260 6 => [
261 'effect' => 'outerShdw',
262 'blur' => 50800 / self::POINTS_WIDTH_MULTIPLIER,
263 'distance' => 38100 / self::POINTS_WIDTH_MULTIPLIER,
264 'direction' => 10800000 / self::ANGLE_MULTIPLIER,
265 'algn' => 'r',
266 'rotWithShape' => '0',
267 ],
268 7 => [
269 'effect' => 'outerShdw',
270 'blur' => 50800 / self::POINTS_WIDTH_MULTIPLIER,
271 'distance' => 38100 / self::POINTS_WIDTH_MULTIPLIER,
272 'direction' => 18900000 / self::ANGLE_MULTIPLIER,
273 'algn' => 'bl',
274 'rotWithShape' => '0',
275 ],
276 8 => [
277 'effect' => 'outerShdw',
278 'blur' => 50800 / self::POINTS_WIDTH_MULTIPLIER,
279 'distance' => 38100 / self::POINTS_WIDTH_MULTIPLIER,
280 'direction' => 16200000 / self::ANGLE_MULTIPLIER,
281 'rotWithShape' => '0',
282 ],
283 9 => [
284 'effect' => 'outerShdw',
285 'blur' => 50800 / self::POINTS_WIDTH_MULTIPLIER,
286 'distance' => 38100 / self::POINTS_WIDTH_MULTIPLIER,
287 'direction' => 13500000 / self::ANGLE_MULTIPLIER,
288 'algn' => 'br',
289 'rotWithShape' => '0',
290 ],
291 //INNER
292 10 => [
293 'effect' => 'innerShdw',
294 'blur' => 63500 / self::POINTS_WIDTH_MULTIPLIER,
295 'distance' => 50800 / self::POINTS_WIDTH_MULTIPLIER,
296 'direction' => 2700000 / self::ANGLE_MULTIPLIER,
297 ],
298 11 => [
299 'effect' => 'innerShdw',
300 'blur' => 63500 / self::POINTS_WIDTH_MULTIPLIER,
301 'distance' => 50800 / self::POINTS_WIDTH_MULTIPLIER,
302 'direction' => 5400000 / self::ANGLE_MULTIPLIER,
303 ],
304 12 => [
305 'effect' => 'innerShdw',
306 'blur' => 63500 / self::POINTS_WIDTH_MULTIPLIER,
307 'distance' => 50800 / self::POINTS_WIDTH_MULTIPLIER,
308 'direction' => 8100000 / self::ANGLE_MULTIPLIER,
309 ],
310 13 => [
311 'effect' => 'innerShdw',
312 'blur' => 63500 / self::POINTS_WIDTH_MULTIPLIER,
313 'distance' => 50800 / self::POINTS_WIDTH_MULTIPLIER,
314 ],
315 14 => [
316 'effect' => 'innerShdw',
317 'blur' => 114300 / self::POINTS_WIDTH_MULTIPLIER,
318 ],
319 15 => [
320 'effect' => 'innerShdw',
321 'blur' => 63500 / self::POINTS_WIDTH_MULTIPLIER,
322 'distance' => 50800 / self::POINTS_WIDTH_MULTIPLIER,
323 'direction' => 10800000 / self::ANGLE_MULTIPLIER,
324 ],
325 16 => [
326 'effect' => 'innerShdw',
327 'blur' => 63500 / self::POINTS_WIDTH_MULTIPLIER,
328 'distance' => 50800 / self::POINTS_WIDTH_MULTIPLIER,
329 'direction' => 18900000 / self::ANGLE_MULTIPLIER,
330 ],
331 17 => [
332 'effect' => 'innerShdw',
333 'blur' => 63500 / self::POINTS_WIDTH_MULTIPLIER,
334 'distance' => 50800 / self::POINTS_WIDTH_MULTIPLIER,
335 'direction' => 16200000 / self::ANGLE_MULTIPLIER,
336 ],
337 18 => [
338 'effect' => 'innerShdw',
339 'blur' => 63500 / self::POINTS_WIDTH_MULTIPLIER,
340 'distance' => 50800 / self::POINTS_WIDTH_MULTIPLIER,
341 'direction' => 13500000 / self::ANGLE_MULTIPLIER,
342 ],
343 //perspective
344 19 => [
345 'effect' => 'outerShdw',
346 'blur' => 152400 / self::POINTS_WIDTH_MULTIPLIER,
347 'distance' => 317500 / self::POINTS_WIDTH_MULTIPLIER,
348 'size' => [
349 'sx' => 90000 / self::PERCENTAGE_MULTIPLIER,
350 'sy' => -19000 / self::PERCENTAGE_MULTIPLIER,
351 ],
352 'direction' => 5400000 / self::ANGLE_MULTIPLIER,
353 'rotWithShape' => '0',
354 ],
355 20 => [
356 'effect' => 'outerShdw',
357 'blur' => 76200 / self::POINTS_WIDTH_MULTIPLIER,
358 'direction' => 18900000 / self::ANGLE_MULTIPLIER,
359 'size' => [
360 'sy' => 23000 / self::PERCENTAGE_MULTIPLIER,
361 'kx' => -1200000 / self::ANGLE_MULTIPLIER,
362 ],
363 'algn' => 'bl',
364 'rotWithShape' => '0',
365 ],
366 21 => [
367 'effect' => 'outerShdw',
368 'blur' => 76200 / self::POINTS_WIDTH_MULTIPLIER,
369 'direction' => 13500000 / self::ANGLE_MULTIPLIER,
370 'size' => [
371 'sy' => 23000 / self::PERCENTAGE_MULTIPLIER,
372 'kx' => 1200000 / self::ANGLE_MULTIPLIER,
373 ],
374 'algn' => 'br',
375 'rotWithShape' => '0',
376 ],
377 22 => [
378 'effect' => 'outerShdw',
379 'blur' => 76200 / self::POINTS_WIDTH_MULTIPLIER,
380 'distance' => 12700 / self::POINTS_WIDTH_MULTIPLIER,
381 'direction' => 2700000 / self::ANGLE_MULTIPLIER,
382 'size' => [
383 'sy' => -23000 / self::PERCENTAGE_MULTIPLIER,
384 'kx' => -800400 / self::ANGLE_MULTIPLIER,
385 ],
386 'algn' => 'bl',
387 'rotWithShape' => '0',
388 ],
389 23 => [
390 'effect' => 'outerShdw',
391 'blur' => 76200 / self::POINTS_WIDTH_MULTIPLIER,
392 'distance' => 12700 / self::POINTS_WIDTH_MULTIPLIER,
393 'direction' => 8100000 / self::ANGLE_MULTIPLIER,
394 'size' => [
395 'sy' => -23000 / self::PERCENTAGE_MULTIPLIER,
396 'kx' => 800400 / self::ANGLE_MULTIPLIER,
397 ],
398 'algn' => 'br',
399 'rotWithShape' => '0',
400 ],
401 ];
402
403 /** @return mixed[] */
404 protected function getShadowPresetsMap(int $presetsOption): array
405 {
406 return self::PRESETS_OPTIONS[$presetsOption] ?? self::PRESETS_OPTIONS[0];
407 }
408
409 /**
410 * Get value of array element.
411 *
412 * @param mixed[] $properties
413 * @param array<mixed>|int|string $elements
414 * @return mixed
415 */
416 protected function getArrayElementsValue(array $properties, $elements)
417 {
418 $reference = &$properties;
419 if (!is_array($elements)) {
420 return $reference[$elements];
421 }
422
423 foreach ($elements as $keys) {
424 $reference = &$reference[$keys]; //* @phpstan-ignore offsetAccess.nonOffsetAccessible (I'm not sure what this is doing)
425 }
426
427 return $reference;
428 }
429
430 /**
431 * Set Glow Properties.
432 */
433 public function setGlowProperties(float $size, ?string $colorValue = null, ?int $colorAlpha = null, ?string $colorType = null): void
434 {
435 $this
436 ->activateObject()
437 ->setGlowSize($size);
438 $this->glowColor->setColorPropertiesArray(
439 [
440 'value' => $colorValue,
441 'type' => $colorType,
442 'alpha' => $colorAlpha,
443 ]
444 );
445 }
446
447 /**
448 * Get Glow Property.
449 *
450 * @param mixed[]|string $property
451 *
452 * @return null|array<mixed>|float|int|string
453 */
454 public function getGlowProperty($property)
455 {
456 $retVal = null;
457 if ($property === 'size') {
458 $retVal = $this->glowSize;
459 } elseif ($property === 'color') {
460 $retVal = [
461 'value' => $this->glowColor->getColorProperty('value'),
462 'type' => $this->glowColor->getColorProperty('type'),
463 'alpha' => $this->glowColor->getColorProperty('alpha'),
464 ];
465 } elseif (is_array($property) && count($property) >= 2 && $property[0] === 'color') {
466 /** @var string */
467 $temp = $property[1];
468 $retVal = $this->glowColor->getColorProperty($temp);
469 }
470
471 return $retVal;
472 }
473
474 /**
475 * Get Glow Color Property.
476 * @return null|int|string
477 */
478 public function getGlowColor(string $propertyName)
479 {
480 return $this->glowColor->getColorProperty($propertyName);
481 }
482
483 public function getGlowColorObject(): ChartColor
484 {
485 return $this->glowColor;
486 }
487
488 /**
489 * Get Glow Size.
490 */
491 public function getGlowSize(): ?float
492 {
493 return $this->glowSize;
494 }
495
496 /**
497 * Set Glow Size.
498 *
499 * @return $this
500 */
501 protected function setGlowSize(?float $size)
502 {
503 $this->glowSize = $size;
504
505 return $this;
506 }
507
508 /**
509 * Set Soft Edges Size.
510 */
511 public function setSoftEdges(?float $size): void
512 {
513 if ($size !== null) {
514 $this->activateObject();
515 $this->softEdges['size'] = $size;
516 }
517 }
518
519 /**
520 * Get Soft Edges Size.
521 */
522 public function getSoftEdgesSize(): ?float
523 {
524 return $this->softEdges['size'];
525 }
526
527 /** @param mixed $value */
528 public function setShadowProperty(string $propertyName, $value): self
529 {
530 $this->activateObject();
531 if ($propertyName === 'color' && is_array($value)) {
532 /** @var array{value: ?string, alpha: null|int|string, brightness?: null|int|string, type: ?string} */
533 $valuex = $value;
534 $this->shadowColor->setColorPropertiesArray($valuex);
535 } else {
536 $this->shadowProperties[$propertyName] = $value;
537 }
538
539 return $this;
540 }
541
542 /**
543 * Set Shadow Properties.
544 * @param null|float|int|string $colorAlpha
545 */
546 public function setShadowProperties(int $presets, ?string $colorValue = null, ?string $colorType = null, $colorAlpha = null, ?float $blur = null, ?int $angle = null, ?float $distance = null): void
547 {
548 $this->activateObject()->setShadowPresetsProperties((int) $presets);
549 if ($presets === 0) {
550 $this->shadowColor->setType(ChartColor::EXCEL_COLOR_TYPE_STANDARD);
551 $this->shadowColor->setValue('black');
552 $this->shadowColor->setAlpha(40);
553 }
554 if ($colorValue !== null) {
555 $this->shadowColor->setValue($colorValue);
556 }
557 if ($colorType !== null) {
558 $this->shadowColor->setType($colorType);
559 }
560 if (is_numeric($colorAlpha)) {
561 $this->shadowColor->setAlpha((int) $colorAlpha);
562 }
563 $this
564 ->setShadowBlur($blur)
565 ->setShadowAngle($angle)
566 ->setShadowDistance($distance);
567 }
568
569 /**
570 * Set Shadow Presets Properties.
571 *
572 * @return $this
573 */
574 protected function setShadowPresetsProperties(int $presets)
575 {
576 $this->shadowProperties['presets'] = $presets;
577 $this->setShadowPropertiesMapValues($this->getShadowPresetsMap($presets));
578
579 return $this;
580 }
581
582 protected const SHADOW_ARRAY_KEYS = ['size', 'color'];
583
584 /**
585 * Set Shadow Properties Values.
586 *
587 * @param mixed[] $propertiesMap
588 * @param null|mixed[] $reference
589 *
590 * @return $this
591 */
592 protected function setShadowPropertiesMapValues(array $propertiesMap, ?array &$reference = null)
593 {
594 $base_reference = $reference;
595 foreach ($propertiesMap as $property_key => $property_val) {
596 if (is_array($property_val)) {
597 if (in_array($property_key, self::SHADOW_ARRAY_KEYS, true)) {
598 /** @var null|array<mixed> */
599 $temp = &$this->shadowProperties[$property_key];
600 $reference = &$temp;
601 $this->setShadowPropertiesMapValues(
602 $property_val,
603 $reference
604 );
605 }
606 } else {
607 if ($base_reference === null) {
608 $this->shadowProperties[$property_key] = $property_val;
609 } else {
610 $reference[$property_key] = $property_val;
611 }
612 }
613 }
614
615 return $this;
616 }
617
618 /**
619 * Set Shadow Blur.
620 *
621 * @return $this
622 */
623 protected function setShadowBlur(?float $blur)
624 {
625 if ($blur !== null) {
626 $this->shadowProperties['blur'] = $blur;
627 }
628
629 return $this;
630 }
631
632 /**
633 * Set Shadow Angle.
634 *
635 * @return $this
636 * @param null|float|int|string $angle
637 */
638 protected function setShadowAngle($angle)
639 {
640 if (is_numeric($angle)) {
641 $this->shadowProperties['direction'] = $angle;
642 }
643
644 return $this;
645 }
646
647 /**
648 * Set Shadow Distance.
649 *
650 * @return $this
651 */
652 protected function setShadowDistance(?float $distance)
653 {
654 if ($distance !== null) {
655 $this->shadowProperties['distance'] = $distance;
656 }
657
658 return $this;
659 }
660
661 public function getShadowColorObject(): ChartColor
662 {
663 return $this->shadowColor;
664 }
665
666 /**
667 * Get Shadow Property.
668 *
669 * @param string|string[] $elements
670 *
671 * @return null|mixed[]|string
672 */
673 public function getShadowProperty($elements)
674 {
675 if ($elements === 'color') {
676 return [
677 'value' => $this->shadowColor->getValue(),
678 'type' => $this->shadowColor->getType(),
679 'alpha' => $this->shadowColor->getAlpha(),
680 ];
681 }
682 $retVal = $this->getArrayElementsValue($this->shadowProperties, $elements);
683 if (is_scalar($retVal)) {
684 $retVal = (string) $retVal;
685 } elseif ($retVal !== null && !is_array($retVal)) {
686 // @codeCoverageIgnoreStart
687 throw new Exception('Unexpected value for shadowProperty');
688 // @codeCoverageIgnoreEnd
689 }
690
691 return $retVal;
692 }
693
694 /** @return mixed[] */
695 public function getShadowArray(): array
696 {
697 $array = $this->shadowProperties;
698 if ($this->getShadowColorObject()->isUsable()) {
699 $array['color'] = $this->getShadowProperty('color');
700 }
701
702 return $array;
703 }
704
705 protected ChartColor $lineColor;
706
707 /** @var array{width: null|float|int|string, compound: ?string, dash: ?string, cap: ?string, join: ?string, arrow: array{head: array{type: ?string, size: null|int|string, w: ?string, len: ?string}, end: array{type: ?string, size: null|int|string, w: ?string, len: ?string}}} */
708 protected array $lineStyleProperties = [
709 'width' => null, //'9525',
710 'compound' => '', //self::LINE_STYLE_COMPOUND_SIMPLE,
711 'dash' => '', //self::LINE_STYLE_DASH_SOLID,
712 'cap' => '', //self::LINE_STYLE_CAP_FLAT,
713 'join' => '', //self::LINE_STYLE_JOIN_BEVEL,
714 'arrow' => [
715 'head' => [
716 'type' => '', //self::LINE_STYLE_ARROW_TYPE_NOARROW,
717 'size' => '', //self::LINE_STYLE_ARROW_SIZE_5,
718 'w' => '',
719 'len' => '',
720 ],
721 'end' => [
722 'type' => '', //self::LINE_STYLE_ARROW_TYPE_NOARROW,
723 'size' => '', //self::LINE_STYLE_ARROW_SIZE_8,
724 'w' => '',
725 'len' => '',
726 ],
727 ],
728 ];
729
730 public function copyLineStyles(self $otherProperties): void
731 {
732 $this->lineStyleProperties = $otherProperties->lineStyleProperties;
733 $this->lineColor = $otherProperties->lineColor;
734 $this->glowSize = $otherProperties->glowSize;
735 $this->glowColor = $otherProperties->glowColor;
736 $this->softEdges = $otherProperties->softEdges;
737 $this->shadowProperties = $otherProperties->shadowProperties;
738 }
739
740 public function getLineColor(): ChartColor
741 {
742 return $this->lineColor;
743 }
744
745 /**
746 * Set Line Color Properties.
747 */
748 public function setLineColorProperties(?string $value, ?int $alpha = null, ?string $colorType = null): void
749 {
750 $this->activateObject();
751 $this->lineColor->setColorPropertiesArray(
752 $this->setColorProperties(
753 $value,
754 $alpha,
755 $colorType
756 )
757 );
758 }
759
760 /**
761 * Get Line Color Property.
762 * @return null|int|string
763 */
764 public function getLineColorProperty(string $propertyName)
765 {
766 return $this->lineColor->getColorProperty($propertyName);
767 }
768
769 /**
770 * Set Line Style Properties.
771 * @param null|float|int|string $lineWidth
772 */
773 public function setLineStyleProperties(
774 $lineWidth = null,
775 ?string $compoundType = '',
776 ?string $dashType = '',
777 ?string $capType = '',
778 ?string $joinType = '',
779 ?string $headArrowType = '',
780 int $headArrowSize = 0,
781 ?string $endArrowType = '',
782 int $endArrowSize = 0,
783 ?string $headArrowWidth = '',
784 ?string $headArrowLength = '',
785 ?string $endArrowWidth = '',
786 ?string $endArrowLength = ''
787 ): void {
788 $this->activateObject();
789 if (is_numeric($lineWidth)) {
790 $this->lineStyleProperties['width'] = $lineWidth;
791 }
792 if ($compoundType !== '') {
793 $this->lineStyleProperties['compound'] = $compoundType;
794 }
795 if ($dashType !== '') {
796 $this->lineStyleProperties['dash'] = $dashType;
797 }
798 if ($capType !== '') {
799 $this->lineStyleProperties['cap'] = $capType;
800 }
801 if ($joinType !== '') {
802 $this->lineStyleProperties['join'] = $joinType;
803 }
804 if ($headArrowType !== '') {
805 $this->lineStyleProperties['arrow']['head']['type'] = $headArrowType;
806 }
807 if (isset(self::ARROW_SIZES[$headArrowSize])) {
808 $this->lineStyleProperties['arrow']['head']['size'] = $headArrowSize;
809 $this->lineStyleProperties['arrow']['head']['w'] = self::ARROW_SIZES[$headArrowSize]['w'];
810 $this->lineStyleProperties['arrow']['head']['len'] = self::ARROW_SIZES[$headArrowSize]['len'];
811 }
812 if ($endArrowType !== '') {
813 $this->lineStyleProperties['arrow']['end']['type'] = $endArrowType;
814 }
815 if (isset(self::ARROW_SIZES[$endArrowSize])) {
816 $this->lineStyleProperties['arrow']['end']['size'] = $endArrowSize;
817 $this->lineStyleProperties['arrow']['end']['w'] = self::ARROW_SIZES[$endArrowSize]['w'];
818 $this->lineStyleProperties['arrow']['end']['len'] = self::ARROW_SIZES[$endArrowSize]['len'];
819 }
820 if ($headArrowWidth !== '') {
821 $this->lineStyleProperties['arrow']['head']['w'] = $headArrowWidth;
822 }
823 if ($headArrowLength !== '') {
824 $this->lineStyleProperties['arrow']['head']['len'] = $headArrowLength;
825 }
826 if ($endArrowWidth !== '') {
827 $this->lineStyleProperties['arrow']['end']['w'] = $endArrowWidth;
828 }
829 if ($endArrowLength !== '') {
830 $this->lineStyleProperties['arrow']['end']['len'] = $endArrowLength;
831 }
832 }
833
834 /** @return mixed[] */
835 public function getLineStyleArray(): array
836 {
837 return $this->lineStyleProperties;
838 }
839
840 /** @param mixed[] $lineStyleProperties */
841 public function setLineStyleArray(array $lineStyleProperties = []): self
842 {
843 /** @var array{width?: ?string, compound?: string, dash?: string, cap?: string, join?: string, arrow?: array{head?: array{type?: string, size?: int, w?: string, len?: string}, end?: array{type?: string, size?: int, w?: string, len?: string}}} $lineStyleProperties */
844 $this->activateObject();
845 $this->lineStyleProperties['width'] = $lineStyleProperties['width'] ?? null;
846 $this->lineStyleProperties['compound'] = $lineStyleProperties['compound'] ?? '';
847 $this->lineStyleProperties['dash'] = $lineStyleProperties['dash'] ?? '';
848 $this->lineStyleProperties['cap'] = $lineStyleProperties['cap'] ?? '';
849 $this->lineStyleProperties['join'] = $lineStyleProperties['join'] ?? '';
850 $this->lineStyleProperties['arrow']['head']['type'] = $lineStyleProperties['arrow']['head']['type'] ?? '';
851 $this->lineStyleProperties['arrow']['head']['size'] = $lineStyleProperties['arrow']['head']['size'] ?? '';
852 $this->lineStyleProperties['arrow']['head']['w'] = $lineStyleProperties['arrow']['head']['w'] ?? '';
853 $this->lineStyleProperties['arrow']['head']['len'] = $lineStyleProperties['arrow']['head']['len'] ?? '';
854 $this->lineStyleProperties['arrow']['end']['type'] = $lineStyleProperties['arrow']['end']['type'] ?? '';
855 $this->lineStyleProperties['arrow']['end']['size'] = $lineStyleProperties['arrow']['end']['size'] ?? '';
856 $this->lineStyleProperties['arrow']['end']['w'] = $lineStyleProperties['arrow']['end']['w'] ?? '';
857 $this->lineStyleProperties['arrow']['end']['len'] = $lineStyleProperties['arrow']['end']['len'] ?? '';
858
859 return $this;
860 }
861
862 /**
863 * @param mixed $value
864 */
865 public function setLineStyleProperty(string $propertyName, $value): self
866 {
867 $this->activateObject();
868 $this->lineStyleProperties[$propertyName] = $value; //* @phpstan-ignore assign.propertyType (Too complicated)
869
870 return $this;
871 }
872
873 /**
874 * Get Line Style Property.
875 *
876 * @param array<mixed>|string $elements
877 */
878 public function getLineStyleProperty($elements): ?string
879 {
880 $retVal = $this->getArrayElementsValue($this->lineStyleProperties, $elements);
881 if (is_scalar($retVal)) {
882 $retVal = (string) $retVal;
883 } elseif ($retVal !== null) {
884 // @codeCoverageIgnoreStart
885 throw new Exception('Unexpected value for lineStyleProperty');
886 // @codeCoverageIgnoreEnd
887 }
888
889 return $retVal;
890 }
891
892 protected const ARROW_SIZES = [
893 1 => ['w' => 'sm', 'len' => 'sm'],
894 2 => ['w' => 'sm', 'len' => 'med'],
895 3 => ['w' => 'sm', 'len' => 'lg'],
896 4 => ['w' => 'med', 'len' => 'sm'],
897 5 => ['w' => 'med', 'len' => 'med'],
898 6 => ['w' => 'med', 'len' => 'lg'],
899 7 => ['w' => 'lg', 'len' => 'sm'],
900 8 => ['w' => 'lg', 'len' => 'med'],
901 9 => ['w' => 'lg', 'len' => 'lg'],
902 ];
903
904 /**
905 * Get Line Style Arrow Size.
906 */
907 protected function getLineStyleArrowSize(int $arraySelector, string $arrayKaySelector): string
908 {
909 return self::ARROW_SIZES[$arraySelector][$arrayKaySelector] ?? '';
910 }
911
912 /**
913 * Get Line Style Arrow Parameters.
914 */
915 public function getLineStyleArrowParameters(string $arrowSelector, string $propertySelector): string
916 {
917 return $this->getLineStyleArrowSize((int) $this->lineStyleProperties['arrow'][$arrowSelector]['size'], $propertySelector);
918 }
919
920 /**
921 * Get Line Style Arrow Width.
922 */
923 public function getLineStyleArrowWidth(string $arrow): ?string
924 {
925 return $this->getLineStyleProperty(['arrow', $arrow, 'w']);
926 }
927
928 /**
929 * Get Line Style Arrow Excel Length.
930 */
931 public function getLineStyleArrowLength(string $arrow): ?string
932 {
933 return $this->getLineStyleProperty(['arrow', $arrow, 'len']);
934 }
935
936 /**
937 * Implement PHP __clone to create a deep clone, not just a shallow copy.
938 */
939 public function __clone()
940 {
941 $this->lineColor = clone $this->lineColor;
942 $this->glowColor = clone $this->glowColor;
943 $this->shadowColor = clone $this->shadowColor;
944 }
945 }
946