Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
94.64% |
53 / 56 |
|
96.97% |
32 / 33 |
CRAP | |
0.00% |
0 / 1 |
Chart | |
94.64% |
53 / 56 |
|
96.97% |
32 / 33 |
35.19 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getWidth | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setWidth | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getHeight | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setHeight | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
is3d | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
set3d | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getColors | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setColors | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getTitle | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setTitle | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
isShowLegend | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setShowLegend | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getLegendPosition | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setLegendPosition | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
showAxisLabels | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setShowAxisLabels | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getDataLabelOptions | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setDataLabelOptions | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 | |||
showGridY | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setShowGridY | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getCategoryLabelPosition | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setCategoryLabelPosition | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
getValueLabelPosition | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setValueLabelPosition | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
getCategoryAxisTitle | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setCategoryAxisTitle | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getValueAxisTitle | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setValueAxisTitle | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getMajorTickPosition | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setMajorTickPosition | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
showGridX | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setShowGridX | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | /** |
4 | * This file is part of PHPWord - A pure PHP library for reading and writing |
5 | * word processing documents. |
6 | * |
7 | * PHPWord is free software distributed under the terms of the GNU Lesser |
8 | * General Public License version 3 as published by the Free Software Foundation. |
9 | * |
10 | * For the full copyright and license information, please read the LICENSE |
11 | * file that was distributed with this source code. For the full list of |
12 | * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. |
13 | * |
14 | * @see https://github.com/PHPOffice/PHPWord |
15 | * |
16 | * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 |
17 | */ |
18 | |
19 | namespace PhpOffice\PhpWord\Style; |
20 | |
21 | /** |
22 | * Chart style. |
23 | * |
24 | * @since 0.12.0 |
25 | */ |
26 | class Chart extends AbstractStyle |
27 | { |
28 | /** |
29 | * Width (in EMU). |
30 | * |
31 | * @var int |
32 | */ |
33 | private $width = 1000000; |
34 | |
35 | /** |
36 | * Height (in EMU). |
37 | * |
38 | * @var int |
39 | */ |
40 | private $height = 1000000; |
41 | |
42 | /** |
43 | * Is 3D; applies to pie, bar, line, area. |
44 | * |
45 | * @var bool |
46 | */ |
47 | private $is3d = false; |
48 | |
49 | /** |
50 | * A list of colors to use in the chart. |
51 | * |
52 | * @var array |
53 | */ |
54 | private $colors = []; |
55 | |
56 | /** |
57 | * Chart title. |
58 | * |
59 | * @var string |
60 | */ |
61 | private $title; |
62 | |
63 | /** |
64 | * Chart legend visibility. |
65 | * |
66 | * @var bool |
67 | */ |
68 | private $showLegend = false; |
69 | |
70 | /** |
71 | * Chart legend Position. |
72 | * Possible values are 'r', 't', 'b', 'l', 'tr'. |
73 | * |
74 | * @var string |
75 | */ |
76 | private $legendPosition = 'r'; |
77 | |
78 | /** |
79 | * A list of display options for data labels. |
80 | * |
81 | * @var array |
82 | */ |
83 | private $dataLabelOptions = [ |
84 | 'showVal' => true, // value |
85 | 'showCatName' => true, // category name |
86 | 'showLegendKey' => false, //show the cart legend |
87 | 'showSerName' => false, // series name |
88 | 'showPercent' => false, |
89 | 'showLeaderLines' => false, |
90 | 'showBubbleSize' => false, |
91 | ]; |
92 | |
93 | /** |
94 | * A string that tells the writer where to write chart labels or to skip |
95 | * "nextTo" - sets labels next to the axis (bar graphs on the left) (default) |
96 | * "low" - labels on the left side of the graph |
97 | * "high" - labels on the right side of the graph. |
98 | * |
99 | * @var string |
100 | */ |
101 | private $categoryLabelPosition = 'nextTo'; |
102 | |
103 | /** |
104 | * A string that tells the writer where to write chart labels or to skip |
105 | * "nextTo" - sets labels next to the axis (bar graphs on the bottom) (default) |
106 | * "low" - labels are below the graph |
107 | * "high" - labels above the graph. |
108 | * |
109 | * @var string |
110 | */ |
111 | private $valueLabelPosition = 'nextTo'; |
112 | |
113 | /** |
114 | * @var string |
115 | */ |
116 | private $categoryAxisTitle; |
117 | |
118 | /** |
119 | * @var string |
120 | */ |
121 | private $valueAxisTitle; |
122 | |
123 | /** |
124 | * The position for major tick marks |
125 | * Possible values are 'in', 'out', 'cross', 'none'. |
126 | * |
127 | * @var string |
128 | */ |
129 | private $majorTickMarkPos = 'none'; |
130 | |
131 | /** |
132 | * Show labels for axis. |
133 | * |
134 | * @var bool |
135 | */ |
136 | private $showAxisLabels = false; |
137 | |
138 | /** |
139 | * Show Gridlines for Y-Axis. |
140 | * |
141 | * @var bool |
142 | */ |
143 | private $gridY = false; |
144 | |
145 | /** |
146 | * Show Gridlines for X-Axis. |
147 | * |
148 | * @var bool |
149 | */ |
150 | private $gridX = false; |
151 | |
152 | /** |
153 | * Create a new instance. |
154 | * |
155 | * @param array $style |
156 | */ |
157 | public function __construct($style = []) |
158 | { |
159 | $this->setStyleByArray($style); |
160 | } |
161 | |
162 | /** |
163 | * Get width. |
164 | * |
165 | * @return int |
166 | */ |
167 | public function getWidth() |
168 | { |
169 | return $this->width; |
170 | } |
171 | |
172 | /** |
173 | * Set width. |
174 | * |
175 | * @param int $value |
176 | * |
177 | * @return self |
178 | */ |
179 | public function setWidth($value = null) |
180 | { |
181 | $this->width = $this->setIntVal($value, $this->width); |
182 | |
183 | return $this; |
184 | } |
185 | |
186 | /** |
187 | * Get height. |
188 | * |
189 | * @return int |
190 | */ |
191 | public function getHeight() |
192 | { |
193 | return $this->height; |
194 | } |
195 | |
196 | /** |
197 | * Set height. |
198 | * |
199 | * @param int $value |
200 | * |
201 | * @return self |
202 | */ |
203 | public function setHeight($value = null) |
204 | { |
205 | $this->height = $this->setIntVal($value, $this->height); |
206 | |
207 | return $this; |
208 | } |
209 | |
210 | /** |
211 | * Is 3D. |
212 | * |
213 | * @return bool |
214 | */ |
215 | public function is3d() |
216 | { |
217 | return $this->is3d; |
218 | } |
219 | |
220 | /** |
221 | * Set 3D. |
222 | * |
223 | * @param bool $value |
224 | * |
225 | * @return self |
226 | */ |
227 | public function set3d($value = true) |
228 | { |
229 | $this->is3d = $this->setBoolVal($value, $this->is3d); |
230 | |
231 | return $this; |
232 | } |
233 | |
234 | /** |
235 | * Get the list of colors to use in a chart. |
236 | * |
237 | * @return array |
238 | */ |
239 | public function getColors() |
240 | { |
241 | return $this->colors; |
242 | } |
243 | |
244 | /** |
245 | * Set the colors to use in a chart. |
246 | * |
247 | * @param array $value a list of colors to use in the chart |
248 | * |
249 | * @return self |
250 | */ |
251 | public function setColors($value = []) |
252 | { |
253 | $this->colors = $value; |
254 | |
255 | return $this; |
256 | } |
257 | |
258 | /** |
259 | * Get the chart title. |
260 | * |
261 | * @return string |
262 | */ |
263 | public function getTitle() |
264 | { |
265 | return $this->title; |
266 | } |
267 | |
268 | /** |
269 | * Set the chart title. |
270 | * |
271 | * @param string $value |
272 | * |
273 | * @return self |
274 | */ |
275 | public function setTitle($value = null) |
276 | { |
277 | $this->title = $value; |
278 | |
279 | return $this; |
280 | } |
281 | |
282 | /** |
283 | * Get chart legend visibility. |
284 | * |
285 | * @return bool |
286 | */ |
287 | public function isShowLegend() |
288 | { |
289 | return $this->showLegend; |
290 | } |
291 | |
292 | /** |
293 | * Set chart legend visibility. |
294 | * |
295 | * @param bool $value |
296 | * |
297 | * @return self |
298 | */ |
299 | public function setShowLegend($value = false) |
300 | { |
301 | $this->showLegend = $value; |
302 | |
303 | return $this; |
304 | } |
305 | |
306 | /** |
307 | * Get chart legend position. |
308 | * |
309 | * @return string |
310 | */ |
311 | public function getLegendPosition() |
312 | { |
313 | return $this->legendPosition; |
314 | } |
315 | |
316 | /** |
317 | * Set chart legend position. choices: |
318 | * "r" - right of chart |
319 | * "b" - bottom of chart |
320 | * "t" - top of chart |
321 | * "l" - left of chart |
322 | * "tr" - top right of chart. |
323 | * |
324 | * default: right |
325 | * |
326 | * @param string $legendPosition |
327 | * |
328 | * @return self |
329 | */ |
330 | public function setLegendPosition($legendPosition = 'r') |
331 | { |
332 | $enum = ['r', 'b', 't', 'l', 'tr']; |
333 | $this->legendPosition = $this->setEnumVal($legendPosition, $enum, $this->legendPosition); |
334 | |
335 | return $this; |
336 | } |
337 | |
338 | /* |
339 | * Show labels for axis |
340 | * |
341 | * @return bool |
342 | */ |
343 | public function showAxisLabels() |
344 | { |
345 | return $this->showAxisLabels; |
346 | } |
347 | |
348 | /** |
349 | * Set show Gridlines for Y-Axis. |
350 | * |
351 | * @param bool $value |
352 | * |
353 | * @return self |
354 | */ |
355 | public function setShowAxisLabels($value = true) |
356 | { |
357 | $this->showAxisLabels = $this->setBoolVal($value, $this->showAxisLabels); |
358 | |
359 | return $this; |
360 | } |
361 | |
362 | /** |
363 | * get the list of options for data labels. |
364 | * |
365 | * @return array |
366 | */ |
367 | public function getDataLabelOptions() |
368 | { |
369 | return $this->dataLabelOptions; |
370 | } |
371 | |
372 | /** |
373 | * Set values for data label options. |
374 | * This will only change values for options defined in $this->dataLabelOptions, and cannot create new ones. |
375 | * |
376 | * @param array $values [description] |
377 | */ |
378 | public function setDataLabelOptions($values = []): void |
379 | { |
380 | foreach (array_keys($this->dataLabelOptions) as $option) { |
381 | if (isset($values[$option])) { |
382 | $this->dataLabelOptions[$option] = $this->setBoolVal( |
383 | $values[$option], |
384 | $this->dataLabelOptions[$option] |
385 | ); |
386 | } |
387 | } |
388 | } |
389 | |
390 | /* |
391 | * Show Gridlines for Y-Axis |
392 | * |
393 | * @return bool |
394 | */ |
395 | public function showGridY() |
396 | { |
397 | return $this->gridY; |
398 | } |
399 | |
400 | /** |
401 | * Set show Gridlines for Y-Axis. |
402 | * |
403 | * @param bool $value |
404 | * |
405 | * @return self |
406 | */ |
407 | public function setShowGridY($value = true) |
408 | { |
409 | $this->gridY = $this->setBoolVal($value, $this->gridY); |
410 | |
411 | return $this; |
412 | } |
413 | |
414 | /** |
415 | * Get the categoryLabelPosition setting. |
416 | * |
417 | * @return string |
418 | */ |
419 | public function getCategoryLabelPosition() |
420 | { |
421 | return $this->categoryLabelPosition; |
422 | } |
423 | |
424 | /** |
425 | * Set the categoryLabelPosition setting |
426 | * "none" - skips writing labels |
427 | * "nextTo" - sets labels next to the (bar graphs on the left) |
428 | * "low" - labels on the left side of the graph |
429 | * "high" - labels on the right side of the graph. |
430 | * |
431 | * @param mixed $labelPosition |
432 | * |
433 | * @return self |
434 | */ |
435 | public function setCategoryLabelPosition($labelPosition) |
436 | { |
437 | $enum = ['nextTo', 'low', 'high']; |
438 | $this->categoryLabelPosition = $this->setEnumVal($labelPosition, $enum, $this->categoryLabelPosition); |
439 | |
440 | return $this; |
441 | } |
442 | |
443 | /** |
444 | * Get the valueAxisLabelPosition setting. |
445 | * |
446 | * @return string |
447 | */ |
448 | public function getValueLabelPosition() |
449 | { |
450 | return $this->valueLabelPosition; |
451 | } |
452 | |
453 | /** |
454 | * Set the valueLabelPosition setting |
455 | * "none" - skips writing labels |
456 | * "nextTo" - sets labels next to the value |
457 | * "low" - sets labels are below the graph |
458 | * "high" - sets labels above the graph. |
459 | * |
460 | * @param string |
461 | * @param mixed $labelPosition |
462 | */ |
463 | public function setValueLabelPosition($labelPosition) |
464 | { |
465 | $enum = ['nextTo', 'low', 'high']; |
466 | $this->valueLabelPosition = $this->setEnumVal($labelPosition, $enum, $this->valueLabelPosition); |
467 | |
468 | return $this; |
469 | } |
470 | |
471 | /** |
472 | * Get the categoryAxisTitle. |
473 | * |
474 | * @return string |
475 | */ |
476 | public function getCategoryAxisTitle() |
477 | { |
478 | return $this->categoryAxisTitle; |
479 | } |
480 | |
481 | /** |
482 | * Set the title that appears on the category side of the chart. |
483 | * |
484 | * @param string $axisTitle |
485 | */ |
486 | public function setCategoryAxisTitle($axisTitle) |
487 | { |
488 | $this->categoryAxisTitle = $axisTitle; |
489 | |
490 | return $this; |
491 | } |
492 | |
493 | /** |
494 | * Get the valueAxisTitle. |
495 | * |
496 | * @return string |
497 | */ |
498 | public function getValueAxisTitle() |
499 | { |
500 | return $this->valueAxisTitle; |
501 | } |
502 | |
503 | /** |
504 | * Set the title that appears on the value side of the chart. |
505 | * |
506 | * @param string $axisTitle |
507 | */ |
508 | public function setValueAxisTitle($axisTitle) |
509 | { |
510 | $this->valueAxisTitle = $axisTitle; |
511 | |
512 | return $this; |
513 | } |
514 | |
515 | public function getMajorTickPosition() |
516 | { |
517 | return $this->majorTickMarkPos; |
518 | } |
519 | |
520 | /** |
521 | * Set the position for major tick marks. |
522 | * |
523 | * @param string $position |
524 | */ |
525 | public function setMajorTickPosition($position): void |
526 | { |
527 | $enum = ['in', 'out', 'cross', 'none']; |
528 | $this->majorTickMarkPos = $this->setEnumVal($position, $enum, $this->majorTickMarkPos); |
529 | } |
530 | |
531 | /** |
532 | * Show Gridlines for X-Axis. |
533 | * |
534 | * @return bool |
535 | */ |
536 | public function showGridX() |
537 | { |
538 | return $this->gridX; |
539 | } |
540 | |
541 | /** |
542 | * Set show Gridlines for X-Axis. |
543 | * |
544 | * @param bool $value |
545 | * |
546 | * @return self |
547 | */ |
548 | public function setShowGridX($value = true) |
549 | { |
550 | $this->gridX = $this->setBoolVal($value, $this->gridX); |
551 | |
552 | return $this; |
553 | } |
554 | } |