Completed
Pull Request — develop (#591)
by
unknown
06:44
created

Series::getLabelColor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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