Completed
Pull Request — develop (#410)
by Franck
33:12 queued 17:43
created

Axis::setMajorTickMark()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 1
cts 1
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
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 81
    /**
114
     * Create a new \PhpOffice\PhpPresentation\Shape\Chart\Axis instance
115 81
     *
116 81
     * @param string $title Title
117 81
     */
118 81
    public function __construct($title = 'Axis Title')
119
    {
120
        $this->title = $title;
121
        $this->outline = new Outline();
122
        $this->font  = new Font();
123
    }
124
125 30
    /**
126
     * Get Title
127 30
     *
128
     * @return string
129
     */
130
    public function getTitle()
131
    {
132
        return $this->title;
133
    }
134
135
    /**
136 1
     * Set Title
137
     *
138 1
     * @param  string                         $value
139
     * @return $this
140 1
     */
141
    public function setTitle($value = 'Axis Title')
142
    {
143
        $this->title = $value;
144
145
        return $this;
146
    }
147
148 54
    /**
149
     * Get font
150 54
     *
151
     * @return \PhpOffice\PhpPresentation\Style\Font
152
     */
153
    public function getFont()
154
    {
155
        return $this->font;
156
    }
157
158
    /**
159
     * Set font
160 1
     *
161
     * @param  \PhpOffice\PhpPresentation\Style\Font               $pFont Font
162 1
     * @throws \Exception
163 1
     * @return \PhpOffice\PhpPresentation\Shape\Chart\Axis
164
     */
165
    public function setFont(Font $pFont = null)
166
    {
167
        $this->font = $pFont;
168
        return $this;
169
    }
170
171 29
    /**
172
     * Get Format Code
173 29
     *
174
     * @return string
175
     */
176
    public function getFormatCode()
177
    {
178
        return $this->formatCode;
179
    }
180
181
    /**
182 1
     * Set Format Code
183
     *
184 1
     * @param  string                         $value
185
     * @return $this
186 1
     */
187
    public function setFormatCode($value = '')
188
    {
189
        $this->formatCode = $value;
190
191
        return $this;
192 53
    }
193
194 53
    /**
195
     * @return int|null
196
     */
197
    public function getMinBounds()
198
    {
199
        return $this->minBounds;
200
    }
201 3
202
    /**
203 3
     * @param int|null $minBounds
204 3
     * @return Axis
205
     */
206
    public function setMinBounds($minBounds = null)
207
    {
208
        $this->minBounds = is_null($minBounds) ? null : (int)$minBounds;
209
        return $this;
210 53
    }
211
212 53
    /**
213
     * @return int|null
214
     */
215
    public function getMaxBounds()
216
    {
217
        return $this->maxBounds;
218
    }
219 3
220
    /**
221 3
     * @param int|null $maxBounds
222 3
     * @return Axis
223
     */
224
    public function setMaxBounds($maxBounds = null)
225
    {
226
        $this->maxBounds = is_null($maxBounds) ? null : (int)$maxBounds;
227
        return $this;
228 54
    }
229
230 54
    /**
231
     * @return Gridlines
232
     */
233
    public function getMajorGridlines()
234
    {
235
        return $this->majorGridlines;
236
    }
237 3
238
    /**
239 3
     * @param Gridlines $majorGridlines
240 3
     * @return Axis
241
     */
242
    public function setMajorGridlines(Gridlines $majorGridlines)
243
    {
244
        $this->majorGridlines = $majorGridlines;
245
        return $this;
246 54
    }
247
248 54
    /**
249
     * @return Gridlines
250
     */
251
    public function getMinorGridlines()
252
    {
253
        return $this->minorGridlines;
254
    }
255 3
256
    /**
257 3
     * @param Gridlines $minorGridlines
258 3
     * @return Axis
259
     */
260
    public function setMinorGridlines(Gridlines $minorGridlines)
261
    {
262
        $this->minorGridlines = $minorGridlines;
263
        return $this;
264 29
    }
265
266 29
    /**
267
     * @return string
268
     */
269
    public function getMinorTickMark()
270
    {
271
        return $this->minorTickMark;
272
    }
273 2
274
    /**
275 2
     * @param string $pTickMark
276 2
     * @return Axis
277
     */
278
    public function setMinorTickMark($pTickMark = self::TICK_MARK_NONE)
279
    {
280
        $this->minorTickMark = $pTickMark;
281
        return $this;
282 29
    }
283
284 29
    /**
285
     * @return string
286
     */
287
    public function getMajorTickMark()
288
    {
289
        return $this->majorTickMark;
290
    }
291 2
292
    /**
293 2
     * @param string $pTickMark
294 2
     * @return Axis
295
     */
296
    public function setMajorTickMark($pTickMark = self::TICK_MARK_NONE)
297
    {
298
        $this->majorTickMark = $pTickMark;
299
        return $this;
300 29
    }
301
302 29
    /**
303
     * @return float
304
     */
305
    public function getMinorUnit()
306
    {
307
        return $this->minorUnit;
308
    }
309 2
310
    /**
311 2
     * @param float $pUnit
312 2
     * @return Axis
313
     */
314
    public function setMinorUnit($pUnit = null)
315
    {
316
        $this->minorUnit = $pUnit;
317
        return $this;
318 29
    }
319
320 29
    /**
321
     * @return float
322
     */
323
    public function getMajorUnit()
324
    {
325
        return $this->majorUnit;
326
    }
327 2
328
    /**
329 2
     * @param float $pUnit
330 2
     * @return Axis
331
     */
332
    public function setMajorUnit($pUnit = null)
333
    {
334
        $this->majorUnit = $pUnit;
335
        return $this;
336 28
    }
337
338 28
    /**
339
     * @return Outline
340
     */
341
    public function getOutline()
342
    {
343
        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 60
    /**
357
     * @return int
358 60
     */
359
    public function getLabelRotation()
360
    {
361
        return $this->labelRotation;
362
    }
363
364
    /**
365
     * @param int $labelRotation
366
     * @return $this
367
     */
368
    public function setLabelRotation($labelRotation)
369
    {
370
        if ($labelRotation < 0) {
371
            $labelRotation = 0;
372
        }
373
        if ($labelRotation > 360) {
374
            $labelRotation = 360;
375
        }
376 1
        $this->labelRotation = $labelRotation;
377
        return $this;
378 1
    }
379
380
    /**
381
     * Get hash code
382
     *
383
     * @return string Hash code
384
     */
385
    public function getHashCode()
386
    {
387
        return md5($this->title . $this->formatCode . __CLASS__);
388
    }
389
390 1
    /**
391
     * Hash index
392 1
     *
393 1
     * @var string
394
     */
395
    private $hashIndex;
396
397
    /**
398
     * Get hash index
399
     *
400 29
     * 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 29
     *
403
     * @return string Hash index
404
     */
405
    public function getHashIndex()
406
    {
407
        return $this->hashIndex;
408
    }
409
410
    /**
411 3
     * Set hash index
412
     *
413 3
     * Note that this index may vary during script execution! Only reliable moment is
414 3
     * 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
    public function setHashIndex($value)
420
    {
421
        $this->hashIndex = $value;
422
        return $this;
423
    }
424
425
    /**
426
     * Axis is hidden ?
427
     * @return boolean
428
     */
429
    public function isVisible()
430
    {
431
        return $this->isVisible;
432
    }
433
434
    /**
435
     * Hide an axis
436
     *
437
     * @param boolean $value delete
438
     * @return $this
439
     */
440
    public function setIsVisible($value)
441
    {
442
        $this->isVisible = (bool)$value;
443
        return $this;
444
    }
445
}
446