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