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