Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
38 / 38
100.00% covered (success)
100.00%
24 / 24
CRAP
100.00% covered (success)
100.00%
1 / 1
Legend
100.00% covered (success)
100.00%
38 / 38
100.00% covered (success)
100.00%
24 / 24
25
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 isVisible
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setVisible
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getPosition
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setPosition
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getOffsetX
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setOffsetX
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getOffsetY
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setOffsetY
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getWidth
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setWidth
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getHeight
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setHeight
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getFont
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setFont
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getBorder
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setBorder
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getFill
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setFill
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getAlignment
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setAlignment
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getHashCode
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
 getHashIndex
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setHashIndex
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 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 * @license     http://www.gnu.org/licenses/lgpl.txt LGPL version 3
16 */
17
18declare(strict_types=1);
19
20namespace PhpOffice\PhpPresentation\Shape\Chart;
21
22use PhpOffice\PhpPresentation\ComparableInterface;
23use PhpOffice\PhpPresentation\Style\Alignment;
24use PhpOffice\PhpPresentation\Style\Border;
25use PhpOffice\PhpPresentation\Style\Fill;
26use PhpOffice\PhpPresentation\Style\Font;
27
28/**
29 * \PhpOffice\PhpPresentation\Shape\Chart\Legend.
30 */
31class Legend implements ComparableInterface
32{
33    /** Legend positions */
34    public const POSITION_BOTTOM = 'b';
35    public const POSITION_LEFT = 'l';
36    public const POSITION_RIGHT = 'r';
37    public const POSITION_TOP = 't';
38    public const POSITION_TOPRIGHT = 'tr';
39
40    /**
41     * Visible.
42     *
43     * @var bool
44     */
45    private $visible = true;
46
47    /**
48     * Position.
49     *
50     * @var string
51     */
52    private $position = self::POSITION_RIGHT;
53
54    /**
55     * OffsetX (as a fraction of the chart).
56     *
57     * @var float
58     */
59    private $offsetX = 0;
60
61    /**
62     * OffsetY (as a fraction of the chart).
63     *
64     * @var float
65     */
66    private $offsetY = 0;
67
68    /**
69     * Width (as a fraction of the chart).
70     *
71     * @var float
72     */
73    private $width = 0;
74
75    /**
76     * Height (as a fraction of the chart).
77     *
78     * @var float
79     */
80    private $height = 0;
81
82    /**
83     * Font.
84     *
85     * @var null|Font
86     */
87    private $font;
88
89    /**
90     * Border.
91     *
92     * @var Border
93     */
94    private $border;
95
96    /**
97     * Fill.
98     *
99     * @var Fill
100     */
101    private $fill;
102
103    /**
104     * Alignment.
105     *
106     * @var Alignment
107     */
108    private $alignment;
109
110    /**
111     * Create a new \PhpOffice\PhpPresentation\Shape\Chart\Legend instance.
112     */
113    public function __construct()
114    {
115        $this->font = new Font();
116        $this->border = new Border();
117        $this->fill = new Fill();
118        $this->alignment = new Alignment();
119    }
120
121    /**
122     * Get Visible.
123     *
124     * @return bool
125     */
126    public function isVisible()
127    {
128        return $this->visible;
129    }
130
131    /**
132     * Set Visible.
133     *
134     * @param bool $value
135     *
136     * @return Legend
137     */
138    public function setVisible($value = true)
139    {
140        $this->visible = $value;
141
142        return $this;
143    }
144
145    /**
146     * Get Position.
147     *
148     * @return string
149     */
150    public function getPosition()
151    {
152        return $this->position;
153    }
154
155    /**
156     * Set Position.
157     *
158     * @param string $value
159     *
160     * @return Legend
161     */
162    public function setPosition($value = self::POSITION_RIGHT)
163    {
164        $this->position = $value;
165
166        return $this;
167    }
168
169    /**
170     * Get OffsetX (as a fraction of the chart).
171     */
172    public function getOffsetX(): float
173    {
174        return $this->offsetX;
175    }
176
177    /**
178     * Set OffsetX (as a fraction of the chart).
179     */
180    public function setOffsetX(float $pValue = 0): self
181    {
182        $this->offsetX = $pValue;
183
184        return $this;
185    }
186
187    /**
188     * Get OffsetY (as a fraction of the chart).
189     */
190    public function getOffsetY(): float
191    {
192        return $this->offsetY;
193    }
194
195    /**
196     * Set OffsetY (as a fraction of the chart).
197     */
198    public function setOffsetY(float $pValue = 0): self
199    {
200        $this->offsetY = $pValue;
201
202        return $this;
203    }
204
205    /**
206     * Get Width (as a fraction of the chart).
207     */
208    public function getWidth(): float
209    {
210        return $this->width;
211    }
212
213    /**
214     * Set Width (as a fraction of the chart).
215     */
216    public function setWidth(float $pValue = 0): self
217    {
218        $this->width = $pValue;
219
220        return $this;
221    }
222
223    /**
224     * Get Height (as a fraction of the chart).
225     */
226    public function getHeight(): float
227    {
228        return $this->height;
229    }
230
231    /**
232     * Set Height (as a fraction of the chart).
233     */
234    public function setHeight(float $value = 0): self
235    {
236        $this->height = $value;
237
238        return $this;
239    }
240
241    /**
242     * Get font.
243     */
244    public function getFont(): ?Font
245    {
246        return $this->font;
247    }
248
249    /**
250     * Set font.
251     *
252     * @param null|Font $pFont Font
253     */
254    public function setFont(?Font $pFont = null): self
255    {
256        $this->font = $pFont;
257
258        return $this;
259    }
260
261    /**
262     * Get Border.
263     *
264     * @return Border
265     */
266    public function getBorder()
267    {
268        return $this->border;
269    }
270
271    /**
272     * Set Border.
273     *
274     * @return Legend
275     */
276    public function setBorder(Border $border)
277    {
278        $this->border = $border;
279
280        return $this;
281    }
282
283    /**
284     * Get Fill.
285     *
286     * @return Fill
287     */
288    public function getFill()
289    {
290        return $this->fill;
291    }
292
293    /**
294     * Set Fill.
295     *
296     * @return Legend
297     */
298    public function setFill(Fill $fill)
299    {
300        $this->fill = $fill;
301
302        return $this;
303    }
304
305    /**
306     * Get alignment.
307     *
308     * @return Alignment
309     */
310    public function getAlignment()
311    {
312        return $this->alignment;
313    }
314
315    /**
316     * Set alignment.
317     *
318     * @return Legend
319     */
320    public function setAlignment(Alignment $alignment)
321    {
322        $this->alignment = $alignment;
323
324        return $this;
325    }
326
327    /**
328     * Get hash code.
329     *
330     * @return string Hash code
331     */
332    public function getHashCode(): string
333    {
334        return md5($this->position . $this->offsetX . $this->offsetY . $this->width . $this->height . $this->font->getHashCode() . $this->border->getHashCode() . $this->fill->getHashCode() . $this->alignment->getHashCode() . ($this->visible ? 't' : 'f') . __CLASS__);
335    }
336
337    /**
338     * Hash index.
339     *
340     * @var int
341     */
342    private $hashIndex;
343
344    /**
345     * Get hash index.
346     *
347     * Note that this index may vary during script execution! Only reliable moment is
348     * while doing a write of a workbook and when changes are not allowed.
349     *
350     * @return null|int Hash index
351     */
352    public function getHashIndex(): ?int
353    {
354        return $this->hashIndex;
355    }
356
357    /**
358     * Set hash index.
359     *
360     * Note that this index may vary during script execution! Only reliable moment is
361     * while doing a write of a workbook and when changes are not allowed.
362     *
363     * @param int $value Hash index
364     *
365     * @return Legend
366     */
367    public function setHashIndex(int $value)
368    {
369        $this->hashIndex = $value;
370
371        return $this;
372    }
373}