Completed
Push — master ( bc0154...042bac )
by Mark
32s queued 28s
created

Axis::getLineProperty()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheet\Chart;
4
5
/**
6
 * Created by PhpStorm.
7
 * User: Wiktor Trzonkowski
8
 * Date: 6/17/14
9
 * Time: 12:11 PM.
10
 */
11
class Axis extends Properties
12
{
13
    const AXIS_TYPE_CATEGORY = 'catAx';
14
    const AXIS_TYPE_DATE = 'dateAx';
15
    const AXIS_TYPE_VALUE = 'valAx';
16
17
    const TIME_UNIT_DAYS = 'days';
18
    const TIME_UNIT_MONTHS = 'months';
19
    const TIME_UNIT_YEARS = 'years';
20
21 82
    public function __construct()
22
    {
23 82
        parent::__construct();
24 82
        $this->fillColor = new ChartColor();
25
    }
26
27
    /**
28
     * Chart Major Gridlines as.
29
     *
30
     * @var ?GridLines
31
     */
32
    private $majorGridlines;
33
34
    /**
35
     * Chart Minor Gridlines as.
36
     *
37
     * @var ?GridLines
38
     */
39
    private $minorGridlines;
40
41
    /**
42
     * Axis Number.
43
     *
44
     * @var mixed[]
45
     */
46
    private $axisNumber = [
47
        'format' => self::FORMAT_CODE_GENERAL,
48
        'source_linked' => 1,
49
        'numeric' => null,
50
    ];
51
52
    /** @var string */
53
    private $axisType = '';
54
55
    /**
56
     * Axis Options.
57
     *
58
     * @var mixed[]
59
     */
60
    private $axisOptions = [
61
        'minimum' => null,
62
        'maximum' => null,
63
        'major_unit' => null,
64
        'minor_unit' => null,
65
        'orientation' => self::ORIENTATION_NORMAL,
66
        'minor_tick_mark' => self::TICK_MARK_NONE,
67
        'major_tick_mark' => self::TICK_MARK_NONE,
68
        'axis_labels' => self::AXIS_LABELS_NEXT_TO,
69
        'horizontal_crosses' => self::HORIZONTAL_CROSSES_AUTOZERO,
70
        'horizontal_crosses_value' => null,
71
        'textRotation' => null,
72
        'hidden' => null,
73
        'majorTimeUnit' => self::TIME_UNIT_YEARS,
74
        'minorTimeUnit' => self::TIME_UNIT_MONTHS,
75
        'baseTimeUnit' => self::TIME_UNIT_DAYS,
76
    ];
77
78
    /**
79
     * Fill Properties.
80
     *
81
     * @var ChartColor
82
     */
83
    private $fillColor;
84
85
    private const NUMERIC_FORMAT = [
86
        Properties::FORMAT_CODE_NUMBER,
87
        Properties::FORMAT_CODE_DATE,
88
        Properties::FORMAT_CODE_DATE_ISO8601,
89
    ];
90
91
    /**
92
     * Get Series Data Type.
93
     *
94
     * @param mixed $format_code
95
     */
96 50
    public function setAxisNumberProperties($format_code, ?bool $numeric = null, int $sourceLinked = 0): void
97
    {
98 50
        $format = (string) $format_code;
99 50
        $this->axisNumber['format'] = $format;
100 50
        $this->axisNumber['source_linked'] = $sourceLinked;
101 50
        if (is_bool($numeric)) {
102 7
            $this->axisNumber['numeric'] = $numeric;
103 46
        } elseif (in_array($format, self::NUMERIC_FORMAT, true)) {
104 6
            $this->axisNumber['numeric'] = true;
105
        }
106
    }
107
108
    /**
109
     * Get Axis Number Format Data Type.
110
     *
111
     * @return string
112
     */
113 61
    public function getAxisNumberFormat()
114
    {
115 61
        return $this->axisNumber['format'];
116
    }
117
118
    /**
119
     * Get Axis Number Source Linked.
120
     *
121
     * @return string
122
     */
123 61
    public function getAxisNumberSourceLinked()
124
    {
125 61
        return (string) $this->axisNumber['source_linked'];
126
    }
127
128 38
    public function getAxisIsNumericFormat(): bool
129
    {
130 38
        return $this->axisType === self::AXIS_TYPE_DATE || (bool) $this->axisNumber['numeric'];
131
    }
132
133 47
    public function setAxisOption(string $key, ?string $value): void
134
    {
135 47
        if ($value !== null && $value !== '') {
136 47
            $this->axisOptions[$key] = $value;
137
        }
138
    }
139
140
    /**
141
     * Set Axis Options Properties.
142
     */
143 2
    public function setAxisOptionsProperties(
144
        string $axisLabels,
145
        ?string $horizontalCrossesValue = null,
146
        ?string $horizontalCrosses = null,
147
        ?string $axisOrientation = null,
148
        ?string $majorTmt = null,
149
        ?string $minorTmt = null,
150
        ?string $minimum = null,
151
        ?string $maximum = null,
152
        ?string $majorUnit = null,
153
        ?string $minorUnit = null,
154
        ?string $textRotation = null,
155
        ?string $hidden = null,
156
        ?string $baseTimeUnit = null,
157
        ?string $majorTimeUnit = null,
158
        ?string $minorTimeUnit = null
159
    ): void {
160 2
        $this->axisOptions['axis_labels'] = $axisLabels;
161 2
        $this->setAxisOption('horizontal_crosses_value', $horizontalCrossesValue);
162 2
        $this->setAxisOption('horizontal_crosses', $horizontalCrosses);
163 2
        $this->setAxisOption('orientation', $axisOrientation);
164 2
        $this->setAxisOption('major_tick_mark', $majorTmt);
165 2
        $this->setAxisOption('minor_tick_mark', $minorTmt);
166 2
        $this->setAxisOption('minimum', $minimum);
167 2
        $this->setAxisOption('maximum', $maximum);
168 2
        $this->setAxisOption('major_unit', $majorUnit);
169 2
        $this->setAxisOption('minor_unit', $minorUnit);
170 2
        $this->setAxisOption('textRotation', $textRotation);
171 2
        $this->setAxisOption('hidden', $hidden);
172 2
        $this->setAxisOption('baseTimeUnit', $baseTimeUnit);
173 2
        $this->setAxisOption('majorTimeUnit', $majorTimeUnit);
174 2
        $this->setAxisOption('minorTimeUnit', $minorTimeUnit);
175
    }
176
177
    /**
178
     * Get Axis Options Property.
179
     *
180
     * @param string $property
181
     *
182
     * @return ?string
183
     */
184 61
    public function getAxisOptionsProperty($property)
185
    {
186 61
        return $this->axisOptions[$property];
187
    }
188
189
    /**
190
     * Set Axis Orientation Property.
191
     *
192
     * @param string $orientation
193
     */
194 1
    public function setAxisOrientation($orientation): void
195
    {
196 1
        $this->axisOptions['orientation'] = (string) $orientation;
197
    }
198
199 60
    public function getAxisType(): string
200
    {
201 60
        return $this->axisType;
202
    }
203
204 45
    public function setAxisType(string $type): self
205
    {
206 45
        if ($type === self::AXIS_TYPE_CATEGORY || $type === self::AXIS_TYPE_VALUE || $type === self::AXIS_TYPE_DATE) {
207 45
            $this->axisType = $type;
208
        } else {
209 3
            $this->axisType = '';
210
        }
211
212 45
        return $this;
213
    }
214
215
    /**
216
     * Set Fill Property.
217
     *
218
     * @param ?string $color
219
     * @param ?int $alpha
220
     * @param ?string $AlphaType
221
     */
222 4
    public function setFillParameters($color, $alpha = null, $AlphaType = ChartColor::EXCEL_COLOR_TYPE_RGB): void
223
    {
224 4
        $this->fillColor->setColorProperties($color, $alpha, $AlphaType);
225
    }
226
227
    /**
228
     * Get Fill Property.
229
     *
230
     * @param string $property
231
     *
232
     * @return string
233
     */
234 1
    public function getFillProperty($property)
235
    {
236 1
        return (string) $this->fillColor->getColorProperty($property);
237
    }
238
239 61
    public function getFillColorObject(): ChartColor
240
    {
241 61
        return $this->fillColor;
242
    }
243
244
    /**
245
     * Get Line Color Property.
246
     *
247
     * @deprecated 1.24.0
248
     *      Use the getLineColor property in the Properties class instead
249
     * @see Properties::getLineColorProperty()
250
     *
251
     * @param string $propertyName
252
     *
253
     * @return null|int|string
254
     */
255
    public function getLineProperty($propertyName)
256
    {
257
        return $this->getLineColorProperty($propertyName);
258
    }
259
260
    /** @var string */
261
    private $crossBetween = ''; // 'between' or 'midCat' might be better
262
263 31
    public function setCrossBetween(string $crossBetween): self
264
    {
265 31
        $this->crossBetween = $crossBetween;
266
267 31
        return $this;
268
    }
269
270 61
    public function getCrossBetween(): string
271
    {
272 61
        return $this->crossBetween;
273
    }
274
275 61
    public function getMajorGridlines(): ?GridLines
276
    {
277 61
        return $this->majorGridlines;
278
    }
279
280 61
    public function getMinorGridlines(): ?GridLines
281
    {
282 61
        return $this->minorGridlines;
283
    }
284
285 36
    public function setMajorGridlines(?GridLines $gridlines): self
286
    {
287 36
        $this->majorGridlines = $gridlines;
288
289 36
        return $this;
290
    }
291
292 10
    public function setMinorGridlines(?GridLines $gridlines): self
293
    {
294 10
        $this->minorGridlines = $gridlines;
295
296 10
        return $this;
297
    }
298
}
299