Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
13 / 13 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
Chart | |
100.00% |
13 / 13 |
|
100.00% |
6 / 6 |
6 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
getType | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setType | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
addSeries | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
getSeries | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getStyle | |
100.00% |
1 / 1 |
|
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\Element; |
20 | |
21 | use PhpOffice\PhpWord\Style\Chart as ChartStyle; |
22 | |
23 | /** |
24 | * Chart element. |
25 | * |
26 | * @since 0.12.0 |
27 | */ |
28 | class Chart extends AbstractElement |
29 | { |
30 | /** |
31 | * Is part of collection. |
32 | * |
33 | * @var bool |
34 | */ |
35 | protected $collectionRelation = true; |
36 | |
37 | /** |
38 | * Type. |
39 | * |
40 | * @var string |
41 | */ |
42 | private $type = 'pie'; |
43 | |
44 | /** |
45 | * Series. |
46 | * |
47 | * @var array |
48 | */ |
49 | private $series = []; |
50 | |
51 | /** |
52 | * Chart style. |
53 | * |
54 | * @var ?ChartStyle |
55 | */ |
56 | private $style; |
57 | |
58 | /** |
59 | * Create new instance. |
60 | * |
61 | * @param string $type |
62 | * @param array $categories |
63 | * @param array $values |
64 | * @param array $style |
65 | * @param null|mixed $seriesName |
66 | */ |
67 | public function __construct($type, $categories, $values, $style = null, $seriesName = null) |
68 | { |
69 | $this->setType($type); |
70 | $this->addSeries($categories, $values, $seriesName); |
71 | $this->style = $this->setNewStyle(new ChartStyle(), $style, true); |
72 | } |
73 | |
74 | /** |
75 | * Get type. |
76 | * |
77 | * @return string |
78 | */ |
79 | public function getType() |
80 | { |
81 | return $this->type; |
82 | } |
83 | |
84 | /** |
85 | * Set type. |
86 | * |
87 | * @param string $value |
88 | */ |
89 | public function setType($value): void |
90 | { |
91 | $enum = ['pie', 'doughnut', 'line', 'bar', 'stacked_bar', 'percent_stacked_bar', 'column', 'stacked_column', 'percent_stacked_column', 'area', 'radar', 'scatter']; |
92 | $this->type = $this->setEnumVal($value, $enum, 'pie'); |
93 | } |
94 | |
95 | /** |
96 | * Add series. |
97 | * |
98 | * @param array $categories |
99 | * @param array $values |
100 | * @param null|mixed $name |
101 | */ |
102 | public function addSeries($categories, $values, $name = null): void |
103 | { |
104 | $this->series[] = [ |
105 | 'categories' => $categories, |
106 | 'values' => $values, |
107 | 'name' => $name, |
108 | ]; |
109 | } |
110 | |
111 | /** |
112 | * Get series. |
113 | * |
114 | * @return array |
115 | */ |
116 | public function getSeries() |
117 | { |
118 | return $this->series; |
119 | } |
120 | |
121 | /** |
122 | * Get chart style. |
123 | * |
124 | * @return ?ChartStyle |
125 | */ |
126 | public function getStyle() |
127 | { |
128 | return $this->style; |
129 | } |
130 | } |