Completed
Push — develop ( 89b566...088966 )
by Franck
02:27 queued 02:17
created

Series::setFont()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
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\Fill;
22
use PhpOffice\PhpPresentation\Style\Font;
23
use PhpOffice\PhpPresentation\Style\Outline;
24
25
/**
26
 * \PhpOffice\PhpPresentation\Shape\Chart\Series
27
 */
28
class Series implements ComparableInterface
29
{
30
    /* Label positions */
31
    const LABEL_BESTFIT = 'bestFit';
32
    const LABEL_BOTTOM = 'b';
33
    const LABEL_CENTER = 'ctr';
34
    const LABEL_INSIDEBASE = 'inBase';
35
    const LABEL_INSIDEEND = 'inEnd';
36
    const LABEL_LEFT = 'i';
37
    const LABEL_OUTSIDEEND = 'outEnd';
38
    const LABEL_RIGHT = 'r';
39
    const LABEL_TOP = 't';
40
41
    /**
42
     * DataPointFills (key/value)
43
     *
44
     * @var array
45
     */
46
    private $dataPointFills = array();
47
48
    /**
49
     * Data Label Number Format
50
     *
51
     * @var string
52
     */
53
    private $DlblNumFormat = '';
54
55
    /**
56
     * Fill
57
     *
58
     * @var \PhpOffice\PhpPresentation\Style\Fill
59
     */
60
    private $fill;
61
62
    /**
63
     * Font
64
     *
65
     * @var \PhpOffice\PhpPresentation\Style\Font
66
     */
67
    private $font;
68
69
    /**
70
     * Label position
71
     *
72
     * @var string
73
     */
74
    private $labelPosition = 'ctr';
75
76
    /**
77
     * @var Marker
78
     */
79
    protected $marker;
80
81
    /**
82
     * @var Outline
83
     */
84
    protected $outline;
85
86
    /**
87
     * ShowCategoryName
88
     *
89
     * @var boolean
90
     */
91
    private $showCategoryName = false;
92
93
    /**
94
     * ShowLeaderLines
95
     *
96
     * @var boolean
97
     */
98
    private $showLeaderLines = true;
99
100
    /**
101
     * Show Legend Key
102
     *
103
     * @var boolean
104
     */
105
    private $showLegendKey = false;
106
107
    /**
108
     * ShowPercentage
109
     *
110
     * @var boolean
111
     */
112
    private $showPercentage = false;
113
114
    /**
115
     * ShowSeriesName
116
     *
117
     * @var boolean
118
     */
119
    private $showSeriesName = false;
120
121
    /**
122
     * ShowValue
123
     *
124
     * @var boolean
125
     */
126
    private $showValue = true;
127
128
    /**
129
     * Title
130
     *
131
     * @var string
132
     */
133
    private $title = 'Series Title';
134
135
    /**
136
     * Values (key/value)
137
     *
138
     * @var array
139
     */
140
    private $values = array();
141
142
    /**
143
     * Hash index
144
     *
145
     * @var string
146
     */
147
    private $hashIndex;
148
149
    /**
150
     * Create a new \PhpOffice\PhpPresentation\Shape\Chart\Series instance
151
     *
152
     * @param string $title  Title
153
     * @param array  $values Values
154
     */
155 87
    public function __construct($title = 'Series Title', $values = array())
156
    {
157 87
        $this->fill = new Fill();
158 87
        $this->font = new Font();
159 87
        $this->font->setName('Calibri');
160 87
        $this->font->setSize(9);
161 87
        $this->title  = $title;
162 87
        $this->values = $values;
163 87
        $this->marker = new Marker();
164 87
    }
165
166
    /**
167
     * Get Title
168
     *
169
     * @return string
170
     */
171 47
    public function getTitle()
172
    {
173 47
        return $this->title;
174
    }
175
176
    /**
177
     * Set Title
178
     *
179
     * @param  string                           $value
180
     * @return \PhpOffice\PhpPresentation\Shape\Chart\Series
181
     */
182 1
    public function setTitle($value = 'Series Title')
183
    {
184 1
        $this->title = $value;
185
186 1
        return $this;
187
    }
188
189
    /**
190
     * Get Data Label NumFormat
191
     *
192
     * @return string
193
     */
194 1
    public function getDlblNumFormat()
195
    {
196 1
        return $this->DlblNumFormat;
197
    }
198
199
    /**
200
     * Has Data Label NumFormat
201
     *
202
     * @return string
203
     */
204 4
    public function hasDlblNumFormat()
205
    {
206 4
        return !empty($this->DlblNumFormat);
207
    }
208
209
    /**
210
     * Set Data Label NumFormat
211
     *
212
     * @param  string $value
213
     * @return \PhpOffice\PhpPresentation\Shape\Chart\Series
214
     */
215 1
    public function setDlblNumFormat($value = '')
216
    {
217 1
        $this->DlblNumFormat = $value;
218 1
        return $this;
219
    }
220
221
    /**
222
     * Get Fill
223
     *
224
     * @return \PhpOffice\PhpPresentation\Style\Fill
225
     */
226 43
    public function getFill()
227
    {
228 43
        return $this->fill;
229
    }
230
231
    /**
232
     * Set Fill
233
     *
234
     * @param \PhpOffice\PhpPresentation\Style\Fill $fill
235
     * @return Series
236
     */
237 1
    public function setFill(Fill $fill = null)
238
    {
239 1
        $this->fill = $fill;
240 1
        return $this;
241
    }
242
243
    /**
244
     * Get DataPointFill
245
     *
246
     * @param  int                      $dataPointIndex Data point index.
247
     * @return \PhpOffice\PhpPresentation\Style\Fill
248
     */
249 11
    public function getDataPointFill($dataPointIndex)
250
    {
251 11
        if (!isset($this->dataPointFills[$dataPointIndex])) {
252 11
            $this->dataPointFills[$dataPointIndex] = new Fill();
253 11
        }
254
255 11
        return $this->dataPointFills[$dataPointIndex];
256
    }
257
258
    /**
259
     * Get DataPointFills
260
     *
261
     * @return Fill[]
262
     */
263 33
    public function getDataPointFills()
264
    {
265 33
        return $this->dataPointFills;
266
    }
267
268
    /**
269
     * Get Values
270
     *
271
     * @return array
272
     */
273 48
    public function getValues()
274
    {
275 48
        return $this->values;
276
    }
277
278
    /**
279
     * Set Values
280
     *
281
     * @param  array                            $value
282
     * @return \PhpOffice\PhpPresentation\Shape\Chart\Series
283
     */
284 1
    public function setValues($value = array())
285
    {
286 1
        $this->values = $value;
287
288 1
        return $this;
289
    }
290
291
    /**
292
     * Add Value
293
     *
294
     * @param  mixed                            $key
295
     * @param  mixed                            $value
296
     * @return \PhpOffice\PhpPresentation\Shape\Chart\Series
297
     */
298 1
    public function addValue($key, $value)
299
    {
300 1
        $this->values[$key] = $value;
301
302 1
        return $this;
303
    }
304
305
    /**
306
     * Get ShowSeriesName
307
     *
308
     * @return boolean
309
     */
310 25
    public function hasShowSeriesName()
311
    {
312 25
        return $this->showSeriesName;
313
    }
314
315
    /**
316
     * Set ShowSeriesName
317
     *
318
     * @param  boolean                          $value
319
     * @return \PhpOffice\PhpPresentation\Shape\Chart\Series
320
     */
321 11
    public function setShowSeriesName($value)
322
    {
323 11
        $this->showSeriesName = $value;
324
325 11
        return $this;
326
    }
327
328
    /**
329
     * Get ShowCategoryName
330
     *
331
     * @return boolean
332
     */
333 46
    public function hasShowCategoryName()
334
    {
335 46
        return $this->showCategoryName;
336
    }
337
338
    /**
339
     * Set ShowCategoryName
340
     *
341
     * @param  boolean                          $value
342
     * @return \PhpOffice\PhpPresentation\Shape\Chart\Series
343
     */
344 2
    public function setShowCategoryName($value)
345
    {
346 2
        $this->showCategoryName = $value;
347
348 2
        return $this;
349
    }
350
351
    /**
352
     * Get ShowValue
353
     *
354
     * @return boolean
355
     */
356 8
    public function hasShowLegendKey()
357
    {
358 8
        return $this->showLegendKey;
359
    }
360
361
    /**
362
     * Set ShowValue
363
     *
364
     * @param  boolean                          $value
365
     * @return \PhpOffice\PhpPresentation\Shape\Chart\Series
366
     */
367 3
    public function setShowLegendKey($value)
368
    {
369 3
        $this->showLegendKey = (bool)$value;
370
371 3
        return $this;
372
    }
373
374
    /**
375
     * Get ShowValue
376
     *
377
     * @return boolean
378
     */
379 46
    public function hasShowValue()
380
    {
381 46
        return $this->showValue;
382
    }
383
384
    /**
385
     * Set ShowValue
386
     *
387
     * @param  boolean $value
388
     * @return \PhpOffice\PhpPresentation\Shape\Chart\Series
389
     */
390 2
    public function setShowValue($value)
391
    {
392 2
        $this->showValue = $value;
393
394 2
        return $this;
395
    }
396
397
    /**
398
     * Get ShowPercentage
399
     *
400
     * @return boolean
401
     */
402 46
    public function hasShowPercentage()
403
    {
404 46
        return $this->showPercentage;
405
    }
406
407
    /**
408
     * Set ShowPercentage
409
     *
410
     * @param  boolean                          $value
411
     * @return \PhpOffice\PhpPresentation\Shape\Chart\Series
412
     */
413 2
    public function setShowPercentage($value)
414
    {
415 2
        $this->showPercentage = $value;
416
417 2
        return $this;
418
    }
419
420
    /**
421
     * Get ShowLeaderLines
422
     *
423
     * @return boolean
424
     */
425 24
    public function hasShowLeaderLines()
426
    {
427 24
        return $this->showLeaderLines;
428
    }
429
430
    /**
431
     * Set ShowLeaderLines
432
     *
433
     * @param  boolean                          $value
434
     * @return \PhpOffice\PhpPresentation\Shape\Chart\Series
435
     */
436 1
    public function setShowLeaderLines($value)
437
    {
438 1
        $this->showLeaderLines = $value;
439
440 1
        return $this;
441
    }
442
443
    /**
444
     * Get font
445
     *
446
     * @return \PhpOffice\PhpPresentation\Style\Font
447
     */
448 47
    public function getFont()
449
    {
450 47
        return $this->font;
451
    }
452
453
    /**
454
     * Set font
455
     *
456
     * @param  \PhpOffice\PhpPresentation\Style\Font               $pFont Font
457
     * @throws \Exception
458
     * @return \PhpOffice\PhpPresentation\Shape\RichText\Paragraph
459
     */
460 1
    public function setFont(Font $pFont = null)
461
    {
462 1
        $this->font = $pFont;
463
464 1
        return $this;
465
    }
466
467
    /**
468
     * Get label position
469
     *
470
     * @return string
471
     */
472 8
    public function getLabelPosition()
473
    {
474 8
        return $this->labelPosition;
475
    }
476
477
    /**
478
     * Set label position
479
     *
480
     * @param  string                           $value
481
     * @return \PhpOffice\PhpPresentation\Shape\Chart\Series
482
     */
483 1
    public function setLabelPosition($value)
484
    {
485 1
        $this->labelPosition = $value;
486
487 1
        return $this;
488
    }
489
490
    /**
491
     * @return Marker
492
     */
493 23
    public function getMarker()
494
    {
495 23
        return $this->marker;
496
    }
497
498
    /**
499
     * @param Marker $marker
500
     * @return \PhpOffice\PhpPresentation\Shape\Chart\Series
501
     */
502 1
    public function setMarker(Marker $marker)
503
    {
504 1
        $this->marker = $marker;
505 1
        return $this;
506
    }
507
508
    /**
509
     * @return Outline
510
     */
511 24
    public function getOutline()
512
    {
513 24
        return $this->outline;
514
    }
515
516
    /**
517
     * @param Outline $outline
518
     * @return \PhpOffice\PhpPresentation\Shape\Chart\Series
519
     */
520 6
    public function setOutline(Outline $outline)
521
    {
522 6
        $this->outline = $outline;
523 6
        return $this;
524
    }
525
526
    /**
527
     * Get hash code
528
     *
529
     * @return string Hash code
530
     */
531 53
    public function getHashCode()
532
    {
533 53
        return md5((is_null($this->fill) ? 'null' : $this->fill->getHashCode()) . (is_null($this->font) ? 'null' : $this->font->getHashCode()) . var_export($this->values, true) . var_export($this, true) . __CLASS__);
534
    }
535
536
    /**
537
     * Get hash index
538
     *
539
     * Note that this index may vary during script execution! Only reliable moment is
540
     * while doing a write of a workbook and when changes are not allowed.
541
     *
542
     * @return string Hash index
543
     */
544 2
    public function getHashIndex()
545
    {
546 2
        return $this->hashIndex;
547
    }
548
549
    /**
550
     * Set hash index
551
     *
552
     * Note that this index may vary during script execution! Only reliable moment is
553
     * while doing a write of a workbook and when changes are not allowed.
554
     *
555
     * @param string $value Hash index
556
     * @return \PhpOffice\PhpPresentation\Shape\Chart\Series
557
     */
558 1
    public function setHashIndex($value)
559
    {
560 1
        $this->hashIndex = $value;
561 1
        return $this;
562
    }
563
564
    /**
565
     * @return mixed
566
     * @link http://php.net/manual/en/language.oop5.cloning.php
567
     */
568 2
    public function __clone()
569
    {
570 2
        $this->font = clone $this->font;
571 2
        $this->marker = clone $this->marker;
572 2
        if (is_object($this->outline)) {
573 1
            $this->outline = clone $this->outline;
574 1
        }
575 2
    }
576
}
577