Completed
Push — master ( 1fcc84...3deaa8 )
by Franck
12s
created

AbstractTypeBar::setGapWidthPercent()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 7
cts 7
cp 1
rs 9.9
c 0
b 0
f 0
cc 3
nc 4
nop 1
crap 3
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\Type;
19
20
/**
21
 * \PhpOffice\PhpPresentation\Shape\Chart\Type\Bar
22
 */
23
class AbstractTypeBar extends AbstractType
24
{
25
    /** Orientation of bars */
26
    const DIRECTION_VERTICAL = 'col';
27
    const DIRECTION_HORIZONTAL = 'bar';
28
29
    /** Grouping of bars */
30
    const GROUPING_CLUSTERED = 'clustered'; //Chart series are drawn next to each other along the category axis.
31
    const GROUPING_STACKED = 'stacked'; //Chart series are drawn next to each other on the value axis.
32
    const GROUPING_PERCENTSTACKED = 'percentStacked'; //Chart series are drawn next to each other along the value axis and scaled to total 100%
33
34
35
    /**
36
     * Orientation of bars
37
     *
38
     * @var string
39
     */
40
    protected $barDirection = self::DIRECTION_VERTICAL;
41
42
43
    /**
44
     * Grouping of bars
45
     *
46
     * @var string
47
     */
48
    protected $barGrouping = self::GROUPING_CLUSTERED;
49
50
51
    /**
52
     * Space between bar or columns clusters
53
     *
54
     * @var int
55
     */
56
    protected $gapWidthPercent = 150;
57
58
59
    /**
60
     * Set bar orientation
61
     *
62
     * @param string                          $value
63
     * @return \PhpOffice\PhpPresentation\Shape\Chart\Type\Bar
64
     */
65 5
    public function setBarDirection($value = self::DIRECTION_VERTICAL)
66
    {
67 5
        $this->barDirection = $value;
68 5
        return $this;
69
    }
70
71
    /**
72
     * Get orientation
73
     *
74
     * @return string
75
     */
76 17
    public function getBarDirection()
77
    {
78 17
        return $this->barDirection;
79
    }
80
81
    /**
82
     * Set bar grouping (stack or expanded style bar)
83
     *
84
     * @param string                          $value
85
     * @return \PhpOffice\PhpPresentation\Shape\Chart\Type\Bar
86
     */
87 4
    public function setBarGrouping($value = self::GROUPING_CLUSTERED)
88
    {
89 4
        $this->barGrouping = $value;
90 4
        return $this;
91
    }
92
93
    /**
94
     * Get grouping  (stack or expanded style bar)
95
     *
96
     * @return string
97
     */
98 17
    public function getBarGrouping()
99
    {
100 17
        return $this->barGrouping;
101
    }
102
103
    /**
104
     * @return int
105
     */
106 9
    public function getGapWidthPercent()
107
    {
108 9
        return $this->gapWidthPercent;
109
    }
110
111
    /**
112
     * @param int $gapWidthPercent
113
     * @return $this
114
     */
115 4
    public function setGapWidthPercent($gapWidthPercent)
116
    {
117 4
        if ($gapWidthPercent < 0) {
118 2
            $gapWidthPercent = 0;
119
        }
120 4
        if ($gapWidthPercent > 500) {
121 2
            $gapWidthPercent = 500;
122
        }
123 4
        $this->gapWidthPercent = $gapWidthPercent;
124 4
        return $this;
125
    }
126
    
127
    /**
128
     * Get hash code
129
     *
130
     * @return string Hash code
131
     */
132 17
    public function getHashCode()
133
    {
134 17
        $hash = '';
135 17
        foreach ($this->getSeries() as $series) {
136 16
            $hash .= $series->getHashCode();
137
        }
138 17
        return $hash;
139
    }
140
}
141