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