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

Series::setLabelColor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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