Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
27 / 27
100.00% covered (success)
100.00%
9 / 9
CRAP
100.00% covered (success)
100.00%
1 / 1
AbstractTypeBar
100.00% covered (success)
100.00%
27 / 27
100.00% covered (success)
100.00%
9 / 9
16
100.00% covered (success)
100.00%
1 / 1
 setBarDirection
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getBarDirection
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setBarGrouping
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
3
 getBarGrouping
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getGapWidthPercent
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setGapWidthPercent
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
3
 getOverlapWidthPercent
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setOverlapWidthPercent
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
3
 getHashCode
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
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 * @see        https://github.com/PHPOffice/PHPPresentation
14 *
15 * @license     http://www.gnu.org/licenses/lgpl.txt LGPL version 3
16 */
17
18declare(strict_types=1);
19
20namespace PhpOffice\PhpPresentation\Shape\Chart\Type;
21
22/**
23 * \PhpOffice\PhpPresentation\Shape\Chart\Type\Bar.
24 */
25abstract class AbstractTypeBar extends AbstractType
26{
27    /** Orientation of bars */
28    public const DIRECTION_VERTICAL = 'col';
29    public const DIRECTION_HORIZONTAL = 'bar';
30
31    /** Grouping of bars */
32    public const GROUPING_CLUSTERED = 'clustered'; //Chart series are drawn next to each other along the category axis.
33    public const GROUPING_STACKED = 'stacked'; //Chart series are drawn next to each other on the value axis.
34    public const GROUPING_PERCENTSTACKED = 'percentStacked'; //Chart series are drawn next to each other along the value axis and scaled to total 100%
35
36    /**
37     * Orientation of bars.
38     *
39     * @var string
40     */
41    protected $barDirection = self::DIRECTION_VERTICAL;
42
43    /**
44     * Grouping of bars.
45     *
46     * @var string
47     */
48    protected $barGrouping = self::GROUPING_CLUSTERED;
49
50    /**
51     * Space between bar or columns clusters.
52     *
53     * @var int
54     */
55    protected $gapWidthPercent = 150;
56
57    /**
58     * Overlap within bar or columns clusters. Value between 100 and -100 percent.
59     * For stacked bar charts, the default overlap will be 100, for grouped bar charts 0.
60     *
61     * @var int
62     */
63    protected $overlapWidthPercent = 0;
64
65    /**
66     * Set bar orientation.
67     *
68     * @param string $value
69     *
70     * @return AbstractTypeBar
71     */
72    public function setBarDirection($value = self::DIRECTION_VERTICAL)
73    {
74        $this->barDirection = $value;
75
76        return $this;
77    }
78
79    /**
80     * Get orientation.
81     *
82     * @return string
83     */
84    public function getBarDirection()
85    {
86        return $this->barDirection;
87    }
88
89    /**
90     * Set bar grouping (stack or expanded style bar).
91     *
92     * @param string $value
93     *
94     * @return AbstractTypeBar
95     */
96    public function setBarGrouping($value = self::GROUPING_CLUSTERED)
97    {
98        $this->barGrouping = $value;
99        $this->overlapWidthPercent = 0;
100
101        if ($value === self::GROUPING_STACKED || $value === self::GROUPING_PERCENTSTACKED) {
102            $this->overlapWidthPercent = 100;
103        }
104
105        return $this;
106    }
107
108    /**
109     * Get grouping  (stack or expanded style bar).
110     *
111     * @return string
112     */
113    public function getBarGrouping()
114    {
115        return $this->barGrouping;
116    }
117
118    /**
119     * @return int
120     */
121    public function getGapWidthPercent()
122    {
123        return $this->gapWidthPercent;
124    }
125
126    /**
127     * @param int $gapWidthPercent
128     *
129     * @return $this
130     */
131    public function setGapWidthPercent($gapWidthPercent)
132    {
133        if ($gapWidthPercent < 0) {
134            $gapWidthPercent = 0;
135        }
136        if ($gapWidthPercent > 500) {
137            $gapWidthPercent = 500;
138        }
139        $this->gapWidthPercent = $gapWidthPercent;
140
141        return $this;
142    }
143
144    public function getOverlapWidthPercent(): int
145    {
146        return $this->overlapWidthPercent;
147    }
148
149    /**
150     * @param int $value overlap width percentage
151     */
152    public function setOverlapWidthPercent(int $value): self
153    {
154        if ($value < -100) {
155            $value = -100;
156        }
157        if ($value > 100) {
158            $value = 100;
159        }
160        $this->overlapWidthPercent = $value;
161
162        return $this;
163    }
164
165    /**
166     * Get hash code.
167     *
168     * @return string Hash code
169     */
170    public function getHashCode(): string
171    {
172        $hash = '';
173        foreach ($this->getSeries() as $series) {
174            $hash .= $series->getHashCode();
175        }
176
177        return $hash;
178    }
179}