1441 |
ariadna |
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 |
public function __construct()
|
|
|
22 |
{
|
|
|
23 |
parent::__construct();
|
|
|
24 |
$this->fillColor = new ChartColor();
|
|
|
25 |
}
|
|
|
26 |
|
|
|
27 |
/**
|
|
|
28 |
* Chart Major Gridlines as.
|
|
|
29 |
*/
|
|
|
30 |
private ?GridLines $majorGridlines = null;
|
|
|
31 |
|
|
|
32 |
/**
|
|
|
33 |
* Chart Minor Gridlines as.
|
|
|
34 |
*/
|
|
|
35 |
private ?GridLines $minorGridlines = null;
|
|
|
36 |
|
|
|
37 |
/**
|
|
|
38 |
* Axis Number.
|
|
|
39 |
*
|
|
|
40 |
* @var array{format: string, source_linked: int, numeric: ?bool}
|
|
|
41 |
*/
|
|
|
42 |
private array $axisNumber = [
|
|
|
43 |
'format' => self::FORMAT_CODE_GENERAL,
|
|
|
44 |
'source_linked' => 1,
|
|
|
45 |
'numeric' => null,
|
|
|
46 |
];
|
|
|
47 |
|
|
|
48 |
private string $axisType = '';
|
|
|
49 |
|
|
|
50 |
private ?AxisText $axisText = null;
|
|
|
51 |
|
|
|
52 |
private ?Title $dispUnitsTitle = null;
|
|
|
53 |
|
|
|
54 |
/**
|
|
|
55 |
* Axis Options.
|
|
|
56 |
*
|
|
|
57 |
* @var array<string, null|string>
|
|
|
58 |
*/
|
|
|
59 |
private array $axisOptions = [
|
|
|
60 |
'minimum' => null,
|
|
|
61 |
'maximum' => null,
|
|
|
62 |
'major_unit' => null,
|
|
|
63 |
'minor_unit' => null,
|
|
|
64 |
'orientation' => self::ORIENTATION_NORMAL,
|
|
|
65 |
'minor_tick_mark' => self::TICK_MARK_NONE,
|
|
|
66 |
'major_tick_mark' => self::TICK_MARK_NONE,
|
|
|
67 |
'axis_labels' => self::AXIS_LABELS_NEXT_TO,
|
|
|
68 |
'horizontal_crosses' => self::HORIZONTAL_CROSSES_AUTOZERO,
|
|
|
69 |
'horizontal_crosses_value' => null,
|
|
|
70 |
'textRotation' => null,
|
|
|
71 |
'hidden' => null,
|
|
|
72 |
'majorTimeUnit' => self::TIME_UNIT_YEARS,
|
|
|
73 |
'minorTimeUnit' => self::TIME_UNIT_MONTHS,
|
|
|
74 |
'baseTimeUnit' => self::TIME_UNIT_DAYS,
|
|
|
75 |
'logBase' => null,
|
|
|
76 |
'dispUnitsBuiltIn' => null,
|
|
|
77 |
];
|
|
|
78 |
public const DISP_UNITS_HUNDREDS = 'hundreds';
|
|
|
79 |
public const DISP_UNITS_THOUSANDS = 'thousands';
|
|
|
80 |
public const DISP_UNITS_TEN_THOUSANDS = 'tenThousands';
|
|
|
81 |
public const DISP_UNITS_HUNDRED_THOUSANDS = 'hundredThousands';
|
|
|
82 |
public const DISP_UNITS_MILLIONS = 'millions';
|
|
|
83 |
public const DISP_UNITS_TEN_MILLIONS = 'tenMillions';
|
|
|
84 |
public const DISP_UNITS_HUNDRED_MILLIONS = 'hundredMillions';
|
|
|
85 |
public const DISP_UNITS_BILLIONS = 'billions';
|
|
|
86 |
public const DISP_UNITS_TRILLIONS = 'trillions';
|
|
|
87 |
public const TRILLION_INDEX = (PHP_INT_SIZE > 4) ? 1000000000000 : '1000000000000';
|
|
|
88 |
public const DISP_UNITS_BUILTIN_INT = [
|
|
|
89 |
100 => self::DISP_UNITS_HUNDREDS,
|
|
|
90 |
1000 => self::DISP_UNITS_THOUSANDS,
|
|
|
91 |
10000 => self::DISP_UNITS_TEN_THOUSANDS,
|
|
|
92 |
100000 => self::DISP_UNITS_HUNDRED_THOUSANDS,
|
|
|
93 |
1000000 => self::DISP_UNITS_MILLIONS,
|
|
|
94 |
10000000 => self::DISP_UNITS_TEN_MILLIONS,
|
|
|
95 |
100000000 => self::DISP_UNITS_HUNDRED_MILLIONS,
|
|
|
96 |
1000000000 => self::DISP_UNITS_BILLIONS,
|
|
|
97 |
self::TRILLION_INDEX => self::DISP_UNITS_TRILLIONS, // overflow for 32-bit
|
|
|
98 |
];
|
|
|
99 |
|
|
|
100 |
/**
|
|
|
101 |
* Fill Properties.
|
|
|
102 |
*/
|
|
|
103 |
private ChartColor $fillColor;
|
|
|
104 |
|
|
|
105 |
private const NUMERIC_FORMAT = [
|
|
|
106 |
Properties::FORMAT_CODE_NUMBER,
|
|
|
107 |
Properties::FORMAT_CODE_DATE,
|
|
|
108 |
Properties::FORMAT_CODE_DATE_ISO8601,
|
|
|
109 |
];
|
|
|
110 |
|
|
|
111 |
private bool $noFill = false;
|
|
|
112 |
|
|
|
113 |
/**
|
|
|
114 |
* Get Series Data Type.
|
|
|
115 |
*/
|
|
|
116 |
public function setAxisNumberProperties(string $format_code, ?bool $numeric = null, int $sourceLinked = 0): void
|
|
|
117 |
{
|
|
|
118 |
$format = $format_code;
|
|
|
119 |
$this->axisNumber['format'] = $format;
|
|
|
120 |
$this->axisNumber['source_linked'] = $sourceLinked;
|
|
|
121 |
if (is_bool($numeric)) {
|
|
|
122 |
$this->axisNumber['numeric'] = $numeric;
|
|
|
123 |
} elseif (in_array($format, self::NUMERIC_FORMAT, true)) {
|
|
|
124 |
$this->axisNumber['numeric'] = true;
|
|
|
125 |
}
|
|
|
126 |
}
|
|
|
127 |
|
|
|
128 |
/**
|
|
|
129 |
* Get Axis Number Format Data Type.
|
|
|
130 |
*/
|
|
|
131 |
public function getAxisNumberFormat(): string
|
|
|
132 |
{
|
|
|
133 |
return $this->axisNumber['format'];
|
|
|
134 |
}
|
|
|
135 |
|
|
|
136 |
/**
|
|
|
137 |
* Get Axis Number Source Linked.
|
|
|
138 |
*/
|
|
|
139 |
public function getAxisNumberSourceLinked(): string
|
|
|
140 |
{
|
|
|
141 |
return (string) $this->axisNumber['source_linked'];
|
|
|
142 |
}
|
|
|
143 |
|
|
|
144 |
public function getAxisIsNumericFormat(): bool
|
|
|
145 |
{
|
|
|
146 |
return $this->axisType === self::AXIS_TYPE_DATE || (bool) $this->axisNumber['numeric'];
|
|
|
147 |
}
|
|
|
148 |
|
|
|
149 |
public function setAxisOption(string $key, null|float|int|string $value): void
|
|
|
150 |
{
|
|
|
151 |
if ($value !== null && $value !== '') {
|
|
|
152 |
$this->axisOptions[$key] = (string) $value;
|
|
|
153 |
}
|
|
|
154 |
}
|
|
|
155 |
|
|
|
156 |
/**
|
|
|
157 |
* Set Axis Options Properties.
|
|
|
158 |
*/
|
|
|
159 |
public function setAxisOptionsProperties(
|
|
|
160 |
string $axisLabels,
|
|
|
161 |
?string $horizontalCrossesValue = null,
|
|
|
162 |
?string $horizontalCrosses = null,
|
|
|
163 |
?string $axisOrientation = null,
|
|
|
164 |
?string $majorTmt = null,
|
|
|
165 |
?string $minorTmt = null,
|
|
|
166 |
null|float|int|string $minimum = null,
|
|
|
167 |
null|float|int|string $maximum = null,
|
|
|
168 |
null|float|int|string $majorUnit = null,
|
|
|
169 |
null|float|int|string $minorUnit = null,
|
|
|
170 |
null|float|int|string $textRotation = null,
|
|
|
171 |
?string $hidden = null,
|
|
|
172 |
?string $baseTimeUnit = null,
|
|
|
173 |
?string $majorTimeUnit = null,
|
|
|
174 |
?string $minorTimeUnit = null,
|
|
|
175 |
null|float|int|string $logBase = null,
|
|
|
176 |
?string $dispUnitsBuiltIn = null
|
|
|
177 |
): void {
|
|
|
178 |
$this->axisOptions['axis_labels'] = $axisLabels;
|
|
|
179 |
$this->setAxisOption('horizontal_crosses_value', $horizontalCrossesValue);
|
|
|
180 |
$this->setAxisOption('horizontal_crosses', $horizontalCrosses);
|
|
|
181 |
$this->setAxisOption('orientation', $axisOrientation);
|
|
|
182 |
$this->setAxisOption('major_tick_mark', $majorTmt);
|
|
|
183 |
$this->setAxisOption('minor_tick_mark', $minorTmt);
|
|
|
184 |
$this->setAxisOption('minimum', $minimum);
|
|
|
185 |
$this->setAxisOption('maximum', $maximum);
|
|
|
186 |
$this->setAxisOption('major_unit', $majorUnit);
|
|
|
187 |
$this->setAxisOption('minor_unit', $minorUnit);
|
|
|
188 |
$this->setAxisOption('textRotation', $textRotation);
|
|
|
189 |
$this->setAxisOption('hidden', $hidden);
|
|
|
190 |
$this->setAxisOption('baseTimeUnit', $baseTimeUnit);
|
|
|
191 |
$this->setAxisOption('majorTimeUnit', $majorTimeUnit);
|
|
|
192 |
$this->setAxisOption('minorTimeUnit', $minorTimeUnit);
|
|
|
193 |
$this->setAxisOption('logBase', $logBase);
|
|
|
194 |
$this->setAxisOption('dispUnitsBuiltIn', $dispUnitsBuiltIn);
|
|
|
195 |
}
|
|
|
196 |
|
|
|
197 |
/**
|
|
|
198 |
* Get Axis Options Property.
|
|
|
199 |
*/
|
|
|
200 |
public function getAxisOptionsProperty(string $property): ?string
|
|
|
201 |
{
|
|
|
202 |
if ($property === 'textRotation') {
|
|
|
203 |
if ($this->axisText !== null) {
|
|
|
204 |
if ($this->axisText->getRotation() !== null) {
|
|
|
205 |
return (string) $this->axisText->getRotation();
|
|
|
206 |
}
|
|
|
207 |
}
|
|
|
208 |
}
|
|
|
209 |
|
|
|
210 |
return $this->axisOptions[$property];
|
|
|
211 |
}
|
|
|
212 |
|
|
|
213 |
/**
|
|
|
214 |
* Set Axis Orientation Property.
|
|
|
215 |
*/
|
|
|
216 |
public function setAxisOrientation(string $orientation): void
|
|
|
217 |
{
|
|
|
218 |
$this->axisOptions['orientation'] = (string) $orientation;
|
|
|
219 |
}
|
|
|
220 |
|
|
|
221 |
public function getAxisType(): string
|
|
|
222 |
{
|
|
|
223 |
return $this->axisType;
|
|
|
224 |
}
|
|
|
225 |
|
|
|
226 |
public function setAxisType(string $type): self
|
|
|
227 |
{
|
|
|
228 |
if ($type === self::AXIS_TYPE_CATEGORY || $type === self::AXIS_TYPE_VALUE || $type === self::AXIS_TYPE_DATE) {
|
|
|
229 |
$this->axisType = $type;
|
|
|
230 |
} else {
|
|
|
231 |
$this->axisType = '';
|
|
|
232 |
}
|
|
|
233 |
|
|
|
234 |
return $this;
|
|
|
235 |
}
|
|
|
236 |
|
|
|
237 |
/**
|
|
|
238 |
* Set Fill Property.
|
|
|
239 |
*/
|
|
|
240 |
public function setFillParameters(?string $color, ?int $alpha = null, ?string $AlphaType = ChartColor::EXCEL_COLOR_TYPE_RGB): void
|
|
|
241 |
{
|
|
|
242 |
$this->fillColor->setColorProperties($color, $alpha, $AlphaType);
|
|
|
243 |
}
|
|
|
244 |
|
|
|
245 |
/**
|
|
|
246 |
* Get Fill Property.
|
|
|
247 |
*/
|
|
|
248 |
public function getFillProperty(string $property): string
|
|
|
249 |
{
|
|
|
250 |
return (string) $this->fillColor->getColorProperty($property);
|
|
|
251 |
}
|
|
|
252 |
|
|
|
253 |
public function getFillColorObject(): ChartColor
|
|
|
254 |
{
|
|
|
255 |
return $this->fillColor;
|
|
|
256 |
}
|
|
|
257 |
|
|
|
258 |
private string $crossBetween = ''; // 'between' or 'midCat' might be better
|
|
|
259 |
|
|
|
260 |
public function setCrossBetween(string $crossBetween): self
|
|
|
261 |
{
|
|
|
262 |
$this->crossBetween = $crossBetween;
|
|
|
263 |
|
|
|
264 |
return $this;
|
|
|
265 |
}
|
|
|
266 |
|
|
|
267 |
public function getCrossBetween(): string
|
|
|
268 |
{
|
|
|
269 |
return $this->crossBetween;
|
|
|
270 |
}
|
|
|
271 |
|
|
|
272 |
public function getMajorGridlines(): ?GridLines
|
|
|
273 |
{
|
|
|
274 |
return $this->majorGridlines;
|
|
|
275 |
}
|
|
|
276 |
|
|
|
277 |
public function getMinorGridlines(): ?GridLines
|
|
|
278 |
{
|
|
|
279 |
return $this->minorGridlines;
|
|
|
280 |
}
|
|
|
281 |
|
|
|
282 |
public function setMajorGridlines(?GridLines $gridlines): self
|
|
|
283 |
{
|
|
|
284 |
$this->majorGridlines = $gridlines;
|
|
|
285 |
|
|
|
286 |
return $this;
|
|
|
287 |
}
|
|
|
288 |
|
|
|
289 |
public function setMinorGridlines(?GridLines $gridlines): self
|
|
|
290 |
{
|
|
|
291 |
$this->minorGridlines = $gridlines;
|
|
|
292 |
|
|
|
293 |
return $this;
|
|
|
294 |
}
|
|
|
295 |
|
|
|
296 |
public function getAxisText(): ?AxisText
|
|
|
297 |
{
|
|
|
298 |
return $this->axisText;
|
|
|
299 |
}
|
|
|
300 |
|
|
|
301 |
public function setAxisText(?AxisText $axisText): self
|
|
|
302 |
{
|
|
|
303 |
$this->axisText = $axisText;
|
|
|
304 |
|
|
|
305 |
return $this;
|
|
|
306 |
}
|
|
|
307 |
|
|
|
308 |
public function setNoFill(bool $noFill): self
|
|
|
309 |
{
|
|
|
310 |
$this->noFill = $noFill;
|
|
|
311 |
|
|
|
312 |
return $this;
|
|
|
313 |
}
|
|
|
314 |
|
|
|
315 |
public function getNoFill(): bool
|
|
|
316 |
{
|
|
|
317 |
return $this->noFill;
|
|
|
318 |
}
|
|
|
319 |
|
|
|
320 |
public function setDispUnitsTitle(?Title $dispUnitsTitle): self
|
|
|
321 |
{
|
|
|
322 |
$this->dispUnitsTitle = $dispUnitsTitle;
|
|
|
323 |
|
|
|
324 |
return $this;
|
|
|
325 |
}
|
|
|
326 |
|
|
|
327 |
public function getDispUnitsTitle(): ?Title
|
|
|
328 |
{
|
|
|
329 |
return $this->dispUnitsTitle;
|
|
|
330 |
}
|
|
|
331 |
|
|
|
332 |
/**
|
|
|
333 |
* Implement PHP __clone to create a deep clone, not just a shallow copy.
|
|
|
334 |
*/
|
|
|
335 |
public function __clone()
|
|
|
336 |
{
|
|
|
337 |
parent::__clone();
|
|
|
338 |
$this->majorGridlines = ($this->majorGridlines === null) ? null : clone $this->majorGridlines;
|
|
|
339 |
$this->majorGridlines = ($this->minorGridlines === null) ? null : clone $this->minorGridlines;
|
|
|
340 |
$this->axisText = ($this->axisText === null) ? null : clone $this->axisText;
|
|
|
341 |
$this->dispUnitsTitle = ($this->dispUnitsTitle === null) ? null : clone $this->dispUnitsTitle;
|
|
|
342 |
$this->fillColor = clone $this->fillColor;
|
|
|
343 |
}
|
|
|
344 |
}
|