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
|
92 |
|
public function __construct() |
22
|
|
|
{ |
23
|
92 |
|
parent::__construct(); |
24
|
92 |
|
$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
|
|
|
/** @var ?AxisText */ |
56
|
|
|
private $axisText; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Axis Options. |
60
|
|
|
* |
61
|
|
|
* @var mixed[] |
62
|
|
|
*/ |
63
|
|
|
private $axisOptions = [ |
64
|
|
|
'minimum' => null, |
65
|
|
|
'maximum' => null, |
66
|
|
|
'major_unit' => null, |
67
|
|
|
'minor_unit' => null, |
68
|
|
|
'orientation' => self::ORIENTATION_NORMAL, |
69
|
|
|
'minor_tick_mark' => self::TICK_MARK_NONE, |
70
|
|
|
'major_tick_mark' => self::TICK_MARK_NONE, |
71
|
|
|
'axis_labels' => self::AXIS_LABELS_NEXT_TO, |
72
|
|
|
'horizontal_crosses' => self::HORIZONTAL_CROSSES_AUTOZERO, |
73
|
|
|
'horizontal_crosses_value' => null, |
74
|
|
|
'textRotation' => null, |
75
|
|
|
'hidden' => null, |
76
|
|
|
'majorTimeUnit' => self::TIME_UNIT_YEARS, |
77
|
|
|
'minorTimeUnit' => self::TIME_UNIT_MONTHS, |
78
|
|
|
'baseTimeUnit' => self::TIME_UNIT_DAYS, |
79
|
|
|
]; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Fill Properties. |
83
|
|
|
* |
84
|
|
|
* @var ChartColor |
85
|
|
|
*/ |
86
|
|
|
private $fillColor; |
87
|
|
|
|
88
|
|
|
private const NUMERIC_FORMAT = [ |
89
|
|
|
Properties::FORMAT_CODE_NUMBER, |
90
|
|
|
Properties::FORMAT_CODE_DATE, |
91
|
|
|
Properties::FORMAT_CODE_DATE_ISO8601, |
92
|
|
|
]; |
93
|
|
|
|
94
|
|
|
/** @var bool */ |
95
|
|
|
private $noFill = false; |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Get Series Data Type. |
99
|
|
|
* |
100
|
|
|
* @param mixed $format_code |
101
|
|
|
*/ |
102
|
57 |
|
public function setAxisNumberProperties($format_code, ?bool $numeric = null, int $sourceLinked = 0): void |
103
|
|
|
{ |
104
|
57 |
|
$format = (string) $format_code; |
105
|
57 |
|
$this->axisNumber['format'] = $format; |
106
|
57 |
|
$this->axisNumber['source_linked'] = $sourceLinked; |
107
|
57 |
|
if (is_bool($numeric)) { |
108
|
8 |
|
$this->axisNumber['numeric'] = $numeric; |
109
|
53 |
|
} elseif (in_array($format, self::NUMERIC_FORMAT, true)) { |
110
|
7 |
|
$this->axisNumber['numeric'] = true; |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Get Axis Number Format Data Type. |
116
|
|
|
* |
117
|
|
|
* @return string |
118
|
|
|
*/ |
119
|
71 |
|
public function getAxisNumberFormat() |
120
|
|
|
{ |
121
|
71 |
|
return $this->axisNumber['format']; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Get Axis Number Source Linked. |
126
|
|
|
* |
127
|
|
|
* @return string |
128
|
|
|
*/ |
129
|
71 |
|
public function getAxisNumberSourceLinked() |
130
|
|
|
{ |
131
|
71 |
|
return (string) $this->axisNumber['source_linked']; |
132
|
|
|
} |
133
|
|
|
|
134
|
42 |
|
public function getAxisIsNumericFormat(): bool |
135
|
|
|
{ |
136
|
42 |
|
return $this->axisType === self::AXIS_TYPE_DATE || (bool) $this->axisNumber['numeric']; |
137
|
|
|
} |
138
|
|
|
|
139
|
55 |
|
public function setAxisOption(string $key, ?string $value): void |
140
|
|
|
{ |
141
|
55 |
|
if ($value !== null && $value !== '') { |
142
|
54 |
|
$this->axisOptions[$key] = $value; |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Set Axis Options Properties. |
148
|
|
|
*/ |
149
|
4 |
|
public function setAxisOptionsProperties( |
150
|
|
|
string $axisLabels, |
151
|
|
|
?string $horizontalCrossesValue = null, |
152
|
|
|
?string $horizontalCrosses = null, |
153
|
|
|
?string $axisOrientation = null, |
154
|
|
|
?string $majorTmt = null, |
155
|
|
|
?string $minorTmt = null, |
156
|
|
|
?string $minimum = null, |
157
|
|
|
?string $maximum = null, |
158
|
|
|
?string $majorUnit = null, |
159
|
|
|
?string $minorUnit = null, |
160
|
|
|
?string $textRotation = null, |
161
|
|
|
?string $hidden = null, |
162
|
|
|
?string $baseTimeUnit = null, |
163
|
|
|
?string $majorTimeUnit = null, |
164
|
|
|
?string $minorTimeUnit = null |
165
|
|
|
): void { |
166
|
4 |
|
$this->axisOptions['axis_labels'] = $axisLabels; |
167
|
4 |
|
$this->setAxisOption('horizontal_crosses_value', $horizontalCrossesValue); |
168
|
4 |
|
$this->setAxisOption('horizontal_crosses', $horizontalCrosses); |
169
|
4 |
|
$this->setAxisOption('orientation', $axisOrientation); |
170
|
4 |
|
$this->setAxisOption('major_tick_mark', $majorTmt); |
171
|
4 |
|
$this->setAxisOption('minor_tick_mark', $minorTmt); |
172
|
4 |
|
$this->setAxisOption('minimum', $minimum); |
173
|
4 |
|
$this->setAxisOption('maximum', $maximum); |
174
|
4 |
|
$this->setAxisOption('major_unit', $majorUnit); |
175
|
4 |
|
$this->setAxisOption('minor_unit', $minorUnit); |
176
|
4 |
|
$this->setAxisOption('textRotation', $textRotation); |
177
|
4 |
|
$this->setAxisOption('hidden', $hidden); |
178
|
4 |
|
$this->setAxisOption('baseTimeUnit', $baseTimeUnit); |
179
|
4 |
|
$this->setAxisOption('majorTimeUnit', $majorTimeUnit); |
180
|
4 |
|
$this->setAxisOption('minorTimeUnit', $minorTimeUnit); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* Get Axis Options Property. |
185
|
|
|
* |
186
|
|
|
* @param string $property |
187
|
|
|
* |
188
|
|
|
* @return ?string |
189
|
|
|
*/ |
190
|
71 |
|
public function getAxisOptionsProperty($property) |
191
|
|
|
{ |
192
|
71 |
|
if ($property === 'textRotation') { |
193
|
71 |
|
if ($this->axisText !== null) { |
194
|
7 |
|
if ($this->axisText->getRotation() !== null) { |
195
|
6 |
|
return (string) $this->axisText->getRotation(); |
196
|
|
|
} |
197
|
|
|
} |
198
|
|
|
} |
199
|
|
|
|
200
|
71 |
|
return $this->axisOptions[$property]; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* Set Axis Orientation Property. |
205
|
|
|
* |
206
|
|
|
* @param string $orientation |
207
|
|
|
*/ |
208
|
1 |
|
public function setAxisOrientation($orientation): void |
209
|
|
|
{ |
210
|
1 |
|
$this->axisOptions['orientation'] = (string) $orientation; |
211
|
|
|
} |
212
|
|
|
|
213
|
70 |
|
public function getAxisType(): string |
214
|
|
|
{ |
215
|
70 |
|
return $this->axisType; |
216
|
|
|
} |
217
|
|
|
|
218
|
53 |
|
public function setAxisType(string $type): self |
219
|
|
|
{ |
220
|
53 |
|
if ($type === self::AXIS_TYPE_CATEGORY || $type === self::AXIS_TYPE_VALUE || $type === self::AXIS_TYPE_DATE) { |
221
|
53 |
|
$this->axisType = $type; |
222
|
|
|
} else { |
223
|
3 |
|
$this->axisType = ''; |
224
|
|
|
} |
225
|
|
|
|
226
|
53 |
|
return $this; |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* Set Fill Property. |
231
|
|
|
* |
232
|
|
|
* @param ?string $color |
233
|
|
|
* @param ?int $alpha |
234
|
|
|
* @param ?string $AlphaType |
235
|
|
|
*/ |
236
|
4 |
|
public function setFillParameters($color, $alpha = null, $AlphaType = ChartColor::EXCEL_COLOR_TYPE_RGB): void |
237
|
|
|
{ |
238
|
4 |
|
$this->fillColor->setColorProperties($color, $alpha, $AlphaType); |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
/** |
242
|
|
|
* Get Fill Property. |
243
|
|
|
* |
244
|
|
|
* @param string $property |
245
|
|
|
* |
246
|
|
|
* @return string |
247
|
|
|
*/ |
248
|
1 |
|
public function getFillProperty($property) |
249
|
|
|
{ |
250
|
1 |
|
return (string) $this->fillColor->getColorProperty($property); |
251
|
|
|
} |
252
|
|
|
|
253
|
71 |
|
public function getFillColorObject(): ChartColor |
254
|
|
|
{ |
255
|
71 |
|
return $this->fillColor; |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* Get Line Color Property. |
260
|
|
|
* |
261
|
|
|
* @deprecated 1.24.0 |
262
|
|
|
* Use the getLineColor property in the Properties class instead |
263
|
|
|
* @see Properties::getLineColorProperty() |
264
|
|
|
* |
265
|
|
|
* @param string $propertyName |
266
|
|
|
* |
267
|
|
|
* @return null|int|string |
268
|
|
|
*/ |
269
|
|
|
public function getLineProperty($propertyName) |
270
|
|
|
{ |
271
|
|
|
return $this->getLineColorProperty($propertyName); |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
/** @var string */ |
275
|
|
|
private $crossBetween = ''; // 'between' or 'midCat' might be better |
276
|
|
|
|
277
|
36 |
|
public function setCrossBetween(string $crossBetween): self |
278
|
|
|
{ |
279
|
36 |
|
$this->crossBetween = $crossBetween; |
280
|
|
|
|
281
|
36 |
|
return $this; |
282
|
|
|
} |
283
|
|
|
|
284
|
71 |
|
public function getCrossBetween(): string |
285
|
|
|
{ |
286
|
71 |
|
return $this->crossBetween; |
287
|
|
|
} |
288
|
|
|
|
289
|
71 |
|
public function getMajorGridlines(): ?GridLines |
290
|
|
|
{ |
291
|
71 |
|
return $this->majorGridlines; |
292
|
|
|
} |
293
|
|
|
|
294
|
71 |
|
public function getMinorGridlines(): ?GridLines |
295
|
|
|
{ |
296
|
71 |
|
return $this->minorGridlines; |
297
|
|
|
} |
298
|
|
|
|
299
|
41 |
|
public function setMajorGridlines(?GridLines $gridlines): self |
300
|
|
|
{ |
301
|
41 |
|
$this->majorGridlines = $gridlines; |
302
|
|
|
|
303
|
41 |
|
return $this; |
304
|
|
|
} |
305
|
|
|
|
306
|
10 |
|
public function setMinorGridlines(?GridLines $gridlines): self |
307
|
|
|
{ |
308
|
10 |
|
$this->minorGridlines = $gridlines; |
309
|
|
|
|
310
|
10 |
|
return $this; |
311
|
|
|
} |
312
|
|
|
|
313
|
71 |
|
public function getAxisText(): ?AxisText |
314
|
|
|
{ |
315
|
71 |
|
return $this->axisText; |
316
|
|
|
} |
317
|
|
|
|
318
|
11 |
|
public function setAxisText(?AxisText $axisText): self |
319
|
|
|
{ |
320
|
11 |
|
$this->axisText = $axisText; |
321
|
|
|
|
322
|
11 |
|
return $this; |
323
|
|
|
} |
324
|
|
|
|
325
|
4 |
|
public function setNoFill(bool $noFill): self |
326
|
|
|
{ |
327
|
4 |
|
$this->noFill = $noFill; |
328
|
|
|
|
329
|
4 |
|
return $this; |
330
|
|
|
} |
331
|
|
|
|
332
|
71 |
|
public function getNoFill(): bool |
333
|
|
|
{ |
334
|
71 |
|
return $this->noFill; |
335
|
|
|
} |
336
|
|
|
} |
337
|
|
|
|