Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
71 / 71
100.00% covered (success)
100.00%
40 / 40
CRAP
100.00% covered (success)
100.00%
1 / 1
Axis
100.00% covered (success)
100.00%
71 / 71
100.00% covered (success)
100.00%
40 / 40
45
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 getTitle
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setTitle
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getFont
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setTickLabelFont
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getTickLabelFont
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setFont
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getFormatCode
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setFormatCode
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getMinBounds
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setMinBounds
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 getMaxBounds
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setMaxBounds
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 getCrossesAt
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setCrossesAt
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 isReversedOrder
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setIsReversedOrder
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getMajorGridlines
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setMajorGridlines
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getMinorGridlines
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setMinorGridlines
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getMinorTickMark
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setMinorTickMark
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getMajorTickMark
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setMajorTickMark
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getMinorUnit
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setMinorUnit
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getMajorUnit
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setMajorUnit
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getOutline
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setOutline
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getTitleRotation
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setTitleRotation
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
3
 getHashCode
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getHashIndex
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setHashIndex
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 isVisible
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setIsVisible
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getTickLabelPosition
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setTickLabelPosition
100.00% covered (success)
100.00%
7 / 7
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;
21
22use PhpOffice\PhpPresentation\ComparableInterface;
23use PhpOffice\PhpPresentation\Style\Font;
24use PhpOffice\PhpPresentation\Style\Outline;
25
26class Axis implements ComparableInterface
27{
28    public const AXIS_X = 'x';
29    public const AXIS_Y = 'y';
30
31    public const TICK_MARK_NONE = 'none';
32    public const TICK_MARK_CROSS = 'cross';
33    public const TICK_MARK_INSIDE = 'in';
34    public const TICK_MARK_OUTSIDE = 'out';
35
36    public const TICK_LABEL_POSITION_NEXT_TO = 'nextTo';
37    public const TICK_LABEL_POSITION_HIGH = 'high';
38    public const TICK_LABEL_POSITION_LOW = 'low';
39
40    public const CROSSES_AUTO = 'autoZero';
41    public const CROSSES_MIN = 'min';
42    public const CROSSES_MAX = 'max';
43
44    public const DEFAULT_FORMAT_CODE = 'general';
45
46    /**
47     * Title.
48     *
49     * @var string
50     */
51    private $title = 'Axis Title';
52
53    /**
54     * @var int
55     */
56    private $titleRotation = 0;
57
58    /**
59     * Format code.
60     *
61     * @var string
62     */
63    private $formatCode = self::DEFAULT_FORMAT_CODE;
64
65    /**
66     * Font.
67     *
68     * @var Font
69     */
70    private $font;
71
72    /**
73     * Tick lable font.
74     *
75     * @var Font
76     */
77    protected $tickLabelFont;
78
79    /**
80     * @var null|Gridlines
81     */
82    protected $majorGridlines;
83
84    /**
85     * @var null|Gridlines
86     */
87    protected $minorGridlines;
88
89    /**
90     * @var int
91     */
92    protected $minBounds;
93
94    /**
95     * @var int
96     */
97    protected $maxBounds;
98
99    /**
100     * @var string
101     */
102    protected $crossesAt = self::CROSSES_AUTO;
103
104    /**
105     * @var bool
106     */
107    protected $isReversedOrder = false;
108
109    /**
110     * @var string
111     */
112    protected $minorTickMark = self::TICK_MARK_NONE;
113
114    /**
115     * @var string
116     */
117    protected $majorTickMark = self::TICK_MARK_NONE;
118
119    /**
120     * @var string
121     */
122    protected $tickLabelPosition = self::TICK_LABEL_POSITION_NEXT_TO;
123
124    /**
125     * @var float
126     */
127    protected $minorUnit;
128
129    /**
130     * @var float
131     */
132    protected $majorUnit;
133
134    /**
135     * @var Outline
136     */
137    protected $outline;
138
139    /**
140     * @var bool
141     */
142    protected $isVisible = true;
143
144    /**
145     * Create a new \PhpOffice\PhpPresentation\Shape\Chart\Axis instance.
146     *
147     * @param string $title Title
148     */
149    public function __construct(string $title = 'Axis Title')
150    {
151        $this->title = $title;
152        $this->outline = new Outline();
153        $this->font = new Font();
154        $this->tickLabelFont = new Font();
155    }
156
157    /**
158     * Get Title.
159     */
160    public function getTitle(): string
161    {
162        return $this->title;
163    }
164
165    /**
166     * Set Title.
167     */
168    public function setTitle(string $value = 'Axis Title'): self
169    {
170        $this->title = $value;
171
172        return $this;
173    }
174
175    /**
176     * Get font.
177     */
178    public function getFont(): ?Font
179    {
180        return $this->font;
181    }
182
183    /**
184     * Set tick label font.
185     */
186    public function setTickLabelFont(?Font $font = null): self
187    {
188        $this->tickLabelFont = $font;
189
190        return $this;
191    }
192
193    /**
194     * Get tick label font.
195     */
196    public function getTickLabelFont(): ?Font
197    {
198        return $this->tickLabelFont;
199    }
200
201    /**
202     * Set font.
203     */
204    public function setFont(?Font $font = null): self
205    {
206        $this->font = $font;
207
208        return $this;
209    }
210
211    /**
212     * Get Format Code.
213     */
214    public function getFormatCode(): string
215    {
216        return $this->formatCode;
217    }
218
219    /**
220     * Set Format Code.
221     */
222    public function setFormatCode(string $value = self::DEFAULT_FORMAT_CODE): self
223    {
224        $this->formatCode = $value;
225
226        return $this;
227    }
228
229    public function getMinBounds(): ?int
230    {
231        return $this->minBounds;
232    }
233
234    public function setMinBounds(?int $minBounds = null): self
235    {
236        $this->minBounds = null === $minBounds ? null : $minBounds;
237
238        return $this;
239    }
240
241    public function getMaxBounds(): ?int
242    {
243        return $this->maxBounds;
244    }
245
246    public function setMaxBounds(?int $maxBounds = null): self
247    {
248        $this->maxBounds = null === $maxBounds ? null : $maxBounds;
249
250        return $this;
251    }
252
253    public function getCrossesAt(): string
254    {
255        return $this->crossesAt;
256    }
257
258    public function setCrossesAt(string $value = self::CROSSES_AUTO): self
259    {
260        $this->crossesAt = $value;
261
262        return $this;
263    }
264
265    public function isReversedOrder(): bool
266    {
267        return $this->isReversedOrder;
268    }
269
270    public function setIsReversedOrder(bool $value = false): self
271    {
272        $this->isReversedOrder = $value;
273
274        return $this;
275    }
276
277    public function getMajorGridlines(): ?Gridlines
278    {
279        return $this->majorGridlines;
280    }
281
282    public function setMajorGridlines(Gridlines $majorGridlines): self
283    {
284        $this->majorGridlines = $majorGridlines;
285
286        return $this;
287    }
288
289    public function getMinorGridlines(): ?Gridlines
290    {
291        return $this->minorGridlines;
292    }
293
294    public function setMinorGridlines(Gridlines $minorGridlines): self
295    {
296        $this->minorGridlines = $minorGridlines;
297
298        return $this;
299    }
300
301    public function getMinorTickMark(): string
302    {
303        return $this->minorTickMark;
304    }
305
306    public function setMinorTickMark(string $tickMark = self::TICK_MARK_NONE): self
307    {
308        $this->minorTickMark = $tickMark;
309
310        return $this;
311    }
312
313    public function getMajorTickMark(): string
314    {
315        return $this->majorTickMark;
316    }
317
318    public function setMajorTickMark(string $tickMark = self::TICK_MARK_NONE): self
319    {
320        $this->majorTickMark = $tickMark;
321
322        return $this;
323    }
324
325    public function getMinorUnit(): ?float
326    {
327        return $this->minorUnit;
328    }
329
330    /**
331     * @param null|float $unit
332     */
333    public function setMinorUnit($unit = null): self
334    {
335        $this->minorUnit = $unit;
336
337        return $this;
338    }
339
340    public function getMajorUnit(): ?float
341    {
342        return $this->majorUnit;
343    }
344
345    public function setMajorUnit(?float $unit = null): self
346    {
347        $this->majorUnit = $unit;
348
349        return $this;
350    }
351
352    public function getOutline(): Outline
353    {
354        return $this->outline;
355    }
356
357    public function setOutline(Outline $outline): self
358    {
359        $this->outline = $outline;
360
361        return $this;
362    }
363
364    public function getTitleRotation(): int
365    {
366        return $this->titleRotation;
367    }
368
369    public function setTitleRotation(int $titleRotation): self
370    {
371        if ($titleRotation < 0) {
372            $titleRotation = 0;
373        }
374        if ($titleRotation > 360) {
375            $titleRotation = 360;
376        }
377        $this->titleRotation = $titleRotation;
378
379        return $this;
380    }
381
382    /**
383     * Get hash code.
384     *
385     * @return string Hash code
386     */
387    public function getHashCode(): string
388    {
389        return md5($this->title . $this->formatCode . __CLASS__);
390    }
391
392    /**
393     * Hash index.
394     *
395     * @var int
396     */
397    private $hashIndex;
398
399    /**
400     * Get hash index.
401     *
402     * Note that this index may vary during script execution! Only reliable moment is
403     * while doing a write of a workbook and when changes are not allowed.
404     *
405     * @return null|int Hash index
406     */
407    public function getHashIndex(): ?int
408    {
409        return $this->hashIndex;
410    }
411
412    /**
413     * Set hash index.
414     *
415     * Note that this index may vary during script execution! Only reliable moment is
416     * while doing a write of a workbook and when changes are not allowed.
417     *
418     * @param int $value Hash index
419     *
420     * @return self
421     */
422    public function setHashIndex(int $value)
423    {
424        $this->hashIndex = $value;
425
426        return $this;
427    }
428
429    /**
430     * Axis is hidden ?
431     */
432    public function isVisible(): bool
433    {
434        return $this->isVisible;
435    }
436
437    /**
438     * Hide an axis.
439     *
440     * @param bool $value delete
441     */
442    public function setIsVisible(bool $value): self
443    {
444        $this->isVisible = $value;
445
446        return $this;
447    }
448
449    public function getTickLabelPosition(): string
450    {
451        return $this->tickLabelPosition;
452    }
453
454    public function setTickLabelPosition(string $value = self::TICK_LABEL_POSITION_NEXT_TO): self
455    {
456        if (in_array($value, [
457            self::TICK_LABEL_POSITION_HIGH,
458            self::TICK_LABEL_POSITION_LOW,
459            self::TICK_LABEL_POSITION_NEXT_TO,
460        ])) {
461            $this->tickLabelPosition = $value;
462        }
463
464        return $this;
465    }
466}