Completed
Pull Request — develop (#591)
by
unknown
06:26
created

Axis::getTickLabelPos()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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