Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
12 / 12
CRAP
100.00% covered (success)
100.00%
25 / 25
Chart
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
12 / 12
14
100.00% covered (success)
100.00%
25 / 25
 __construct
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
6 / 6
 __clone
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
6 / 6
 getDisplayBlankAs
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 getTitle
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 getLegend
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 getPlotArea
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 getView3D
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 hasIncludedSpreadsheet
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 setDisplayBlankAs
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
3 / 3
 setIncludeSpreadsheet
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getIndexedFilename
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 getHashCode
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
1 / 1
1<?php
2/**
3 * This file is part of PHPPresentation - A pure PHP library for reading and writing
4 * presentations documents.
5 *
6 * PHPPresentation 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/PHPPresentation/contributors.
12 *
13 * @see        https://github.com/PHPOffice/PHPPresentation
14 *
15 * @copyright   2009-2015 PHPPresentation contributors
16 * @license     http://www.gnu.org/licenses/lgpl.txt LGPL version 3
17 */
18
19declare(strict_types=1);
20
21namespace PhpOffice\PhpPresentation\Shape;
22
23use PhpOffice\PhpPresentation\ComparableInterface;
24use PhpOffice\PhpPresentation\Shape\Chart\Legend;
25use PhpOffice\PhpPresentation\Shape\Chart\PlotArea;
26use PhpOffice\PhpPresentation\Shape\Chart\Title;
27use PhpOffice\PhpPresentation\Shape\Chart\View3D;
28
29/**
30 * Chart element.
31 */
32class Chart extends AbstractGraphic implements ComparableInterface
33{
34    public const BLANKAS_GAP = 'gap';
35    public const BLANKAS_ZERO = 'zero';
36    public const BLANKAS_SPAN = 'span';
37
38    /**
39     * Title.
40     *
41     * @var Title
42     */
43    private $title;
44
45    /**
46     * Legend.
47     *
48     * @var Legend
49     */
50    private $legend;
51
52    /**
53     * Plot area.
54     *
55     * @var PlotArea
56     */
57    private $plotArea;
58
59    /**
60     * View 3D.
61     *
62     * @var View3D
63     */
64    private $view3D;
65
66    /**
67     * Is the spreadsheet included for editing data ?
68     *
69     * @var bool
70     */
71    private $includeSpreadsheet = false;
72
73    /**
74     * How to display blank (missing) values? Not set by default.
75     *
76     * @var string
77     */
78    private $displayBlankAs = self::BLANKAS_ZERO;
79
80    /**
81     * Create a new Chart.
82     */
83    public function __construct()
84    {
85        // Initialize
86        $this->title = new Title();
87        $this->legend = new Legend();
88        $this->plotArea = new PlotArea();
89        $this->view3D = new View3D();
90
91        // Initialize parent
92        parent::__construct();
93    }
94
95    public function __clone()
96    {
97        parent::__clone();
98
99        $this->title = clone $this->title;
100        $this->legend = clone $this->legend;
101        $this->plotArea = clone $this->plotArea;
102        $this->view3D = clone $this->view3D;
103    }
104
105    /**
106     * How missing/blank values are displayed on chart (dispBlanksAs property)
107     *
108     * @return string
109     */
110    public function getDisplayBlankAs(): string
111    {
112        return $this->displayBlankAs;
113    }
114
115    /**
116     * Get Title.
117     *
118     * @return Title
119     */
120    public function getTitle(): Title
121    {
122        return $this->title;
123    }
124
125    /**
126     * Get Legend.
127     *
128     * @return Legend
129     */
130    public function getLegend(): Legend
131    {
132        return $this->legend;
133    }
134
135    /**
136     * Get PlotArea.
137     *
138     * @return PlotArea
139     */
140    public function getPlotArea(): PlotArea
141    {
142        return $this->plotArea;
143    }
144
145    /**
146     * Get View3D.
147     *
148     * @return View3D
149     */
150    public function getView3D(): View3D
151    {
152        return $this->view3D;
153    }
154
155    /**
156     * Is the spreadsheet included for editing data ?
157     *
158     * @return bool
159     */
160    public function hasIncludedSpreadsheet(): bool
161    {
162        return $this->includeSpreadsheet;
163    }
164
165    /**
166     * Define a way to display missing/blank values (dispBlanksAs property)
167     *
168     * @param string $value
169     *
170     * @return self
171     */
172    public function setDisplayBlankAs(string $value): self
173    {
174        if (in_array($value, [self::BLANKAS_GAP, self::BLANKAS_SPAN, self::BLANKAS_ZERO])) {
175            $this->displayBlankAs = $value;
176        }
177
178        return $this;
179    }
180
181    /**
182     * Is the spreadsheet included for editing data ?
183     *
184     * @param bool $value
185     *
186     * @return self
187     */
188    public function setIncludeSpreadsheet(bool $value = false): self
189    {
190        $this->includeSpreadsheet = $value;
191
192        return $this;
193    }
194
195    /**
196     * Get indexed filename (using image index).
197     *
198     * @return string
199     */
200    public function getIndexedFilename(): string
201    {
202        return 'chart' . $this->getImageIndex() . '.xml';
203    }
204
205    /**
206     * Get hash code.
207     *
208     * @return string Hash code
209     */
210    public function getHashCode(): string
211    {
212        return md5(parent::getHashCode() . $this->title->getHashCode() . $this->legend->getHashCode() . $this->plotArea->getHashCode() . $this->view3D->getHashCode() . ($this->includeSpreadsheet ? 1 : 0) . __CLASS__);
213    }
214}