Completed
Push — master ( 4f40d9...14b52b )
by Franck
17s
created

Legend::isVisible()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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