Completed
Pull Request — develop (#410)
by Franck
06:19
created

Axis::setMinBounds()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

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